MatteoScript commited on
Commit
d57ded5
·
verified ·
1 Parent(s): 0bb76a8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +107 -7
main.py CHANGED
@@ -9,6 +9,7 @@ import requests
9
  import os
10
  import socket
11
  import time
 
12
 
13
  #--------------------------------------------------- Definizione Server FAST API ------------------------------------------------------
14
  app = FastAPI()
@@ -29,13 +30,6 @@ class InputData(BaseModel):
29
  top_p: float = 0.95
30
  repetition_penalty: float = 1.0
31
 
32
- class InputImage(BaseModel):
33
- input: str
34
- negativePrompt: str = ''
35
- steps: int = 30
36
- cfg: int = 7
37
- seed: int = -1
38
-
39
  class PostSpazio(BaseModel):
40
  nomeSpazio: str
41
  input: str = ''
@@ -81,9 +75,115 @@ def format_prompt(message, history):
81
 
82
 
83
  #--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  @app.post("/Immagine")
85
  def generate_image(request: Request, input_data: InputImage):
86
  client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
 
 
 
 
 
 
87
  max_attempts = 20
88
  attempt = 0
89
  while attempt < max_attempts:
 
9
  import os
10
  import socket
11
  import time
12
+ from enum import Enum
13
 
14
  #--------------------------------------------------- Definizione Server FAST API ------------------------------------------------------
15
  app = FastAPI()
 
30
  top_p: float = 0.95
31
  repetition_penalty: float = 1.0
32
 
 
 
 
 
 
 
 
33
  class PostSpazio(BaseModel):
34
  nomeSpazio: str
35
  input: str = ''
 
75
 
76
 
77
  #--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------
