Equityone commited on
Commit
7860e0a
·
verified ·
1 Parent(s): 9d0c061

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -47
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
- # 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,13 +172,13 @@ class ImageGenerator:
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
 
 
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