Equityone commited on
Commit
c1886c4
·
verified ·
1 Parent(s): 5647bfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -50
app.py CHANGED
@@ -19,64 +19,97 @@ logger = logging.getLogger(__name__)
19
  # Chargement des variables d'environnement
20
  load_dotenv()
21
 
22
- # Styles artistiques étendus
23
  ART_STYLES = {
24
- "Art Moderne": {
25
- "prompt_prefix": "modern art style poster, professional design",
26
- "negative_prompt": "traditional, photorealistic, cluttered, busy design"
 
27
  },
28
- "Neo Vintage": {
29
- "prompt_prefix": "vintage style advertising poster, retro design",
30
- "negative_prompt": "modern, digital, contemporary style"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  },
32
  "Pop Art": {
33
- "prompt_prefix": "pop art style poster, bold design",
34
- "negative_prompt": "subtle, realistic, traditional art"
35
  },
36
  "Minimaliste": {
37
- "prompt_prefix": "minimalist design poster, clean composition",
38
- "negative_prompt": "complex, detailed, ornate, busy"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  },
40
  "Cyberpunk": {
41
- "prompt_prefix": "cyberpunk style poster, neon lights, futuristic design",
42
  "negative_prompt": "vintage, natural, rustic, traditional"
43
  },
44
- "Aquarelle": {
45
- "prompt_prefix": "watercolor art style poster, fluid artistic design",
46
- "negative_prompt": "digital, sharp, photorealistic"
47
  },
48
  "Art Déco": {
49
- "prompt_prefix": "art deco style poster, geometric patterns, luxury design",
50
- "negative_prompt": "modern, minimalist, casual"
51
  },
52
- "Japonais": {
53
- "prompt_prefix": "japanese art style poster, ukiyo-e inspired design",
54
- "negative_prompt": "western, modern, photographic"
55
  }
56
  }
57
 
58
- # Paramètres de composition
59
  COMPOSITION_PARAMS = {
60
  "Layouts": {
61
- "Centré": "centered composition, balanced layout",
62
- "Asymétrique": "dynamic asymmetrical composition",
63
- "Grille": "grid-based layout, structured composition",
64
- "Diagonal": "diagonal dynamic composition",
65
- "Minimaliste": "minimal composition, lots of whitespace"
66
  },
67
  "Ambiances": {
68
- "Dramatique": "dramatic lighting, high contrast",
69
- "Doux": "soft lighting, gentle atmosphere",
70
- "Vibrant": "vibrant colors, energetic mood",
71
- "Mystérieux": "mysterious atmosphere, moody lighting",
72
- "Serein": "peaceful atmosphere, calm mood"
73
  },
74
  "Palette": {
75
- "Monochrome": "monochromatic color scheme",
76
- "Contrasté": "high contrast color palette",
77
- "Pastel": "soft pastel color palette",
78
- "Terre": "earthy color palette",
79
- "Néon": "neon color palette"
80
  }
81
  }
82
 
@@ -90,8 +123,8 @@ class ImageGenerator:
90
  logger.info("ImageGenerator initialisé")
91
 
92
  def _build_prompt(self, params: Dict[str, Any]) -> str:
93
- """Construction de prompt améliorée"""
94
- style_info = ART_STYLES.get(params["style"], ART_STYLES["Neo Vintage"])
95
  prompt = f"{style_info['prompt_prefix']}, {params['subject']}"
96
 
97
  # Ajout des paramètres de composition
@@ -105,15 +138,15 @@ class ImageGenerator:
105
  # Ajout des ajustements fins
106
  if params.get("detail_level"):
107
  detail_strength = params["detail_level"]
108
- prompt += f", {'highly detailed' if detail_strength > 7 else 'moderately detailed'}"
109
 
110
  if params.get("contrast"):
111
  contrast_strength = params["contrast"]
112
- prompt += f", {'high contrast' if contrast_strength > 7 else 'balanced contrast'}"
113
 
114
  if params.get("saturation"):
115
  saturation_strength = params["saturation"]
116
- prompt += f", {'vibrant colors' if saturation_strength > 7 else 'subtle colors'}"
117
 
118
  if params.get("title"):
119
  prompt += f", with text saying '{params['title']}'"
@@ -130,7 +163,6 @@ class ImageGenerator:
130
 
131
  prompt = self._build_prompt(params)
132
 
133
- # Configuration de base
134
  payload = {
135
  "inputs": prompt,
136
  "parameters": {
@@ -187,7 +219,6 @@ def create_interface():
187
  """)
188
 
189
  with gr.Column(elem_classes="container"):
190
- # Format et Orientation
191
  with gr.Group(elem_classes="controls-group"):
192
  gr.Markdown("### 📐 Format et Orientation")
193
  with gr.Row():
@@ -202,13 +233,12 @@ def create_interface():
202
  label="Orientation"
203
  )
204
 
205
- # Style et Composition
206
  with gr.Group(elem_classes="controls-group"):
207
  gr.Markdown("### 🎨 Style et Composition")
208
  with gr.Row():
209
  style = gr.Dropdown(
210
  choices=list(ART_STYLES.keys()),
211
- value="Neo Vintage",
212
  label="Style artistique"
213
  )
214
  layout = gr.Dropdown(
@@ -229,7 +259,6 @@ def create_interface():
229
  label="Palette"
230
  )
231
 
232
- # Contenu
233
  with gr.Group(elem_classes="controls-group"):
234
  gr.Markdown("### 📝 Contenu")
235
  subject = gr.Textbox(
@@ -241,7 +270,6 @@ def create_interface():
241
  placeholder="Titre de l'affiche..."
242
  )
243
 
244
- # Ajustements fins
245
  with gr.Group(elem_classes="advanced-controls"):
246
  gr.Markdown("### 🎯 Ajustements Fins")
247
  with gr.Row():
@@ -267,7 +295,6 @@ def create_interface():
267
  label="Saturation"
268
  )
269
 
270
- # Paramètres de génération
271
  with gr.Group(elem_classes="controls-group"):
272
  with gr.Row():
273
  quality = gr.Slider(
@@ -283,12 +310,10 @@ def create_interface():
283
  label="Créativité"
284
  )
285
 
286
- # Boutons
287
  with gr.Row():
288
  generate_btn = gr.Button("✨ Générer", variant="primary")
289
  clear_btn = gr.Button("🗑️ Effacer", variant="secondary")
290
 
291
- # Sortie
292
  image_output = gr.Image(label="Aperçu")
293
  status = gr.Textbox(label="Statut", interactive=False)
294
 
 
19
  # Chargement des variables d'environnement
20
  load_dotenv()
21
 
22
+ # Styles artistiques complets
23
  ART_STYLES = {
24
+ # Styles Classiques
25
+ "Photoréaliste": {
26
+ "prompt_prefix": "hyperrealistic photograph, extremely detailed, studio quality, professional photography, 8k uhd",
27
+ "negative_prompt": "artistic, painterly, abstract, cartoon, illustration, low quality"
28
  },
29
+ "Expressionniste": {
30
+ "prompt_prefix": "expressive painting style, intense emotional art, bold brushstrokes, vibrant colors, van gogh inspired",
31
+ "negative_prompt": "realistic, subtle, photographic, clean lines, digital art"
32
+ },
33
+ "Impressionniste": {
34
+ "prompt_prefix": "impressionist painting style, soft light, visible brushstrokes, outdoor scene, monet inspired",
35
+ "negative_prompt": "sharp details, high contrast, digital, modern"
36
+ },
37
+ "Art Abstrait": {
38
+ "prompt_prefix": "abstract art, geometric shapes, non-representational, kandinsky style, pure artistic expression",
39
+ "negative_prompt": "realistic, figurative, photographic, literal"
40
+ },
41
+ "Surréaliste": {
42
+ "prompt_prefix": "surrealist art, dreamlike imagery, symbolic elements, dali inspired, metaphysical art",
43
+ "negative_prompt": "realistic, conventional, ordinary, literal"
44
+ },
45
+
46
+ # Styles Modernes
47
+ "Art Moderne": {
48
+ "prompt_prefix": "modern art style poster, professional design, contemporary aesthetic",
49
+ "negative_prompt": "traditional, cluttered, busy design, vintage"
50
  },
51
  "Pop Art": {
52
+ "prompt_prefix": "pop art style poster, bold colors, repeated patterns, screen print effect, warhol inspired",
53
+ "negative_prompt": "subtle, realistic, traditional, painterly"
54
  },
55
  "Minimaliste": {
56
+ "prompt_prefix": "minimalist design poster, clean composition, elegant simplicity",
57
+ "negative_prompt": "complex, detailed, ornate, busy, cluttered"
58
+ },
59
+ "Cubiste": {
60
+ "prompt_prefix": "cubist art style, geometric fragmentation, multiple perspectives, picasso inspired",
61
+ "negative_prompt": "realistic, single perspective, traditional, photographic"
62
+ },
63
+ "Futuriste": {
64
+ "prompt_prefix": "futuristic art style, dynamic movement, technological elements, speed and motion",
65
+ "negative_prompt": "static, traditional, classical, historical"
66
+ },
67
+
68
+ # Styles Spéciaux
69
+ "Neo Vintage": {
70
+ "prompt_prefix": "vintage style advertising poster, retro design, classic aesthetic",
71
+ "negative_prompt": "modern, digital, contemporary style"
72
  },
73
  "Cyberpunk": {
74
+ "prompt_prefix": "cyberpunk style poster, neon lights, futuristic design, high-tech aesthetic",
75
  "negative_prompt": "vintage, natural, rustic, traditional"
76
  },
77
+ "Japonais": {
78
+ "prompt_prefix": "japanese art style poster, ukiyo-e inspired design, traditional japanese aesthetic",
79
+ "negative_prompt": "western, modern, photographic"
80
  },
81
  "Art Déco": {
82
+ "prompt_prefix": "art deco style poster, geometric patterns, luxury design, 1920s aesthetic",
83
+ "negative_prompt": "modern, minimalist, casual, contemporary"
84
  },
85
+ "Symboliste": {
86
+ "prompt_prefix": "symbolic art, decorative patterns, gold elements, mystical atmosphere, klimt inspired",
87
+ "negative_prompt": "realistic, simple, plain, literal"
88
  }
89
  }
90
 
91
+ # Paramètres de composition enrichis
92
  COMPOSITION_PARAMS = {
93
  "Layouts": {
94
+ "Centré": "centered composition, balanced layout, harmonious arrangement",
95
+ "Asymétrique": "dynamic asymmetrical composition, creative balance",
96
+ "Grille": "grid-based layout, structured composition, organized design",
97
+ "Diagonal": "diagonal dynamic composition, energetic flow",
98
+ "Minimaliste": "minimal composition, lots of whitespace, elegant spacing"
99
  },
100
  "Ambiances": {
101
+ "Dramatique": "dramatic lighting, high contrast, intense mood",
102
+ "Doux": "soft lighting, gentle atmosphere, subtle mood",
103
+ "Vibrant": "vibrant colors, energetic mood, dynamic atmosphere",
104
+ "Mystérieux": "mysterious atmosphere, moody lighting, enigmatic feel",
105
+ "Serein": "peaceful atmosphere, calm mood, tranquil setting"
106
  },
107
  "Palette": {
108
+ "Monochrome": "monochromatic color scheme, sophisticated tones",
109
+ "Contrasté": "high contrast color palette, bold color combinations",
110
+ "Pastel": "soft pastel color palette, gentle colors",
111
+ "Terre": "earthy color palette, natural tones",
112
+ "Néon": "neon color palette, vibrant glowing colors"
113
  }
114
  }
115
 
 
123
  logger.info("ImageGenerator initialisé")
124
 
125
  def _build_prompt(self, params: Dict[str, Any]) -> str:
126
+ """Construction de prompt améliorée avec plus de détails"""
127
+ style_info = ART_STYLES.get(params["style"], ART_STYLES["Art Moderne"])
128
  prompt = f"{style_info['prompt_prefix']}, {params['subject']}"
129
 
130
  # Ajout des paramètres de composition
 
138
  # Ajout des ajustements fins
139
  if params.get("detail_level"):
140
  detail_strength = params["detail_level"]
141
+ prompt += f", {'highly detailed, intricate' if detail_strength > 7 else 'moderately detailed'}"
142
 
143
  if params.get("contrast"):
144
  contrast_strength = params["contrast"]
145
+ prompt += f", {'high contrast, dramatic lighting' if contrast_strength > 7 else 'balanced contrast'}"
146
 
147
  if params.get("saturation"):
148
  saturation_strength = params["saturation"]
149
+ prompt += f", {'vibrant saturated colors' if saturation_strength > 7 else 'subtle muted colors'}"
150
 
151
  if params.get("title"):
152
  prompt += f", with text saying '{params['title']}'"
 
163
 
164
  prompt = self._build_prompt(params)
165
 
 
166
  payload = {
167
  "inputs": prompt,
168
  "parameters": {
 
219
  """)
220
 
221
  with gr.Column(elem_classes="container"):
 
222
  with gr.Group(elem_classes="controls-group"):
223
  gr.Markdown("### 📐 Format et Orientation")
224
  with gr.Row():
 
233
  label="Orientation"
234
  )
