Update app.py
Browse files
app.py
CHANGED
@@ -1,403 +1,185 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
from PIL import Image
|
4 |
-
import
|
5 |
-
import
|
6 |
-
import gc
|
7 |
-
import json
|
8 |
-
from typing import Tuple, Optional, Dict, Any
|
9 |
import logging
|
10 |
-
from
|
11 |
from prompt_enhancer import PromptEnhancer
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
load_dotenv()
|
22 |
-
|
23 |
-
# Styles artistiques complets
|
24 |
-
ART_STYLES = {
|
25 |
-
# Styles Classiques
|
26 |
-
"Ultra Réaliste": {
|
27 |
-
"prompt_prefix": "ultra realistic photograph, stunning photorealistic quality, unreal engine 5 quality, octane render, ray tracing, volumetric lighting, subsurface scattering, 8k UHD, cinema quality, masterpiece, perfect composition, award winning photography",
|
28 |
-
"negative_prompt": "artificial, digital art, illustration, painting, drawing, artistic, cartoon, anime, unreal, fake, low quality, blurry, soft, deformed"
|
29 |
-
},
|
30 |
-
"Photoréaliste": {
|
31 |
-
"prompt_prefix": "hyperrealistic photograph, extremely detailed, studio quality, professional photography, 8k uhd",
|
32 |
-
"negative_prompt": "artistic, painterly, abstract, cartoon, illustration, low quality"
|
33 |
-
},
|
34 |
-
"Expressionniste": {
|
35 |
-
"prompt_prefix": "expressive painting style, intense emotional art, bold brushstrokes, vibrant colors, van gogh inspired",
|
36 |
-
"negative_prompt": "realistic, subtle, photographic, clean lines, digital art"
|
37 |
-
},
|
38 |
-
"Impressionniste": {
|
39 |
-
"prompt_prefix": "impressionist painting style, soft light, visible brushstrokes, outdoor scene, monet inspired",
|
40 |
-
"negative_prompt": "sharp details, high contrast, digital, modern"
|
41 |
-
},
|
42 |
-
"Art Abstrait": {
|
43 |
-
"prompt_prefix": "abstract art, geometric shapes, non-representational, kandinsky style, pure artistic expression",
|
44 |
-
"negative_prompt": "realistic, figurative, photographic, literal"
|
45 |
-
},
|
46 |
-
"Surréaliste": {
|
47 |
-
"prompt_prefix": "surrealist art, dreamlike imagery, symbolic elements, dali inspired, metaphysical art",
|
48 |
-
"negative_prompt": "realistic, conventional, ordinary, literal"
|
49 |
-
},
|
50 |
-
"Art Moderne": {
|
51 |
-
"prompt_prefix": "modern art style poster, professional design, contemporary aesthetic",
|
52 |
-
"negative_prompt": "traditional, cluttered, busy design, vintage"
|
53 |
-
},
|
54 |
-
"Pop Art": {
|
55 |
-
"prompt_prefix": "pop art style poster, bold colors, repeated patterns, screen print effect, warhol inspired",
|
56 |
-
"negative_prompt": "subtle, realistic, traditional, painterly"
|
57 |
-
},
|
58 |
-
"Minimaliste": {
|
59 |
-
"prompt_prefix": "minimalist design poster, clean composition, elegant simplicity",
|
60 |
-
"negative_prompt": "complex, detailed, ornate, busy, cluttered"
|
61 |
-
},
|
62 |
-
"Cubiste": {
|
63 |
-
"prompt_prefix": "cubist art style, geometric fragmentation, multiple perspectives, picasso inspired",
|
64 |
-
"negative_prompt": "realistic, single perspective, traditional, photographic"
|
65 |
-
},
|
66 |
-
"Futuriste": {
|
67 |
-
"prompt_prefix": "futuristic art style, dynamic movement, technological elements, speed and motion",
|
68 |
-
"negative_prompt": "static, traditional, classical, historical"
|
69 |
-
},
|
70 |
-
"Neo Vintage": {
|
71 |
-
"prompt_prefix": "vintage style advertising poster, retro design, classic aesthetic",
|
72 |
-
"negative_prompt": "modern, digital, contemporary style"
|
73 |
-
},
|
74 |
-
"Cyberpunk": {
|
75 |
-
"prompt_prefix": "cyberpunk style poster, neon lights, futuristic design, high-tech aesthetic",
|
76 |
-
"negative_prompt": "vintage, natural, rustic, traditional"
|
77 |
-
},
|
78 |
-
"Japonais": {
|
79 |
-
"prompt_prefix": "japanese art style poster, ukiyo-e inspired design, traditional japanese aesthetic",
|
80 |
-
"negative_prompt": "western, modern, photographic"
|
81 |
-
},
|
82 |
-
"Art Déco": {
|
83 |
-
"prompt_prefix": "art deco style poster, geometric patterns, luxury design, 1920s aesthetic",
|
84 |
-
"negative_prompt": "modern, minimalist, casual, contemporary"
|
85 |
-
},
|
86 |
-
"Symboliste": {
|
87 |
-
"prompt_prefix": "symbolic art, decorative patterns, gold elements, mystical atmosphere, klimt inspired",
|
88 |
-
"negative_prompt": "realistic, simple, plain, literal"
|
89 |
-
}
|
90 |
-
}
|
91 |
-
|
92 |
-
# Paramètres de composition enrichis
|
93 |
-
COMPOSITION_PARAMS = {
|
94 |
-
"Layouts": {
|
95 |
-
"Centré": "centered composition, balanced layout, harmonious arrangement",
|
96 |
-
"Asymétrique": "dynamic asymmetrical composition, creative balance",
|
97 |
-
"Grille": "grid-based layout, structured composition, organized design",
|
98 |
-
"Diagonal": "diagonal dynamic composition, energetic flow",
|
99 |
-
"Minimaliste": "minimal composition, lots of whitespace, elegant spacing"
|
100 |
-
},
|
101 |
-
"Ambiances": {
|
102 |
-
"Dramatique": "dramatic lighting, high contrast, intense mood",
|
103 |
-
"Doux": "soft lighting, gentle atmosphere, subtle mood",
|
104 |
-
"Vibrant": "vibrant colors, energetic mood, dynamic atmosphere",
|
105 |
-
"Mystérieux": "mysterious atmosphere, moody lighting, enigmatic feel",
|
106 |
-
"Serein": "peaceful atmosphere, calm mood, tranquil setting"
|
107 |
-
},
|
108 |
-
"Palette": {
|
109 |
-
"Monochrome": "monochromatic color scheme, sophisticated tones",
|
110 |
-
"Contrasté": "high contrast color palette, bold color combinations",
|
111 |
-
"Pastel": "soft pastel color palette, gentle colors",
|
112 |
-
"Terre": "earthy color palette, natural tones",
|
113 |
-
"Néon": "neon color palette, vibrant glowing colors"
|
114 |
-
}
|
115 |
-
}
|
116 |
-
|
117 |
-
class ImageGenerator:
|
118 |
def __init__(self):
|
119 |
-
self.
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
try:
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
}
|
181 |
-
|
182 |
-
logger.debug(f"Payload: {json.dumps(payload, indent=2)}")
|
183 |
-
|
184 |
-
response = requests.post(
|
185 |
-
self.API_URL,
|
186 |
-
headers=self.headers,
|
187 |
-
json=payload,
|
188 |
-
timeout=30
|
189 |
-
)
|
190 |
-
|
191 |
-
if response.status_code == 200:
|
192 |
-
image = Image.open(io.BytesIO(response.content))
|
193 |
-
return image, "✨ Création réussie!"
|
194 |
-
else:
|
195 |
-
error_msg = f"⚠️ Erreur API {response.status_code}: {response.text}"
|
196 |
-
logger.error(error_msg)
|
197 |
-
return None, error_msg
|
198 |
-
|
199 |
except Exception as e:
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
with gr.Blocks(css=css) as app:
|
219 |
-
gr.HTML("""
|
220 |
-
<div class="welcome">
|
221 |
-
<h1>🎨 Equity Artisan 3.0</h1>
|
222 |
-
<p>Assistant de création d'affiches professionnelles</p>
|
223 |
-
</div>
|
224 |
-
""")
|
225 |
-
|
226 |
-
with gr.Column(elem_classes="container"):
|
227 |
-
# Zone d'introduction et guide
|
228 |
-
gr.Markdown("""
|
229 |
-
### 🎯 Guide d'utilisation
|
230 |
-
1. Choisissez le format et l'orientation de votre affiche
|
231 |
-
2. Sélectionnez un style artistique et une composition
|
232 |
-
3. Décrivez votre vision dans "Description"
|
233 |
-
4. Ajustez les paramètres fins selon vos besoins
|
234 |
-
5. Cliquez sur "Générer" !
|
235 |
-
""")
|
236 |
-
|
237 |
-
with gr.Group(elem_classes="controls-group"):
|
238 |
-
gr.Markdown("### 📐 Format et Orientation")
|
239 |
-
with gr.Row():
|
240 |
-
format_size = gr.Dropdown(
|
241 |
-
choices=["A4", "A3", "A2", "A1", "A0"],
|
242 |
-
value="A4",
|
243 |
-
label="Format",
|
244 |
-
info="Choisissez la taille de votre affiche. A4 est le plus petit, A0 le plus grand."
|
245 |
-
)
|
246 |
-
orientation = gr.Radio(
|
247 |
-
choices=["Portrait", "Paysage"],
|
248 |
-
value="Portrait",
|
249 |
-
label="Orientation",
|
250 |
-
info="Portrait (vertical) ou Paysage (horizontal)"
|
251 |
-
)
|
252 |
-
|
253 |
-
with gr.Group(elem_classes="controls-group"):
|
254 |
-
gr.Markdown("### 🎨 Style et Composition")
|
255 |
-
with gr.Row():
|
256 |
-
style = gr.Dropdown(
|
257 |
-
choices=list(ART_STYLES.keys()),
|
258 |
-
value="Art Moderne",
|
259 |
-
label="Style artistique",
|
260 |
-
info="Le style global de votre affiche. Chaque style a ses propres caractéristiques uniques."
|
261 |
-
)
|
262 |
-
layout = gr.Dropdown(
|
263 |
-
choices=list(COMPOSITION_PARAMS["Layouts"].keys()),
|
264 |
-
value="Centré",
|
265 |
-
label="Composition",
|
266 |
-
info="Comment les éléments seront organisés dans l'affiche"
|
267 |
-
)
|
268 |
-
|
269 |
-
with gr.Row():
|
270 |
-
ambiance = gr.Dropdown(
|
271 |
-
choices=list(COMPOSITION_PARAMS["Ambiances"].keys()),
|
272 |
-
value="Dramatique",
|
273 |
-
label="Ambiance",
|
274 |
-
info="L'atmosphère générale de votre affiche"
|
275 |
-
)
|
276 |
-
palette = gr.Dropdown(
|
277 |
-
choices=list(COMPOSITION_PARAMS["Palette"].keys()),
|
278 |
-
value="Contrasté",
|
279 |
-
label="Palette",
|
280 |
-
info="Les types de couleurs utilisées"
|
281 |
-
)
|
282 |
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
|
|
287 |
label="Description",
|
288 |
-
placeholder="
|
289 |
-
|
290 |
)
|
291 |
-
|
292 |
-
label="Titre",
|
293 |
-
placeholder="Le titre qui apparaîtra sur l'affiche...",
|
294 |
-
info="Laissez vide si vous ne voulez pas de titre sur l'affiche"
|
295 |
-
)
|
296 |
-
|
297 |
-
with gr.Group(elem_classes="advanced-controls"):
|
298 |
-
gr.Markdown("""### 🎯 Ajustements Fins
|
299 |
-
*Ces paramètres permettent d'affiner le résultat final*""")
|
300 |
with gr.Row():
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
value=
|
305 |
-
step=1,
|
306 |
-
label="Niveau de Détail",
|
307 |
-
info="Plus la valeur est élevée, plus l'image sera détaillée"
|
308 |
)
|
309 |
-
|
310 |
minimum=1,
|
311 |
-
maximum=
|
312 |
-
value=
|
313 |
-
|
314 |
-
|
315 |
-
info="Influence l'intensité des couleurs et la différence entre les zones claires et sombres"
|
316 |
-
)
|
317 |
-
saturation = gr.Slider(
|
318 |
-
minimum=1,
|
319 |
-
maximum=10,
|
320 |
-
value=5,
|
321 |
-
step=1,
|
322 |
-
label="Saturation",
|
323 |
-
info="Contrôle la vivacité des couleurs"
|
324 |
)
|
325 |
|
326 |
-
with gr.Group(elem_classes="controls-group"):
|
327 |
-
gr.Markdown("### ⚙️ Paramètres de Génération")
|
328 |
with gr.Row():
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
label="Qualité",
|
334 |
-
info="Influence la qualité finale de l'image. Une valeur plus élevée prend plus de temps"
|
335 |
)
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
value=
|
340 |
-
label="
|
341 |
-
info="Plus la valeur est élevée, plus l'IA prendra de libertés créatives"
|
342 |
)
|
343 |
|
344 |
-
with gr.
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
def
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
params = {
|
354 |
-
"
|
355 |
-
"
|
356 |
-
"
|
357 |
-
"
|
358 |
-
"ambiance": args[4],
|
359 |
-
"palette": args[5],
|
360 |
-
"subject": args[6],
|
361 |
-
"title": args[7],
|
362 |
-
"detail_level": args[8],
|
363 |
-
"contrast": args[9],
|
364 |
-
"saturation": args[10],
|
365 |
-
"quality": args[11],
|
366 |
-
"creativity": args[12]
|
367 |
}
|
368 |
-
|
369 |
-
|
370 |
-
return result
|
371 |
|
372 |
generate_btn.click(
|
373 |
-
|
374 |
-
inputs=[
|
375 |
-
|
376 |
-
|
377 |
-
style,
|
378 |
-
layout,
|
379 |
-
ambiance,
|
380 |
-
palette,
|
381 |
-
subject,
|
382 |
-
title,
|
383 |
-
detail_level,
|
384 |
-
contrast,
|
385 |
-
saturation,
|
386 |
-
quality,
|
387 |
-
creativity
|
388 |
-
],
|
389 |
-
outputs=[image_output, status]
|
390 |
-
)
|
391 |
-
|
392 |
-
clear_btn.click(
|
393 |
-
lambda: (None, "🗑️ Image effacée"),
|
394 |
-
outputs=[image_output, status]
|
395 |
)
|
396 |
|
397 |
-
|
398 |
-
return app
|
399 |
|
400 |
if __name__ == "__main__":
|
401 |
-
app =
|
402 |
-
|
403 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from typing import Dict, Any, Tuple, Optional
|
3 |
from PIL import Image
|
4 |
+
import torch
|
5 |
+
from diffusers import StableDiffusionXLPipeline, DPMSolverMultistepScheduler
|
|
|
|
|
|
|
6 |
import logging
|
7 |
+
from dataclasses import dataclass
|
8 |
from prompt_enhancer import PromptEnhancer
|
9 |
|
10 |
+
@dataclass
|
11 |
+
class GenerationConfig:
|
12 |
+
width: int = 1024
|
13 |
+
height: int = 1024
|
14 |
+
num_inference_steps: int = 50
|
15 |
+
guidance_scale: float = 7.5
|
16 |
+
high_noise_frac: float = 0.8
|
17 |
+
negative_prompt: str = ""
|
18 |
|
19 |
+
class EnhancedImageGenerator:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def __init__(self):
|
21 |
+
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
+
self.pipeline = self._initialize_pipeline()
|
23 |
+
self.prompt_enhancer = PromptEnhancer()
|
24 |
+
|
25 |
+
def _initialize_pipeline(self) -> StableDiffusionXLPipeline:
|
26 |
+
pipeline = StableDiffusionXLPipeline.from_pretrained(
|
27 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
28 |
+
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32,
|
29 |
+
use_safetensors=True,
|
30 |
+
variant="fp16" if self.device == "cuda" else None
|
31 |
+
)
|
32 |
+
|
33 |
+
# Optimisations cruciales pour la qualité
|
34 |
+
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(
|
35 |
+
pipeline.scheduler.config,
|
36 |
+
algorithm_type="dpmsolver++",
|
37 |
+
use_karras_sigmas=True
|
38 |
+
)
|
39 |
+
|
40 |
+
if self.device == "cuda":
|
41 |
+
pipeline.enable_xformers_memory_efficient_attention()
|
42 |
+
pipeline.enable_model_cpu_offload()
|
43 |
+
|
44 |
+
return pipeline
|
45 |
+
|
46 |
+
def _enhance_prompt(self, base_prompt: str, style_params: Dict[str, Any]) -> str:
|
47 |
+
"""Amélioration avancée des prompts avec analyse contextuelle"""
|
48 |
+
enhanced = self.prompt_enhancer.enhance(
|
49 |
+
base_prompt,
|
50 |
+
style=style_params["style"],
|
51 |
+
composition=style_params["composition"],
|
52 |
+
mood=style_params["mood"]
|
53 |
+
)
|
54 |
+
|
55 |
+
# Ajout d'optimisations de qualité spécifiques
|
56 |
+
quality_terms = [
|
57 |
+
"masterpiece",
|
58 |
+
"highly detailed",
|
59 |
+
"professional",
|
60 |
+
"award winning",
|
61 |
+
"stunning",
|
62 |
+
f"resolution {style_params.get('resolution', '8k')}",
|
63 |
+
"perfect composition"
|
64 |
+
]
|
65 |
+
|
66 |
+
return f"{enhanced}, {', '.join(quality_terms)}"
|
67 |
+
|
68 |
+
def generate(
|
69 |
+
self,
|
70 |
+
params: Dict[str, Any],
|
71 |
+
config: GenerationConfig
|
72 |
+
) -> Tuple[Optional[Image.Image], str]:
|
73 |
try:
|
74 |
+
# Optimisation du prompt
|
75 |
+
enhanced_prompt = self._enhance_prompt(params["prompt"], params)
|
76 |
+
|
77 |
+
# Configuration avancée de la génération
|
78 |
+
with torch.inference_mode():
|
79 |
+
image = self.pipeline(
|
80 |
+
prompt=enhanced_prompt,
|
81 |
+
negative_prompt=config.negative_prompt,
|
82 |
+
width=config.width,
|
83 |
+
height=config.height,
|
84 |
+
num_inference_steps=config.num_inference_steps,
|
85 |
+
guidance_scale=config.guidance_scale,
|
86 |
+
high_noise_frac=config.high_noise_frac,
|
87 |
+
).images[0]
|
88 |
+
|
89 |
+
return image, "Génération réussie!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
except Exception as e:
|
91 |
+
logging.error(f"Erreur lors de la génération: {str(e)}")
|
92 |
+
return None, f"Erreur: {str(e)}"
|
93 |
+
|
94 |
+
def create_enhanced_interface():
|
95 |
+
# Styles enrichis avec paramètres optimisés
|
96 |
+
ENHANCED_STYLES = {
|
97 |
+
"Ultra Réaliste": {
|
98 |
+
"prompt_enhancement": "ultra photorealistic, 8k UHD, hyperdetailed",
|
99 |
+
"quality_boost": 1.2,
|
100 |
+
"steps_multiplier": 1.3
|
101 |
+
},
|
102 |
+
"Artistique Pro": {
|
103 |
+
"prompt_enhancement": "professional artistic composition, perfect lighting",
|
104 |
+
"quality_boost": 1.1,
|
105 |
+
"steps_multiplier": 1.2
|
106 |
+
}
|
107 |
+
# ... autres styles
|
108 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
+
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
111 |
+
with gr.Row():
|
112 |
+
with gr.Column(scale=2):
|
113 |
+
# Interface utilisateur améliorée
|
114 |
+
prompt_input = gr.Textbox(
|
115 |
label="Description",
|
116 |
+
placeholder="Décrivez votre vision en détail...",
|
117 |
+
lines=3
|
118 |
)
|
119 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
with gr.Row():
|
121 |
+
style_selector = gr.Dropdown(
|
122 |
+
choices=list(ENHANCED_STYLES.keys()),
|
123 |
+
label="Style",
|
124 |
+
value="Ultra Réaliste"
|
|
|
|
|
|
|
125 |
)
|
126 |
+
quality_slider = gr.Slider(
|
127 |
minimum=1,
|
128 |
+
maximum=5,
|
129 |
+
value=4,
|
130 |
+
label="Niveau de Qualité",
|
131 |
+
info="Impact la finesse des détails"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
)
|
133 |
|
|
|
|
|
134 |
with gr.Row():
|
135 |
+
resolution_selector = gr.Radio(
|
136 |
+
choices=["4K", "8K"],
|
137 |
+
value="8K",
|
138 |
+
label="Résolution"
|
|
|
|
|
139 |
)
|
140 |
+
|
141 |
+
aspect_ratio = gr.Radio(
|
142 |
+
choices=["1:1", "16:9", "9:16"],
|
143 |
+
value="1:1",
|
144 |
+
label="Format"
|
|
|
145 |
)
|
146 |
|
147 |
+
with gr.Column(scale=3):
|
148 |
+
output_image = gr.Image(label="Résultat")
|
149 |
+
status = gr.Textbox(label="Status")
|
150 |
+
|
151 |
+
generate_btn = gr.Button("Générer", variant="primary")
|
152 |
+
|
153 |
+
# Logique de génération optimisée
|
154 |
+
def generate_optimized(prompt, style, quality, resolution, aspect):
|
155 |
+
generator = EnhancedImageGenerator()
|
156 |
+
|
157 |
+
# Configuration adaptative
|
158 |
+
config = GenerationConfig(
|
159 |
+
num_inference_steps=int(50 * ENHANCED_STYLES[style]["steps_multiplier"]),
|
160 |
+
guidance_scale=7.5 * ENHANCED_STYLES[style]["quality_boost"],
|
161 |
+
width=3840 if resolution == "4K" else 7680,
|
162 |
+
height=2160 if resolution == "4K" else 4320
|
163 |
+
)
|
164 |
+
|
165 |
params = {
|
166 |
+
"prompt": prompt,
|
167 |
+
"style": style,
|
168 |
+
"resolution": resolution,
|
169 |
+
"quality_level": quality
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
}
|
171 |
+
|
172 |
+
return generator.generate(params, config)
|
|
|
173 |
|
174 |
generate_btn.click(
|
175 |
+
generate_optimized,
|
176 |
+
inputs=[prompt_input, style_selector, quality_slider,
|
177 |
+
resolution_selector, aspect_ratio],
|
178 |
+
outputs=[output_image, status]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
)
|
180 |
|
181 |
+
return interface
|
|
|
182 |
|
183 |
if __name__ == "__main__":
|
184 |
+
app = create_enhanced_interface()
|
185 |
+
app.launch()
|
|