Equityone commited on
Commit
d814350
·
verified ·
1 Parent(s): 52c6cb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -120
app.py CHANGED
@@ -10,10 +10,7 @@ import logging
10
  from dotenv import load_dotenv
11
 
12
  # Configuration du logging
13
- logging.basicConfig(
14
- level=logging.DEBUG,
15
- format='%(asctime)s - %(levelname)s - %(message)s'
16
- )
17
  logger = logging.getLogger(__name__)
18
 
19
  # Chargement des variables d'environnement
@@ -52,6 +49,10 @@ ART_STYLES = {
52
  "Japonais": {
53
  "prompt_prefix": "japanese art style poster, ukiyo-e inspired design",
54
  "negative_prompt": "western, modern, photographic"
 
 
 
 
55
  }
56
  }
57
 
@@ -90,28 +91,20 @@ 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
98
- if params.get("layout"):
99
- prompt += f", {COMPOSITION_PARAMS['Layouts'][params['layout']]}"
100
- if params.get("ambiance"):
101
- prompt += f", {COMPOSITION_PARAMS['Ambiances'][params['ambiance']]}"
102
- if params.get("palette"):
103
- prompt += f", {COMPOSITION_PARAMS['Palette'][params['palette']]}"
104
 
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
- if params.get("contrast"):
110
- contrast_strength = params["contrast"]
111
- prompt += f", {'high contrast' if contrast_strength > 7 else 'balanced contrast'}"
112
- if params.get("saturation"):
113
- saturation_strength = params["saturation"]
114
- prompt += f", {'vibrant colors' if saturation_strength > 7 else 'subtle colors'}"
115
 
116
  if params.get("title"):
117
  prompt += f", with text saying '{params['title']}'"
@@ -126,8 +119,6 @@ class ImageGenerator:
126
  return None, "⚠️ Erreur: Token Hugging Face non configuré"
127
 
128
  prompt = self._build_prompt(params)
