Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import json
|
|
8 |
from typing import Tuple, Optional, Dict, Any
|
9 |
import logging
|
10 |
from dotenv import load_dotenv
|
|
|
11 |
|
12 |
# Configuration du logging
|
13 |
logging.basicConfig(
|
@@ -123,9 +124,38 @@ class ImageGenerator:
|
|
123 |
logger.info("ImageGenerator initialisé")
|
124 |
|
125 |
def _build_prompt(self, params: Dict[str, Any]) -> str:
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
style_info = ART_STYLES.get(params["style"], ART_STYLES["Art Moderne"])
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
# Ajout des paramètres de composition
|
131 |
if params.get("layout"):
|
|
|
8 |
from typing import Tuple, Optional, Dict, Any
|
9 |
import logging
|
10 |
from dotenv import load_dotenv
|
11 |
+
from prompt_enhancer import PromptEnhancer
|
12 |
|
13 |
# Configuration du logging
|
14 |
logging.basicConfig(
|
|
|
124 |
logger.info("ImageGenerator initialisé")
|
125 |
|
126 |
def _build_prompt(self, params: Dict[str, Any]) -> str:
|
127 |
+
"""Construction de prompt améliorée avec le PromptEnhancer"""
|
128 |
+
try:
|
129 |
+
# Initialisation du PromptEnhancer
|
130 |
+
enhancer = PromptEnhancer()
|
131 |
+
# Préparation du prompt initial
|
132 |
+
base_prompt = f"{params['subject']}"
|
133 |
+
if params.get('title'):
|
134 |
+
base_prompt += f", with text '{params['title']}'"
|
135 |
+
|
136 |
+
# Amélioration du prompt
|
137 |
+
enhanced_prompt = enhancer.enhance_prompt(base_prompt, style_context)
|
138 |
+
|
139 |
+
# Analyse de l'efficacité du prompt
|
140 |
+
prompt_analysis = enhancer.analyze_prompt_effectiveness(enhanced_prompt)
|
141 |
+
logger.debug(f"Analyse du prompt: {json.dumps(prompt_analysis, indent=2)}")
|
142 |
+
|
143 |
+
return enhanced_prompt
|
144 |
+
except Exception as e:
|
145 |
+
logger.error(f"Erreur dans la construction du prompt: {str(e)}")
|
146 |
+
# Fallback sur le prompt basique en cas d'erreur
|
147 |
+
return f"{style_info['prompt_prefix']}, {params['subject']}"
|
148 |
+
|
149 |
+
# Récupération du style
|
150 |
style_info = ART_STYLES.get(params["style"], ART_STYLES["Art Moderne"])
|
151 |
+
|
152 |
+
# Construction du contexte de style
|
153 |
+
style_context = {
|
154 |
+
"prompt_prefix": style_info['prompt_prefix'],
|
155 |
+
"layout": COMPOSITION_PARAMS['Layouts'][params['layout']],
|
156 |
+
"ambiance": COMPOSITION_PARAMS['Ambiances'][params['ambiance']],
|
157 |
+
"palette": COMPOSITION_PARAMS['Palette'][params['palette']]
|
158 |
+
}
|
159 |
|
160 |
# Ajout des paramètres de composition
|
161 |
if params.get("layout"):
|