78
+ style_image = {
79
+ "PROFESSIONAL-PHOTO": {
80
+ "descrizione": "Professional photo {prompt} . Vivid colors, Mirrorless, 35mm lens, f/1.8 aperture, ISO 100, natural daylight",
81
+ "negativePrompt": "out of frame, lowres, text, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature"
82
+ },
83
+ "CINEMATIC-PHOTO": {
84
+ "descrizione": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
85
+ "negativePrompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"
86
+ },
87
+ "CINEMATIC-PORTRAIT": {
88
+ "descrizione": "cinematic portrait {prompt} 8k, ultra realistic, good vibes, vibrant",
89
+ "negativePrompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"
90
+ },
91
+ "LINE-ART-DRAWING": {
92
+ "descrizione": "line art drawing {prompt} . professional, sleek, modern, minimalist, graphic, line art, vector graphics",
93
+ "negativePrompt": "anime, photorealistic, 35mm film, deformed, glitch, blurry, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, mutated, realism, realistic, impressionism, expressionism, oil, acrylic"
94
+ },
95
+ "COMIC": {
96
+ "descrizione": "comic {prompt} . graphic illustration, comic art, graphic novel art, vibrant, highly detailed",
97
+ "negativePrompt": "photograph, deformed, glitch, noisy, realistic, stock photo"
98
+ },
99
+ "ADVERTISING-POSTER-STYLE": {
100
+ "descrizione": "advertising poster style {prompt} . Professional, modern, product-focused, commercial, eye-catching, highly detailed",
101
+ "negativePrompt": "noisy, blurry, amateurish, sloppy, unattractive"
102
+ },
103
+ "RETAIL-PACKAGING-STYLE": {
104
+ "descrizione": "retail packaging style {prompt} . vibrant, enticing, commercial, product-focused, eye-catching, professional, highly detailed",
105
+ "negativePrompt": "noisy, blurry, amateurish, sloppy, unattractive"
106
+ },
107
+ "GRAFFITI-STYLE": {
108
+ "descrizione": "graffiti style {prompt} . street art, vibrant, urban, detailed, tag, mural",
109
+ "negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic"
110
+ },
111
+ "POP-ART-STYLE": {
112
+ "descrizione": "pop Art style {prompt} . bright colors, bold outlines, popular culture themes, ironic or kitsch",
113
+ "negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, minimalist"
114
+ },
115
+ "ISOMETRIC-STYLE": {
116
+ "descrizione": "isometric style {prompt} . vibrant, beautiful, crisp, detailed, ultra detailed, intricate",
117
+ "negativePrompt": "deformed, mutated, ugly, disfigured, blur, blurry, noise, noisy, realistic, photographic"
118
+ },
119
+ "LOW-POLY-STYLE": {
120
+ "descrizione": "low-poly style {prompt}. ambient occlusion, low-poly game art, polygon mesh, jagged, blocky, wireframe edges, centered composition",
121
+ "negativePrompt": "noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo"
122
+ },
123
+ "CLAYMATION-STYLE": {
124
+ "descrizione": "claymation style {prompt} . sculpture, clay art, centered composition, play-doh",
125
+ "negativePrompt": ""
126
+ },
127
+ "PROFESSIONAL-3D-MODEL": {
128
+ "descrizione": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
129
+ "negativePrompt": "ugly, deformed, noisy, low poly, blurry, painting"
130
+ },
131
+ "ANIME-ARTWORK": {
132
+ "descrizione": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
133
+ "negativePrompt": "photo, deformed, black and white, realism, disfigured, low contrast"
134
+ },
135
+ "ETHEREAL-FANTASY-CONCEPT-ART": {
136
+ "descrizione": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
137
+ "negativePrompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white"
138
+ },
139
+ "CYBERNETIC-STYLE": {
140
+ "descrizione": "cybernetic style {prompt} . futuristic, technological, cybernetic enhancements, robotics, artificial intelligence themes",
141
+ "negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, historical, medieval"
142
+ },
143
+ "FUTURISTIC-STYLE": {
144
+ "descrizione": "futuristic style {prompt} . sleek, modern, ultramodern, high tech, detailed",
145
+ "negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, vintage, antique"
146
+ },
147
+ "SCI-FI-STYLE": {
148
+ "descrizione": "sci-fi style {prompt} . futuristic, technological, alien worlds, space themes, advanced civilizations",
149
+ "negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, historical, medieval"
150
+ },
151
+ "DIGITAL-ART": {
152
+ "descrizione": "Digital Art {prompt} . vibrant, cute, digital, handmade",
153
+ "negativePrompt": ""
154
+ },
155
+ "SIMPLE-LOGO": {
156
+ "descrizione": "Minimalist Logo {prompt} . material design, primary colors, stylized, minimalist",
157
+ "negativePrompt": "3D, high detail, noise, grainy, blurry, painting, drawing, photo, disfigured"
158
+ },
159
+ "MINIMALISTIC-LOGO": {
160
+ "descrizione": "Ultra-minimalist Material Design logo for a BRAND: {prompt} . simple, few colors, clean lines, minimal details, modern color palette, no shadows",
161
+ "negativePrompt": "3D, high detail, noise, grainy, blurry, painting, drawing, photo, disfigured"
162
+ }
163
+ }
164
+
165
+ def create_style_enum(style_image):
166
+ return Enum("StyleEnum", [(style, style) for style in style_image.keys()])
167
+
168
+ enum_styles = create_style_enum(style_image)
169
+
170
+ class InputImage(BaseModel):
171
+ input: str
172
+ negativePrompt: str = ''
173
+ style: Enum = Enum("StyleEnum", [(style, style) for style in style_image.keys()])
174
+ steps: int = 30
175
+ cfg: int = 7
176
+ seed: int = -1
177
+
178
  @app.post("/Immagine")
179
  def generate_image(request: Request, input_data: InputImage):
180
  client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
181
+ if input_data.style:
182
+ if input_data.style in style_image:
183
+ style_info = style_image[input_data.style]
184
+ input_data.input = style_info["descrizione"].format(prompt=input_data.input)
185
+ input_data.negativePrompt = style_info["negativePrompt"]
186
+
187
  max_attempts = 20
188
  attempt = 0
189
  while attempt < max_attempts: