Update app.py
Browse files
app.py
CHANGED
@@ -113,52 +113,52 @@ class ImageGenerator:
|
|
113 |
f"https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
114 |
)
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
|
126 |
def _build_prompt(self, params: Dict[str, Any]) -> str:
|
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 |
def generate(self, params: Dict[str, Any]) -> Tuple[Optional[Image.Image], str]:
|
164 |
|
@@ -172,13 +172,13 @@ class ImageGenerator:
|
|
172 |
|
173 |
payload = {
|
174 |
# Construction de la requête pour l'API Hugging Face
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
}
|
183 |
}
|
184 |
|
|
|
113 |
f"https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
114 |
)
|
115 |
|
116 |
+
# Chargement du token Hugging Face depuis les variables d'environnement
|
117 |
+
token = os.getenv('HUGGINGFACE_TOKEN')
|
118 |
+
|
119 |
+
if not token:
|
120 |
+
logger.error("HUGGINGFACE_TOKEN non trouvé!")
|
121 |
+
|
122 |
+
self.headers = {"Authorization": f"Bearer {token}"}
|
123 |
+
|
124 |
+
logger.info("ImageGenerator initialisé")
|
125 |
|
126 |
def _build_prompt(self, params: Dict[str, Any]) -> str:
|
127 |
+
"""Construction de prompt améliorée"""
|
128 |
+
|
129 |
+
style_info = ART_STYLES.get(params["style"], ART_STYLES["Neo Vintage"])
|
130 |
+
|
131 |
+
prompt = f"{style_info['prompt_prefix']}, {params['subject']}"
|
132 |
|
133 |
+
# Ajout des paramètres de composition
|
134 |
+
if params.get("layout"):
|
135 |
+
prompt += f", {COMPOSITION_PARAMS['Layouts'][params['layout']]}"
|
136 |
+
|
137 |
+
if params.get("ambiance"):
|
138 |
+
prompt += f", {COMPOSITION_PARAMS['Ambiances'][params['ambiance']]}"
|
139 |
+
|
140 |
+
if params.get("palette"):
|
141 |
+
prompt += f", {COMPOSITION_PARAMS['Palette'][params['palette']]}"
|
142 |
|
143 |
+
# Ajout des ajustements fins
|
144 |
+
if params.get("detail_level"):
|
145 |
+
detail_strength = params["detail_level"]
|
146 |
+
prompt += f", {'highly detailed' if detail_strength > 7 else 'moderately detailed'}"
|
147 |
+
|
148 |
+
if params.get("contrast"):
|
149 |
+
contrast_strength = params["contrast"]
|
150 |
+
prompt += f", {'high contrast' if contrast_strength > 7 else 'balanced contrast'}"
|
151 |
+
|
152 |
+
if params.get("saturation"):
|
153 |
+
saturation_strength = params["saturation"]
|
154 |
+
prompt += f", {'vibrant colors' if saturation_strength > 7 else 'subtle colors'}"
|
155 |
|
156 |
+
if params.get("title"):
|
157 |
+
prompt += f", with text saying '{params['title']}'"
|
158 |
|
159 |
+
logger.debug(f"Prompt final: {prompt}")
|
160 |
+
|
161 |
+
return prompt
|
162 |
|
163 |
def generate(self, params: Dict[str, Any]) -> Tuple[Optional[Image.Image], str]:
|
164 |
|
|
|
172 |
|
173 |
payload = {
|
174 |
# Construction de la requête pour l'API Hugging Face
|
175 |
+
"inputs": prompt,
|
176 |
+
"parameters": {
|
177 |
+
"negative_prompt": ART_STYLES[params["style"]]["negative_prompt"],
|
178 |
+
"num_inference_steps": min(int(35 * (params["quality"]/100)), 40),
|
179 |
+
"guidance_scale": min(7.5 * (params["creativity"]/10), 10.0),
|
180 |
+
"width": 768,
|
181 |
+
"height": 768 if params["orientation"] == “Portrait” else 512
|
182 |
}
|
183 |
}
|
184 |
|