129
-
130
- # Configuration de base
131
  payload = {
132
  "inputs": prompt,
133
  "parameters": {
@@ -140,12 +131,7 @@ class ImageGenerator:
140
  }
141
 
142
  logger.debug(f"Payload: {json.dumps(payload, indent=2)}")
143
- response = requests.post(
144
- self.API_URL,
145
- headers=self.headers,
146
- json=payload,
147
- timeout=30
148
- )
149
 
150
  if response.status_code == 200:
151
  image = Image.open(io.BytesIO(response.content))
@@ -166,9 +152,12 @@ def create_interface():
166
  logger.info("Création de l'interface Gradio")
167
  css = """
168
  .container { max-width: 1200px; margin: auto; }
169
- .welcome { text-align: center; margin: 20px 0; padding: 20px; background: #1e293b; border-radius: 10px; }
170
- .controls-group { background: #2d3748; padding: 15px; border-radius: 5px; margin: 10px 0; }
171
- .advanced-controls { background: #374151; padding: 12px; border-radius: 5px; margin: 8px 0; }
 
 
 
172
  """
173
 
174
  generator = ImageGenerator()
@@ -176,118 +165,58 @@ def create_interface():
176
  with gr.Blocks(css=css) as app:
177
  gr.HTML("""
178
  <div class="welcome">
179
- <h1>🎨 Equity Artisan 3.0</h1>
180
- <p>Assistant de création d'affiches professionnelles</p>
181
  </div>
182
  """)
183
 
184
  with gr.Column(elem_classes="container"):
185
- # Format et Orientation
186
  with gr.Group(elem_classes="controls-group"):
187
  gr.Markdown("### 📐 Format et Orientation")
188
  with gr.Row():
189
- format_size = gr.Dropdown(
190
- choices=["A4", "A3", "A2", "A1", "A0"],
191
- value="A4",
192
- label="Format"
193
- )
194
- orientation = gr.Radio(
195
- choices=["Portrait", "Paysage"],
196
- value="Portrait",
197
- label="Orientation"
198
- )
199
 
200
- # Style et Composition
201
  with gr.Group(elem_classes="controls-group"):
202
  gr.Markdown("### 🎨 Style et Composition")
203
  with gr.Row():
204
- style = gr.Dropdown(
205
- choices=list(ART_STYLES.keys()),
206
- value="Neo Vintage",
207
- label="Style artistique"
208
- )
209
- layout = gr.Dropdown(
210
- choices=list(COMPOSITION_PARAMS["Layouts"].keys()),
211
- value="Centré",
212
- label="Composition"
213
- )
214
  with gr.Row():
215
- ambiance = gr.Dropdown(
216
- choices=list(COMPOSITION_PARAMS["Ambiances"].keys()),
217
- value="Dramatique",
218
- label="Ambiance"
219
- )
220
- palette = gr.Dropdown(
221
- choices=list(COMPOSITION_PARAMS["Palette"].keys()),
222
- value="Contrasté",
223
- label="Palette"
224
- )
225
 
226
- # Contenu
227
  with gr.Group(elem_classes="controls-group"):
228
  gr.Markdown("### 📝 Contenu")
229
- subject = gr.Textbox(
230
- label="Description",
231
- placeholder="Décrivez votre vision..."
232
- )
233
- title = gr.Textbox(
234
- label="Titre",
235
- placeholder="Titre de l'affiche..."
236
- )
237
 
238
- # Ajustements fins
239
  with gr.Group(elem_classes="advanced-controls"):
240
  gr.Markdown("### 🎯 Ajustements Fins")
241
  with gr.Row():
242
- detail_level = gr.Slider(
243
- minimum=1, maximum=10, value=7, step=1,
244
- label="Niveau de Détail"
245
- )
246
- contrast = gr.Slider(
247
- minimum=1, maximum=10, value=5, step=1,
248
- label="Contraste"
249
- )
250
- saturation = gr.Slider(
251
- minimum=1, maximum=10, value=5, step=1,
252
- label="Saturation"
253
- )
254
 
255
- # Paramètres de génération
256
  with gr.Group(elem_classes="controls-group"):
257
  with gr.Row():
258
- quality = gr.Slider(
259
- minimum=30, maximum=50, value=35,
260
- label="Qualité"
261
- )
262
- creativity = gr.Slider(
263
- minimum=5, maximum=15, value=7.5,
264
- label="Créativité"
265
- )
266
 
267
- # Boutons
268
  with gr.Row():
269
  generate_btn = gr.Button("�� Générer", variant="primary")
270
  clear_btn = gr.Button("🗑️ Effacer", variant="secondary")
271
 
272
- # Sortie
273
  image_output = gr.Image(label="Aperçu")
274
  status = gr.Textbox(label="Statut", interactive=False)
275
 
276
  def generate(*args):
277
  logger.info("Démarrage d'une nouvelle génération")
278
  params = {
279
- "format_size": args[0],
280
- "orientation": args[1],
281
- "style": args[2],
282
- "layout": args[3],
283
- "ambiance": args[4],
284
- "palette": args[5],
285
- "subject": args[6],
286
- "title": args[7],
287
- "detail_level": args[8],
288
- "contrast": args[9],
289
- "saturation": args[10],
290
- "quality": args[11],
291
  "creativity": args[12]
292
  }
293
  result = generator.generate(params)
@@ -296,17 +225,11 @@ def create_interface():
296
 
297
  generate_btn.click(
298
  generate,
299
- inputs=[
300
- format_size, orientation, style, layout, ambiance, palette,
301
- subject, title, detail_level, contrast, saturation, quality, creativity
302
- ],
303
  outputs=[image_output, status]
304
  )
305
 
306
- clear_btn.click(
307
- lambda: (None, "🗑️ Image effacée"),
308
- outputs=[image_output, status]
309
- )
310
 
311
  logger.info("Interface créée avec succès")
312
  return app
 
10
  from dotenv import load_dotenv
11
 
12
  # Configuration du logging
13
+ logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
 
 
 
14
  logger = logging.getLogger(__name__)
15
 
16
  # Chargement des variables d'environnement
 
49
  "Japonais": {
50
  "prompt_prefix": "japanese art style poster, ukiyo-e inspired design",
51
  "negative_prompt": "western, modern, photographic"
52
+ },
53
+ "Ultra Réaliste": {
54
+ "prompt_prefix": "hyper-realistic poster, photographic quality, extremely detailed",
55
+ "negative_prompt": "cartoon, illustration, stylized, abstract"
56
  }
57
  }
58
 
 
91
  logger.info("ImageGenerator initialisé")
92
 
93
  def _build_prompt(self, params: Dict[str, Any]) -> str:
 
94
  style_info = ART_STYLES.get(params["style"], ART_STYLES["Neo Vintage"])
95
  prompt = f"{style_info['prompt_prefix']}, {params['subject']}"
96
 
97
+ for param_type in ['layout', 'ambiance', 'palette']:
98
+ if params.get(param_type):
99
+ prompt += f", {COMPOSITION_PARAMS[param_type.capitalize()][params[param_type]]}"
 
 
 
 
100
 
101
+ for param, description in [
102
+ ("detail_level", "highly detailed" if params.get("detail_level", 0) > 7 else "moderately detailed"),
103
+ ("contrast", "high contrast" if params.get("contrast", 0) > 7 else "balanced contrast"),
104
+ ("saturation", "vibrant colors" if params.get("saturation", 0) > 7 else "subtle colors")
105
+ ]:
106
+ if params.get(param):
107
+ prompt += f", {description}"
 
 
 
108
 
109
  if params.get("title"):
110
  prompt += f", with text saying '{params['title']}'"
 
119
  return None, "⚠️ Erreur: Token Hugging Face non configuré"
120
 
121
  prompt = self._build_prompt(params)
 
 