235
 
 
236
  with gr.Group(elem_classes="controls-group"):
237
  gr.Markdown("### 🎨 Style et Composition")
238
  with gr.Row():
239
  style = gr.Dropdown(
240
  choices=list(ART_STYLES.keys()),
241
+ value="Art Moderne",
242
  label="Style artistique"
243
  )
244
  layout = gr.Dropdown(
 
259
  label="Palette"
260
  )
261
 
 
262
  with gr.Group(elem_classes="controls-group"):
263
  gr.Markdown("### 📝 Contenu")
264
  subject = gr.Textbox(
 
270
  placeholder="Titre de l'affiche..."
271
  )
272
 
 
273
  with gr.Group(elem_classes="advanced-controls"):
274
  gr.Markdown("### 🎯 Ajustements Fins")
275
  with gr.Row():
 
295
  label="Saturation"
296
  )
297
 
 
298
  with gr.Group(elem_classes="controls-group"):
299
  with gr.Row():
300
  quality = gr.Slider(
 
310
  label="Créativité"
311
  )
312
 
 
313
  with gr.Row():
314
  generate_btn = gr.Button("✨ Générer", variant="primary")
315
  clear_btn = gr.Button("🗑️ Effacer", variant="secondary")
316
 
 
317
  image_output = gr.Image(label="Aperçu")
318
  status = gr.Textbox(label="Statut", interactive=False)
319