Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,10 @@ import requests
|
|
5 |
import io
|
6 |
import gc
|
7 |
import json
|
8 |
-
import time
|
9 |
from typing import Tuple, Optional, Dict, Any
|
10 |
import logging
|
11 |
from dotenv import load_dotenv
|
|
|
12 |
|
13 |
# Configuration du logging
|
14 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
@@ -23,9 +23,70 @@ TIMEOUT = 60
|
|
23 |
DEFAULT_WIDTH = 768
|
24 |
DEFAULT_HEIGHT = 768
|
25 |
|
26 |
-
# Styles artistiques
|
27 |
-
ART_STYLES = {
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
class ImageGenerator:
|
31 |
def __init__(self):
|
@@ -39,11 +100,11 @@ class ImageGenerator:
|
|
39 |
def _build_prompt(self, params: Dict[str, Any]) -> str:
|
40 |
style_info = ART_STYLES.get(params["style"], ART_STYLES["Neo Vintage"])
|
41 |
prompt = f"{style_info['prompt_prefix']}, {params['subject']}"
|
42 |
-
|
43 |
for param_type in ['layout', 'ambiance', 'palette']:
|
44 |
if params.get(param_type):
|
45 |
prompt += f", {COMPOSITION_PARAMS[param_type.capitalize() + 's'][params[param_type]]}"
|
46 |
-
|
47 |
for param, description in [
|
48 |
("detail_level", "highly detailed" if params.get("detail_level", 0) > 7 else "moderately detailed"),
|
49 |
("contrast", "high contrast" if params.get("contrast", 0) > 7 else "balanced contrast"),
|
@@ -51,10 +112,10 @@ class ImageGenerator:
|
|
51 |
]:
|
52 |
if params.get(param):
|
53 |
prompt += f", {description}"
|
54 |
-
|
55 |
if params.get("title"):
|
56 |
prompt += f", with text saying '{params['title']}'"
|
57 |
-
|
58 |
logger.debug(f"Prompt final: {prompt}")
|
59 |
return prompt
|
60 |
|
@@ -105,6 +166,9 @@ def create_interface():
|
|
105 |
.welcome { text-align: center; margin: 20px 0; padding: 20px; background: #1e293b; border-radius: 10px; color: white; }
|
106 |
.controls-group { background: #2d3748; padding: 15px; border-radius: 5px; margin: 10px 0; color: white; }
|
107 |
.advanced-controls { background: #374151; padding: 12px; border-radius: 5px; margin: 8px 0; }
|
|
|
|
|
|
|
108 |
"""
|
109 |
|
110 |
generator = ImageGenerator()
|
@@ -118,8 +182,37 @@ def create_interface():
|
|
118 |
""")
|
119 |
|
120 |
with gr.Column(elem_classes="container"):
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
with gr.Row():
|
125 |
generate_btn = gr.Button("✨ Générer", variant="primary")
|
|
|
5 |
import io
|
6 |
import gc
|
7 |
import json
|
|
|
8 |
from typing import Tuple, Optional, Dict, Any
|
9 |
import logging
|
10 |
from dotenv import load_dotenv
|
11 |
+
import time
|
12 |
|
13 |
# Configuration du logging
|
14 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
23 |
DEFAULT_WIDTH = 768
|
24 |
DEFAULT_HEIGHT = 768
|
25 |
|
26 |
+
# Styles artistiques étendus
|
27 |
+
ART_STYLES = {
|
28 |
+
"Art Moderne": {
|
29 |
+
"prompt_prefix": "modern art style poster, professional design",
|
30 |
+
"negative_prompt": "traditional, photorealistic, cluttered, busy design"
|
31 |
+
},
|
32 |
+
"Neo Vintage": {
|
33 |
+
"prompt_prefix": "vintage style advertising poster, retro design",
|
34 |
+
"negative_prompt": "modern, digital, contemporary style"
|
35 |
+
},
|
36 |
+
"Pop Art": {
|
37 |
+
"prompt_prefix": "pop art style poster, bold design",
|
38 |
+
"negative_prompt": "subtle, realistic, traditional art"
|
39 |
+
},
|
40 |
+
"Minimaliste": {
|
41 |
+
"prompt_prefix": "minimalist design poster, clean composition",
|
42 |
+
"negative_prompt": "complex, detailed, ornate, busy"
|
43 |
+
},
|
44 |
+
"Cyberpunk": {
|
45 |
+
"prompt_prefix": "cyberpunk style poster, neon lights, futuristic design",
|
46 |
+
"negative_prompt": "vintage, natural, rustic, traditional"
|
47 |
+
},
|
48 |
+
"Aquarelle": {
|
49 |
+
"prompt_prefix": "watercolor art style poster, fluid artistic design",
|
50 |
+
"negative_prompt": "digital, sharp, photorealistic"
|
51 |
+
},
|
52 |
+
"Art Déco": {
|
53 |
+
"prompt_prefix": "art deco style poster, geometric patterns, luxury design",
|
54 |
+
"negative_prompt": "modern, minimalist, casual"
|
55 |
+
},
|
56 |
+
"Japonais": {
|
57 |
+
"prompt_prefix": "japanese art style poster, ukiyo-e inspired design",
|
58 |
+
"negative_prompt": "western, modern, photographic"
|
59 |
+
},
|
60 |
+
"Ultra Réaliste": {
|
61 |
+
"prompt_prefix": "hyper-realistic poster, photographic quality, extremely detailed",
|
62 |
+
"negative_prompt": "cartoon, illustration, stylized, abstract"
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
# Paramètres de composition
|
67 |
+
COMPOSITION_PARAMS = {
|
68 |
+
"Layouts": {
|
69 |
+
"Centré": "centered composition, balanced layout",
|
70 |
+
"Asymétrique": "dynamic asymmetrical composition",
|
71 |
+
"Grille": "grid-based layout, structured composition",
|
72 |
+
"Diagonal": "diagonal dynamic composition",
|
73 |
+
"Minimaliste": "minimal composition, lots of whitespace"
|
74 |
+
},
|
75 |
+
"Ambiances": {
|
76 |
+
"Dramatique": "dramatic lighting, high contrast",
|
77 |
+
"Doux": "soft lighting, gentle atmosphere",
|
78 |
+
"Vibrant": "vibrant colors, energetic mood",
|
79 |
+
"Mystérieux": "mysterious atmosphere, moody lighting",
|
80 |
+
"Serein": "peaceful atmosphere, calm mood"
|
81 |
+
},
|
82 |
+
"Palette": {
|
83 |
+
"Monochrome": "monochromatic color scheme",
|
84 |
+
"Contrasté": "high contrast color palette",
|
85 |
+
"Pastel": "soft pastel color palette",
|
86 |
+
"Terre": "earthy color palette",
|
87 |
+
"Néon": "neon color palette"
|
88 |
+
}
|
89 |
+
}
|
90 |
|
91 |
class ImageGenerator:
|
92 |
def __init__(self):
|
|
|
100 |
def _build_prompt(self, params: Dict[str, Any]) -> str:
|
101 |
style_info = ART_STYLES.get(params["style"], ART_STYLES["Neo Vintage"])
|
102 |
prompt = f"{style_info['prompt_prefix']}, {params['subject']}"
|
103 |
+
|
104 |
for param_type in ['layout', 'ambiance', 'palette']:
|
105 |
if params.get(param_type):
|
106 |
prompt += f", {COMPOSITION_PARAMS[param_type.capitalize() + 's'][params[param_type]]}"
|
107 |
+
|
108 |
for param, description in [
|
109 |
("detail_level", "highly detailed" if params.get("detail_level", 0) > 7 else "moderately detailed"),
|
110 |
("contrast", "high contrast" if params.get("contrast", 0) > 7 else "balanced contrast"),
|
|
|
112 |
]:
|
113 |
if params.get(param):
|
114 |
prompt += f", {description}"
|
115 |
+
|
116 |
if params.get("title"):
|
117 |
prompt += f", with text saying '{params['title']}'"
|
118 |
+
|
119 |
logger.debug(f"Prompt final: {prompt}")
|
120 |
return prompt
|
121 |
|
|
|
166 |
.welcome { text-align: center; margin: 20px 0; padding: 20px; background: #1e293b; border-radius: 10px; color: white; }
|
167 |
.controls-group { background: #2d3748; padding: 15px; border-radius: 5px; margin: 10px 0; color: white; }
|
168 |
.advanced-controls { background: #374151; padding: 12px; border-radius: 5px; margin: 8px 0; }
|
169 |
+
.gradio-slider input[type="range"] { accent-color: #4a5568; }
|
170 |
+
.gradio-button { transition: all 0.3s ease; }
|
171 |
+
.gradio-button:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08); }
|
172 |
"""
|
173 |
|
174 |
generator = ImageGenerator()
|
|
|
182 |
""")
|
183 |
|
184 |
with gr.Column(elem_classes="container"):
|
185 |
+
with gr.Group(elem_classes="controls-group"):
|
186 |
+
gr.Markdown("### 📐 Format et Orientation")
|
187 |
+
with gr.Row():
|
188 |
+
format_size = gr.Dropdown(choices=["A4", "A3", "A2", "A1", "A0"], value="A4", label="Format")
|
189 |
+
orientation = gr.Radio(choices=["Portrait", "Paysage"], value="Portrait", label="Orientation")
|
190 |
+
|
191 |
+
with gr.Group(elem_classes="controls-group"):
|
192 |
+
gr.Markdown("### 🎨 Style et Composition")
|
193 |
+
with gr.Row():
|
194 |
+
style = gr.Dropdown(choices=list(ART_STYLES.keys()), value="Neo Vintage", label="Style artistique")
|
195 |
+
layout = gr.Dropdown(choices=list(COMPOSITION_PARAMS["Layouts"].keys()), value="Centré", label="Composition")
|
196 |
+
with gr.Row():
|
197 |
+
ambiance = gr.Dropdown(choices=list(COMPOSITION_PARAMS["Ambiances"].keys()), value="Dramatique", label="Ambiance")
|
198 |
+
palette = gr.Dropdown(choices=list(COMPOSITION_PARAMS["Palette"].keys()), value="Contrasté", label="Palette")
|
199 |
+
|
200 |
+
with gr.Group(elem_classes="controls-group"):
|
201 |
+
gr.Markdown("### 📝 Contenu")
|
202 |
+
subject = gr.Textbox(label="Description", placeholder="Décrivez votre vision...")
|
203 |
+
title = gr.Textbox(label="Titre", placeholder="Titre de l'affiche...")
|
204 |
+
|
205 |
+
with gr.Group(elem_classes="advanced-controls"):
|
206 |
+
gr.Markdown("### 🎯 Ajustements Fins")
|
207 |
+
with gr.Row():
|
208 |
+
detail_level = gr.Slider(minimum=1, maximum=10, value=7, step=1, label="Niveau de Détail")
|
209 |
+
contrast = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Contraste")
|
210 |
+
saturation = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Saturation")
|
211 |
+
|
212 |
+
with gr.Group(elem_classes="controls-group"):
|
213 |
+
with gr.Row():
|
214 |
+
quality = gr.Slider(minimum=30, maximum=50, value=35, label="Qualité")
|
215 |
+
creativity = gr.Slider(minimum=5, maximum=15, value=7.5, label="Créativité")
|
216 |
|
217 |
with gr.Row():
|
218 |
generate_btn = gr.Button("✨ Générer", variant="primary")
|