122
  payload = {
123
  "inputs": prompt,
124
  "parameters": {
 
131
  }
132
 
133
  logger.debug(f"Payload: {json.dumps(payload, indent=2)}")
134
+ response = requests.post(self.API_URL, headers=self.headers, json=payload, timeout=30)
 
 
 
 
 
135
 
136
  if response.status_code == 200:
137
  image = Image.open(io.BytesIO(response.content))
 
152
  logger.info("Création de l'interface Gradio")
153
  css = """
154
  .container { max-width: 1200px; margin: auto; }
155
+ .welcome { text-align: center; margin: 20px 0; padding: 20px; background: #3498db; border-radius: 10px; color: white; }
156
+ .controls-group { background: #ecf0f1; padding: 15px; border-radius: 5px; margin: 10px 0; color: #2c3e50; }
157
+ .advanced-controls { background: #bdc3c7; padding: 12px; border-radius: 5px; margin: 8px 0; }
158
+ .gradio-slider input[type="range"] { accent-color: #3498db; }
159
+ .gradio-button { transition: all 0.3s ease; }
160
+ .gradio-button:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(52, 152, 219, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08); }
161
  """
162
 
163
  generator = ImageGenerator()
 
165
  with gr.Blocks(css=css) as app:
166
  gr.HTML("""
167
  <div class="welcome">
168
+ <h1>🎨 Equity Artisan 4.0</h1>
169
+ <p>Assistant de création d'affiches professionnelles avancé</p>
170
  </div>
171
  """)
172
 
173
  with gr.Column(elem_classes="container"):
 
174
  with gr.Group(elem_classes="controls-group"):
175
  gr.Markdown("### 📐 Format et Orientation")
176
  with gr.Row():
177
+ format_size = gr.Dropdown(choices=["A4", "A3", "A2", "A1", "A0"], value="A4", label="Format")
178
+ orientation = gr.Radio(choices=["Portrait", "Paysage"], value="Portrait", label="Orientation")
 
 
 
 
 
 
 
 
179
 
 
180
  with gr.Group(elem_classes="controls-group"):
181
  gr.Markdown("### 🎨 Style et Composition")
182
  with gr.Row():
183
+ style = gr.Dropdown(choices=list(ART_STYLES.keys()), value="Neo Vintage", label="Style artistique")
184
+ layout = gr.Dropdown(choices=list(COMPOSITION_PARAMS["Layouts"].keys()), value="Centré", label="Composition")
 
 
 
 
 
 
 
 
185
  with gr.Row():
186
+ ambiance = gr.Dropdown(choices=list(COMPOSITION_PARAMS["Ambiances"].keys()), value="Dramatique", label="Ambiance")
187
+ palette = gr.Dropdown(choices=list(COMPOSITION_PARAMS["Palette"].keys()), value="Contrasté", label="Palette")
 
 
 
 
 
 
 
 
188
 
 
189
  with gr.Group(elem_classes="controls-group"):
190
  gr.Markdown("### 📝 Contenu")
191
+ subject = gr.Textbox(label="Description", placeholder="Décrivez votre vision...")
192
+ title = gr.Textbox(label="Titre", placeholder="Titre de l'affiche...")
 
 
 
 
 
 
193
 
 
194
  with gr.Group(elem_classes="advanced-controls"):
195
  gr.Markdown("### 🎯 Ajustements Fins")
196
  with gr.Row():
197
+ detail_level = gr.Slider(minimum=1, maximum=10, value=7, step=1, label="Niveau de Détail")
198
+ contrast = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Contraste")
199
+ saturation = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Saturation")
 
 
 
 
 
 
 
 
 
200
 
 
201
  with gr.Group(elem_classes="controls-group"):
202
  with gr.Row():
203
+ quality = gr.Slider(minimum=30, maximum=50, value=35, label="Qualité")
204
+ creativity = gr.Slider(minimum=5, maximum=15, value=7.5, label="Créativité")
 
 
 
 
 
 
205
 
 
206
  with gr.Row():
207
  generate_btn = gr.Button("�� Générer", variant="primary")
208
  clear_btn = gr.Button("🗑️ Effacer", variant="secondary")
209
 
 
210
  image_output = gr.Image(label="Aperçu")
211
  status = gr.Textbox(label="Statut", interactive=False)
212
 
213
  def generate(*args):
214
  logger.info("Démarrage d'une nouvelle génération")
215
  params = {
216
+ "format_size": args[0], "orientation": args[1], "style": args[2],
217
+ "layout": args[3], "ambiance": args[4], "palette": args[5],
218
+ "subject": args[6], "title": args[7], "detail_level": args[8],
219
+ "contrast": args[9], "saturation": args[10], "quality": args[11],
 
 
 
 
 
 
 
 
220
  "creativity": args[12]
221
  }
222
  result = generator.generate(params)
 
225
 
226
  generate_btn.click(
227
  generate,
228
+ inputs=[format_size, orientation, style, layout, ambiance, palette, subject, title, detail_level, contrast, saturation, quality, creativity],
 
 
 
229
  outputs=[image_output, status]
230
  )
231
 
232
+ clear_btn.click(lambda: (None, "🗑️ Image effacée"), outputs=[image_output, status])
 
 
 
233
 
234
  logger.info("Interface créée avec succès")
235
  return app