Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
App de Mejora de Prompts para Generación de Imágenes
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -11,16 +11,16 @@ from model_configs import MODEL_CONFIGS, ARTIST_STYLES, ENHANCEMENT_RULES
|
|
| 11 |
enhancer = PromptEnhancer()
|
| 12 |
analyzer = PromptAnalyzer()
|
| 13 |
|
|
|
|
| 14 |
# ===== FUNCIONES PRINCIPALES =====
|
| 15 |
|
| 16 |
def enhance_prompt(prompt: str, model: str, style: str,
|
| 17 |
add_quality: bool, add_negative: bool) -> tuple:
|
| 18 |
"""Función principal de mejora de prompts"""
|
| 19 |
|
| 20 |
-
if not prompt.strip():
|
| 21 |
return ("⚠️ Por favor, ingresa un prompt", "", "", "", "")
|
| 22 |
|
| 23 |
-
# Mapear nombres de modelo
|
| 24 |
model_map = {
|
| 25 |
"Stable Diffusion 1.5": "stable-diffusion-1.5",
|
| 26 |
"Stable Diffusion XL": "sdxl",
|
|
@@ -30,9 +30,8 @@ def enhance_prompt(prompt: str, model: str, style: str,
|
|
| 30 |
}
|
| 31 |
|
| 32 |
model_key = model_map.get(model, "stable-diffusion-1.5")
|
| 33 |
-
style_key = style.lower() if style != "Ninguno" else None
|
| 34 |
|
| 35 |
-
# Mejorar el prompt
|
| 36 |
result = enhancer.enhance_for_model(
|
| 37 |
prompt=prompt,
|
| 38 |
model=model_key,
|
|
@@ -41,12 +40,12 @@ def enhance_prompt(prompt: str, model: str, style: str,
|
|
| 41 |
add_negative=add_negative
|
| 42 |
)
|
| 43 |
|
| 44 |
-
# Formatear análisis
|
| 45 |
analysis = result["analysis"]
|
| 46 |
score_emoji = "🟢" if analysis["score"] >= 70 else "🟡" if analysis["score"] >= 40 else "🔴"
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
**Puntuación:** {score_emoji} {analysis['score']}/100
|
| 52 |
|
|
@@ -56,10 +55,9 @@ def enhance_prompt(prompt: str, model: str, style: str,
|
|
| 56 |
- Tokens estimados: {result['tokens_estimate']}/{result['max_tokens']}
|
| 57 |
|
| 58 |
**Sugerencias:**
|
| 59 |
-
{
|
| 60 |
"""
|
| 61 |
|
| 62 |
-
# Generar variaciones
|
| 63 |
variations = enhancer.suggest_variations(result["enhanced"], 3)
|
| 64 |
variations_text = "\n\n".join([f"**Variación {i+1}:**\n`{v}`" for i, v in enumerate(variations)])
|
| 65 |
|
|
@@ -75,7 +73,7 @@ def enhance_prompt(prompt: str, model: str, style: str,
|
|
| 75 |
def fix_prompt(prompt: str) -> tuple:
|
| 76 |
"""Corrige errores comunes en el prompt"""
|
| 77 |
|
| 78 |
-
if not prompt.strip():
|
| 79 |
return ("⚠️ Por favor, ingresa un prompt", "")
|
| 80 |
|
| 81 |
fixed, fixes = enhancer.fix_common_errors(prompt)
|
|
@@ -92,12 +90,10 @@ def build_prompt(subject: str, style: str, lighting: str, mood: str,
|
|
| 92 |
camera: str, quality_opts: list, extra_details: str) -> str:
|
| 93 |
"""Construye un prompt desde componentes"""
|
| 94 |
|
| 95 |
-
if not subject.strip():
|
| 96 |
return "⚠️ Por favor, ingresa al menos un sujeto"
|
| 97 |
|
| 98 |
builder = PromptBuilder()
|
| 99 |
-
|
| 100 |
-
# Configurar componentes
|
| 101 |
builder.set_subject(subject)
|
| 102 |
|
| 103 |
if style and style != "Ninguno":
|
|
@@ -126,7 +122,7 @@ def build_prompt(subject: str, style: str, lighting: str, mood: str,
|
|
| 126 |
quality_terms.extend(quality_map[opt])
|
| 127 |
builder.add_quality(quality_terms)
|
| 128 |
|
| 129 |
-
if extra_details.strip():
|
| 130 |
builder.add_details([extra_details.strip()])
|
| 131 |
|
| 132 |
return builder.build()
|
|
@@ -135,13 +131,12 @@ def build_prompt(subject: str, style: str, lighting: str, mood: str,
|
|
| 135 |
def analyze_only(prompt: str) -> str:
|
| 136 |
"""Solo analiza el prompt sin mejorarlo"""
|
| 137 |
|
| 138 |
-
if not prompt.strip():
|
| 139 |
return "⚠️ Por favor, ingresa un prompt para analizar"
|
| 140 |
|
| 141 |
analysis = analyzer.analyze(prompt)
|
| 142 |
-
|
| 143 |
-
# Crear reporte detallado
|
| 144 |
score = analysis["score"]
|
|
|
|
| 145 |
if score >= 80:
|
| 146 |
grade = "🏆 Excelente"
|
| 147 |
elif score >= 60:
|
|
@@ -151,7 +146,6 @@ def analyze_only(prompt: str) -> str:
|
|
| 151 |
else:
|
| 152 |
grade = "❌ Necesita trabajo"
|
| 153 |
|
| 154 |
-
issues_text = ""
|
| 155 |
if analysis["issues"]:
|
| 156 |
issue_names = {
|
| 157 |
"muy_corto": "❌ Prompt muy corto",
|
|
@@ -165,8 +159,9 @@ def analyze_only(prompt: str) -> str:
|
|
| 165 |
else:
|
| 166 |
issues_text = "✅ No se detectaron problemas"
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
### Calificación: {grade} ({score}/100)
|
| 172 |
|
|
@@ -186,7 +181,7 @@ def analyze_only(prompt: str) -> str:
|
|
| 186 |
---
|
| 187 |
|
| 188 |
### 💡 Sugerencias de Mejora
|
| 189 |
-
{
|
| 190 |
|
| 191 |
---
|
| 192 |
|
|
@@ -204,214 +199,289 @@ def analyze_only(prompt: str) -> str:
|
|
| 204 |
def get_style_examples(style: str) -> str:
|
| 205 |
"""Muestra ejemplos para un estilo específico"""
|
| 206 |
|
| 207 |
-
if style == "Ninguno"
|
| 208 |
return "Selecciona un estilo para ver ejemplos"
|
| 209 |
|
| 210 |
examples = {
|
| 211 |
-
"Fotorealista": """
|
| 212 |
-
**Ejemplos de prompts fotorealistas:**
|
| 213 |
|
| 214 |
1. `professional photograph of a woman, natural lighting, 85mm lens, shallow depth of field, photorealistic, 8k uhd`
|
| 215 |
|
| 216 |
2. `hyperrealistic photo of a mountain landscape, golden hour, dramatic clouds, raw photo, high dynamic range`
|
| 217 |
|
| 218 |
-
3. `product photography of a luxury watch, studio lighting, macro shot, commercial photography, pristine details`
|
| 219 |
-
|
| 220 |
-
"Anime": """
|
| 221 |
-
**Ejemplos de prompts anime:**
|
| 222 |
|
| 223 |
1. `anime girl with blue hair, cherry blossom background, studio ghibli style, vibrant colors, detailed eyes, key visual`
|
| 224 |
|
| 225 |
2. `epic anime battle scene, dynamic action pose, energy effects, dramatic lighting, anime key visual, trending on pixiv`
|
| 226 |
|
| 227 |
-
3. `cozy anime room interior, warm lighting, detailed background, slice of life aesthetic, makoto shinkai style`
|
| 228 |
-
|
| 229 |
-
"Arte Digital": """
|
| 230 |
-
**Ejemplos de arte digital:**
|
| 231 |
|
| 232 |
1. `digital painting of a fantasy castle, dramatic sky, concept art, artstation trending, highly detailed, epic composition`
|
| 233 |
|
| 234 |
2. `character design, full body portrait, detailed armor, digital art, fantasy warrior, professional illustration`
|
| 235 |
|
| 236 |
-
3. `environment concept art, alien planet, sci-fi landscape, matte painting, cinematic, artstation winner`
|
| 237 |
-
|
| 238 |
-
"Pintura": """
|
| 239 |
-
**Ejemplos de pintura:**
|
| 240 |
|
| 241 |
1. `oil painting of a serene lake, impressionist style, visible brush strokes, golden hour lighting, museum quality`
|
| 242 |
|
| 243 |
2. `renaissance portrait, classical technique, dramatic chiaroscuro, oil on canvas, by old masters`
|
| 244 |
|
| 245 |
-
3. `watercolor landscape, soft edges, wet on wet technique, delicate colors, paper texture visible`
|
| 246 |
-
|
| 247 |
-
"3D": """
|
| 248 |
-
**Ejemplos de 3D/CGI:**
|
| 249 |
|
| 250 |
1. `3D render of a cute robot character, octane render, subsurface scattering, studio lighting, pixar style`
|
| 251 |
|
| 252 |
2. `architectural visualization, modern house, ray tracing, unreal engine 5, photorealistic materials`
|
| 253 |
|
| 254 |
-
3. `3D character model, fantasy creature, zbrush detail, substance painter textures, turntable view`
|
| 255 |
-
|
| 256 |
-
"Cinematico": """
|
| 257 |
-
**Ejemplos cinematográficos:**
|
| 258 |
|
| 259 |
1. `cinematic still from a sci-fi movie, anamorphic lens, dramatic lighting, movie poster composition, 4k`
|
| 260 |
|
| 261 |
2. `film noir scene, high contrast, dramatic shadows, mysterious atmosphere, classic hollywood style`
|
| 262 |
|
| 263 |
-
3. `epic movie landscape, sweeping vista, volumetric fog, golden hour, widescreen composition`
|
| 264 |
-
"""
|
| 265 |
}
|
| 266 |
|
| 267 |
return examples.get(style, "No hay ejemplos disponibles para este estilo")
|
| 268 |
|
| 269 |
|
| 270 |
-
# ===== INTERFAZ GRADIO =====
|
| 271 |
-
|
| 272 |
-
# CSS personalizado
|
| 273 |
-
custom_css = """
|
| 274 |
-
.gradio-container {
|
| 275 |
-
max-width: 1200px !important;
|
| 276 |
-
}
|
| 277 |
-
.main-title {
|
| 278 |
-
text-align: center;
|
| 279 |
-
color: #2563eb;
|
| 280 |
-
margin-bottom: 0.5em;
|
| 281 |
-
}
|
| 282 |
-
.subtitle {
|
| 283 |
-
text-align: center;
|
| 284 |
-
color: #6b7280;
|
| 285 |
-
font-size: 1.1em;
|
| 286 |
-
margin-bottom: 1.5em;
|
| 287 |
-
}
|
| 288 |
-
.prompt-output {
|
| 289 |
-
font-family: monospace;
|
| 290 |
-
background-color: #f3f4f6;
|
| 291 |
-
padding: 10px;
|
| 292 |
-
border-radius: 8px;
|
| 293 |
-
}
|
| 294 |
-
"""
|
| 295 |
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
gr.HTML("""
|
| 300 |
-
<h1 class='main-title'>🎨 Prompt Enhancer Pro</h1>
|
| 301 |
-
<p class='subtitle'>Mejora y optimiza tus prompts para generación de imágenes con IA</p>
|
| 302 |
-
""")
|
| 303 |
|
| 304 |
-
with gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
-
|
| 307 |
-
with gr.TabItem("✨ Mejorar Prompt"):
|
| 308 |
-
gr.Markdown("### Transforma tu prompt simple en uno profesional")
|
| 309 |
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
-
with gr.
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
label="Modelo destino"
|
| 324 |
)
|
| 325 |
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
label="Estilo artístico"
|
| 331 |
)
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
add_quality = gr.Checkbox(label="Añadir tokens de calidad", value=True)
|
| 335 |
-
add_negative = gr.Checkbox(label="Generar negative prompt", value=True)
|
| 336 |
-
|
| 337 |
-
enhance_btn = gr.Button("🚀 Mejorar Prompt", variant="primary")
|
| 338 |
|
| 339 |
-
with gr.
|
| 340 |
-
|
| 341 |
-
label="
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
)
|
| 345 |
-
|
| 346 |
-
output_negative = gr.Textbox(
|
| 347 |
-
label="❌ Negative prompt",
|
| 348 |
-
lines=2,
|
| 349 |
-
interactive=False
|
| 350 |
-
)
|
| 351 |
-
|
| 352 |
-
model_info = gr.Markdown("")
|
| 353 |
-
|
| 354 |
-
with gr.Row():
|
| 355 |
-
with gr.Column():
|
| 356 |
-
analysis_output = gr.Markdown(label="Análisis")
|
| 357 |
-
with gr.Column():
|
| 358 |
-
variations_output = gr.Markdown(label="Variaciones sugeridas")
|
| 359 |
-
|
| 360 |
-
enhance_btn.click(
|
| 361 |
-
fn=enhance_prompt,
|
| 362 |
-
inputs=[input_prompt, model_select, style_select, add_quality, add_negative],
|
| 363 |
-
outputs=[output_prompt, output_negative, analysis_output, variations_output, model_info]
|
| 364 |
-
)
|
| 365 |
-
|
| 366 |
-
# ===== TAB 2: CORRECTOR =====
|
| 367 |
-
with gr.TabItem("🔧 Corrector de Errores"):
|
| 368 |
-
gr.Markdown("### Detecta y corrige errores comunes en tus prompts")
|
| 369 |
-
|
| 370 |
-
with gr.Row():
|
| 371 |
-
with gr.Column():
|
| 372 |
-
fix_input = gr.Textbox(
|
| 373 |
-
label="Prompt con posibles errores",
|
| 374 |
-
placeholder="Pega aquí un prompt que quieras revisar...",
|
| 375 |
-
lines=4
|
| 376 |
-
)
|
| 377 |
-
fix_btn = gr.Button("🔍 Analizar y Corregir", variant="primary")
|
| 378 |
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
)
|
| 385 |
-
fixes_log = gr.Markdown("")
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
-
with gr.
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
value="Ninguno",
|
| 410 |
-
label="Estilo artístico"
|
| 411 |
)
|
| 412 |
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
App de Mejora de Prompts para Generación de Imágenes
|
| 3 |
+
Compatible con Gradio 6.0+
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 11 |
enhancer = PromptEnhancer()
|
| 12 |
analyzer = PromptAnalyzer()
|
| 13 |
|
| 14 |
+
|
| 15 |
# ===== FUNCIONES PRINCIPALES =====
|
| 16 |
|
| 17 |
def enhance_prompt(prompt: str, model: str, style: str,
|
| 18 |
add_quality: bool, add_negative: bool) -> tuple:
|
| 19 |
"""Función principal de mejora de prompts"""
|
| 20 |
|
| 21 |
+
if not prompt or not prompt.strip():
|
| 22 |
return ("⚠️ Por favor, ingresa un prompt", "", "", "", "")
|
| 23 |
|
|
|
|
| 24 |
model_map = {
|
| 25 |
"Stable Diffusion 1.5": "stable-diffusion-1.5",
|
| 26 |
"Stable Diffusion XL": "sdxl",
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
model_key = model_map.get(model, "stable-diffusion-1.5")
|
| 33 |
+
style_key = style.lower() if style and style != "Ninguno" else None
|
| 34 |
|
|
|
|
| 35 |
result = enhancer.enhance_for_model(
|
| 36 |
prompt=prompt,
|
| 37 |
model=model_key,
|
|
|
|
| 40 |
add_negative=add_negative
|
| 41 |
)
|
| 42 |
|
|
|
|
| 43 |
analysis = result["analysis"]
|
| 44 |
score_emoji = "🟢" if analysis["score"] >= 70 else "🟡" if analysis["score"] >= 40 else "🔴"
|
| 45 |
|
| 46 |
+
suggestions_text = '\n'.join(analysis['suggestions']) if analysis['suggestions'] else '✅ ¡El prompt está bien estructurado!'
|
| 47 |
+
|
| 48 |
+
analysis_text = f"""### 📊 Análisis del Prompt
|
| 49 |
|
| 50 |
**Puntuación:** {score_emoji} {analysis['score']}/100
|
| 51 |
|
|
|
|
| 55 |
- Tokens estimados: {result['tokens_estimate']}/{result['max_tokens']}
|
| 56 |
|
| 57 |
**Sugerencias:**
|
| 58 |
+
{suggestions_text}
|
| 59 |
"""
|
| 60 |
|
|
|
|
| 61 |
variations = enhancer.suggest_variations(result["enhanced"], 3)
|
| 62 |
variations_text = "\n\n".join([f"**Variación {i+1}:**\n`{v}`" for i, v in enumerate(variations)])
|
| 63 |
|
|
|
|
| 73 |
def fix_prompt(prompt: str) -> tuple:
|
| 74 |
"""Corrige errores comunes en el prompt"""
|
| 75 |
|
| 76 |
+
if not prompt or not prompt.strip():
|
| 77 |
return ("⚠️ Por favor, ingresa un prompt", "")
|
| 78 |
|
| 79 |
fixed, fixes = enhancer.fix_common_errors(prompt)
|
|
|
|
| 90 |
camera: str, quality_opts: list, extra_details: str) -> str:
|
| 91 |
"""Construye un prompt desde componentes"""
|
| 92 |
|
| 93 |
+
if not subject or not subject.strip():
|
| 94 |
return "⚠️ Por favor, ingresa al menos un sujeto"
|
| 95 |
|
| 96 |
builder = PromptBuilder()
|
|
|
|
|
|
|
| 97 |
builder.set_subject(subject)
|
| 98 |
|
| 99 |
if style and style != "Ninguno":
|
|
|
|
| 122 |
quality_terms.extend(quality_map[opt])
|
| 123 |
builder.add_quality(quality_terms)
|
| 124 |
|
| 125 |
+
if extra_details and extra_details.strip():
|
| 126 |
builder.add_details([extra_details.strip()])
|
| 127 |
|
| 128 |
return builder.build()
|
|
|
|
| 131 |
def analyze_only(prompt: str) -> str:
|
| 132 |
"""Solo analiza el prompt sin mejorarlo"""
|
| 133 |
|
| 134 |
+
if not prompt or not prompt.strip():
|
| 135 |
return "⚠️ Por favor, ingresa un prompt para analizar"
|
| 136 |
|
| 137 |
analysis = analyzer.analyze(prompt)
|
|
|
|
|
|
|
| 138 |
score = analysis["score"]
|
| 139 |
+
|
| 140 |
if score >= 80:
|
| 141 |
grade = "🏆 Excelente"
|
| 142 |
elif score >= 60:
|
|
|
|
| 146 |
else:
|
| 147 |
grade = "❌ Necesita trabajo"
|
| 148 |
|
|
|
|
| 149 |
if analysis["issues"]:
|
| 150 |
issue_names = {
|
| 151 |
"muy_corto": "❌ Prompt muy corto",
|
|
|
|
| 159 |
else:
|
| 160 |
issues_text = "✅ No se detectaron problemas"
|
| 161 |
|
| 162 |
+
suggestions_text = '\n'.join(analysis['suggestions']) if analysis['suggestions'] else '¡El prompt está bien estructurado!'
|
| 163 |
+
|
| 164 |
+
report = f"""## 📊 Análisis Detallado
|
| 165 |
|
| 166 |
### Calificación: {grade} ({score}/100)
|
| 167 |
|
|
|
|
| 181 |
---
|
| 182 |
|
| 183 |
### 💡 Sugerencias de Mejora
|
| 184 |
+
{suggestions_text}
|
| 185 |
|
| 186 |
---
|
| 187 |
|
|
|
|
| 199 |
def get_style_examples(style: str) -> str:
|
| 200 |
"""Muestra ejemplos para un estilo específico"""
|
| 201 |
|
| 202 |
+
if not style or style == "Ninguno":
|
| 203 |
return "Selecciona un estilo para ver ejemplos"
|
| 204 |
|
| 205 |
examples = {
|
| 206 |
+
"Fotorealista": """**Ejemplos de prompts fotorealistas:**
|
|
|
|
| 207 |
|
| 208 |
1. `professional photograph of a woman, natural lighting, 85mm lens, shallow depth of field, photorealistic, 8k uhd`
|
| 209 |
|
| 210 |
2. `hyperrealistic photo of a mountain landscape, golden hour, dramatic clouds, raw photo, high dynamic range`
|
| 211 |
|
| 212 |
+
3. `product photography of a luxury watch, studio lighting, macro shot, commercial photography, pristine details`""",
|
| 213 |
+
|
| 214 |
+
"Anime": """**Ejemplos de prompts anime:**
|
|
|
|
| 215 |
|
| 216 |
1. `anime girl with blue hair, cherry blossom background, studio ghibli style, vibrant colors, detailed eyes, key visual`
|
| 217 |
|
| 218 |
2. `epic anime battle scene, dynamic action pose, energy effects, dramatic lighting, anime key visual, trending on pixiv`
|
| 219 |
|
| 220 |
+
3. `cozy anime room interior, warm lighting, detailed background, slice of life aesthetic, makoto shinkai style`""",
|
| 221 |
+
|
| 222 |
+
"Arte Digital": """**Ejemplos de arte digital:**
|
|
|
|
| 223 |
|
| 224 |
1. `digital painting of a fantasy castle, dramatic sky, concept art, artstation trending, highly detailed, epic composition`
|
| 225 |
|
| 226 |
2. `character design, full body portrait, detailed armor, digital art, fantasy warrior, professional illustration`
|
| 227 |
|
| 228 |
+
3. `environment concept art, alien planet, sci-fi landscape, matte painting, cinematic, artstation winner`""",
|
| 229 |
+
|
| 230 |
+
"Pintura": """**Ejemplos de pintura:**
|
|
|
|
| 231 |
|
| 232 |
1. `oil painting of a serene lake, impressionist style, visible brush strokes, golden hour lighting, museum quality`
|
| 233 |
|
| 234 |
2. `renaissance portrait, classical technique, dramatic chiaroscuro, oil on canvas, by old masters`
|
| 235 |
|
| 236 |
+
3. `watercolor landscape, soft edges, wet on wet technique, delicate colors, paper texture visible`""",
|
| 237 |
+
|
| 238 |
+
"3D": """**Ejemplos de 3D/CGI:**
|
|
|
|
| 239 |
|
| 240 |
1. `3D render of a cute robot character, octane render, subsurface scattering, studio lighting, pixar style`
|
| 241 |
|
| 242 |
2. `architectural visualization, modern house, ray tracing, unreal engine 5, photorealistic materials`
|
| 243 |
|
| 244 |
+
3. `3D character model, fantasy creature, zbrush detail, substance painter textures, turntable view`""",
|
| 245 |
+
|
| 246 |
+
"Cinematico": """**Ejemplos cinematográficos:**
|
|
|
|
| 247 |
|
| 248 |
1. `cinematic still from a sci-fi movie, anamorphic lens, dramatic lighting, movie poster composition, 4k`
|
| 249 |
|
| 250 |
2. `film noir scene, high contrast, dramatic shadows, mysterious atmosphere, classic hollywood style`
|
| 251 |
|
| 252 |
+
3. `epic movie landscape, sweeping vista, volumetric fog, golden hour, widescreen composition`"""
|
|
|
|
| 253 |
}
|
| 254 |
|
| 255 |
return examples.get(style, "No hay ejemplos disponibles para este estilo")
|
| 256 |
|
| 257 |
|
| 258 |
+
# ===== INTERFAZ GRADIO 6.0+ =====
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
+
def create_app():
|
| 261 |
+
"""Crea la aplicación Gradio"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
+
with gr.Blocks(title="Prompt Enhancer Pro") as app:
|
| 264 |
+
|
| 265 |
+
gr.HTML("""
|
| 266 |
+
<div style="text-align: center; margin-bottom: 1.5em;">
|
| 267 |
+
<h1 style="color: #2563eb; margin-bottom: 0.3em;">🎨 Prompt Enhancer Pro</h1>
|
| 268 |
+
<p style="color: #6b7280; font-size: 1.1em;">Mejora y optimiza tus prompts para generación de imágenes con IA</p>
|
| 269 |
+
</div>
|
| 270 |
+
""")
|
| 271 |
|
| 272 |
+
with gr.Tabs():
|
|
|
|
|
|
|
| 273 |
|
| 274 |
+
# ===== TAB 1: MEJORAR PROMPT =====
|
| 275 |
+
with gr.TabItem("✨ Mejorar Prompt"):
|
| 276 |
+
gr.Markdown("### Transforma tu prompt simple en uno profesional")
|
| 277 |
+
|
| 278 |
+
with gr.Row():
|
| 279 |
+
with gr.Column(scale=1):
|
| 280 |
+
input_prompt = gr.Textbox(
|
| 281 |
+
label="Tu prompt original",
|
| 282 |
+
placeholder="Escribe tu prompt aquí... (puede ser en español o inglés)",
|
| 283 |
+
lines=3
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
with gr.Row():
|
| 287 |
+
model_select = gr.Dropdown(
|
| 288 |
+
choices=["Stable Diffusion 1.5", "Stable Diffusion XL",
|
| 289 |
+
"FLUX.1", "Midjourney", "DALL-E 3"],
|
| 290 |
+
value="Stable Diffusion XL",
|
| 291 |
+
label="Modelo destino"
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
style_select = gr.Dropdown(
|
| 295 |
+
choices=["Ninguno", "Fotorealista", "Anime", "Arte Digital",
|
| 296 |
+
"Pintura", "3D", "Cinematico", "Minimalista", "Fantasia"],
|
| 297 |
+
value="Ninguno",
|
| 298 |
+
label="Estilo artístico"
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
with gr.Row():
|
| 302 |
+
add_quality = gr.Checkbox(label="Añadir tokens de calidad", value=True)
|
| 303 |
+
add_negative = gr.Checkbox(label="Generar negative prompt", value=True)
|
| 304 |
+
|
| 305 |
+
enhance_btn = gr.Button("🚀 Mejorar Prompt", variant="primary")
|
| 306 |
|
| 307 |
+
with gr.Column(scale=1):
|
| 308 |
+
output_prompt = gr.Textbox(
|
| 309 |
+
label="✅ Prompt mejorado",
|
| 310 |
+
lines=4,
|
| 311 |
+
interactive=False
|
|
|
|
| 312 |
)
|
| 313 |
|
| 314 |
+
output_negative = gr.Textbox(
|
| 315 |
+
label="❌ Negative prompt",
|
| 316 |
+
lines=2,
|
| 317 |
+
interactive=False
|
|
|
|
| 318 |
)
|
| 319 |
+
|
| 320 |
+
model_info = gr.Markdown("")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
+
with gr.Row():
|
| 323 |
+
with gr.Column():
|
| 324 |
+
analysis_output = gr.Markdown(label="Análisis")
|
| 325 |
+
with gr.Column():
|
| 326 |
+
variations_output = gr.Markdown(label="Variaciones sugeridas")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
+
enhance_btn.click(
|
| 329 |
+
fn=enhance_prompt,
|
| 330 |
+
inputs=[input_prompt, model_select, style_select, add_quality, add_negative],
|
| 331 |
+
outputs=[output_prompt, output_negative, analysis_output, variations_output, model_info]
|
| 332 |
+
)
|
|
|
|
|
|
|
| 333 |
|
| 334 |
+
# ===== TAB 2: CORRECTOR =====
|
| 335 |
+
with gr.TabItem("🔧 Corrector de Errores"):
|
| 336 |
+
gr.Markdown("### Detecta y corrige errores comunes en tus prompts")
|
| 337 |
+
|
| 338 |
+
with gr.Row():
|
| 339 |
+
with gr.Column():
|
| 340 |
+
fix_input = gr.Textbox(
|
| 341 |
+
label="Prompt con posibles errores",
|
| 342 |
+
placeholder="Pega aquí un prompt que quieras revisar...",
|
| 343 |
+
lines=4
|
| 344 |
+
)
|
| 345 |
+
fix_btn = gr.Button("🔍 Analizar y Corregir", variant="primary")
|
| 346 |
+
|
| 347 |
+
with gr.Column():
|
| 348 |
+
fix_output = gr.Textbox(
|
| 349 |
+
label="Prompt corregido",
|
| 350 |
+
lines=4,
|
| 351 |
+
interactive=False
|
| 352 |
+
)
|
| 353 |
+
fixes_log = gr.Markdown("")
|
| 354 |
+
|
| 355 |
+
fix_btn.click(
|
| 356 |
+
fn=fix_prompt,
|
| 357 |
+
inputs=[fix_input],
|
| 358 |
+
outputs=[fix_output, fixes_log]
|
| 359 |
+
)
|
| 360 |
|
| 361 |
+
# ===== TAB 3: CONSTRUCTOR =====
|
| 362 |
+
with gr.TabItem("🏗️ Constructor de Prompts"):
|
| 363 |
+
gr.Markdown("### Construye un prompt paso a paso")
|
| 364 |
+
|
| 365 |
+
with gr.Row():
|
| 366 |
+
with gr.Column():
|
| 367 |
+
build_subject = gr.Textbox(
|
| 368 |
+
label="Sujeto principal *",
|
| 369 |
+
placeholder="Ej: a young woman with red hair, a futuristic city..."
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
with gr.Row():
|
| 373 |
+
build_style = gr.Dropdown(
|
| 374 |
+
choices=["Ninguno", "Clasico", "Impresionista", "Surrealista",
|
| 375 |
+
"Pop Art", "Art Nouveau", "Concept Art", "Anime",
|
| 376 |
+
"Fantasia", "Sci-fi", "Horror"],
|
| 377 |
+
value="Ninguno",
|
| 378 |
+
label="Estilo artístico"
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
build_lighting = gr.Dropdown(
|
| 382 |
+
choices=["Ninguno", "Dramatica", "Suave", "Natural",
|
| 383 |
+
"Estudio", "Neon", "Cinematica"],
|
| 384 |
+
value="Ninguno",
|
| 385 |
+
label="Iluminación"
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
with gr.Row():
|
| 389 |
+
build_mood = gr.Dropdown(
|
| 390 |
+
choices=["Ninguno", "Oscuro", "Alegre", "Melancolico",
|
| 391 |
+
"Epico", "Sereno", "Intenso"],
|
| 392 |
+
value="Ninguno",
|
| 393 |
+
label="Ambiente/Mood"
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
build_camera = gr.Dropdown(
|
| 397 |
+
choices=["Ninguno", "Cercano", "Lejano", "Retrato",
|
| 398 |
+
"Aereo", "Bajo", "Alto"],
|
| 399 |
+
value="Ninguno",
|
| 400 |
+
label="Ángulo/Encuadre"
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
build_quality = gr.CheckboxGroup(
|
| 404 |
+
choices=["Alta definición (8K)", "Muy detallado", "Masterpiece",
|
| 405 |
+
"Fotografía profesional", "Arte de alta calidad"],
|
| 406 |
+
label="Calidad"
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
build_extra = gr.Textbox(
|
| 410 |
+
label="Detalles adicionales",
|
| 411 |
+
placeholder="Añade cualquier detalle extra..."
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
build_btn = gr.Button("🔨 Construir Prompt", variant="primary")
|
| 415 |
|
| 416 |
+
with gr.Column():
|
| 417 |
+
build_output = gr.Textbox(
|
| 418 |
+
label="Prompt construido",
|
| 419 |
+
lines=6,
|
| 420 |
+
interactive=False
|
|
|
|
|
|
|
| 421 |
)
|
| 422 |
|
| 423 |
+
gr.Markdown("""### 💡 Tips para cada componente:
|
| 424 |
+
|
| 425 |
+
- **Sujeto**: Sé específico. "young woman with curly red hair" > "woman"
|
| 426 |
+
- **Estilo**: Define la estética visual del resultado
|
| 427 |
+
- **Iluminación**: Afecta dramáticamente el mood de la imagen
|
| 428 |
+
- **Ambiente**: Establece el tono emocional
|
| 429 |
+
- **Encuadre**: Controla la composición de la imagen""")
|
| 430 |
+
|
| 431 |
+
build_btn.click(
|
| 432 |
+
fn=build_prompt,
|
| 433 |
+
inputs=[build_subject, build_style, build_lighting, build_mood,
|
| 434 |
+
build_camera, build_quality, build_extra],
|
| 435 |
+
outputs=[build_output]
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
# ===== TAB 4: ANALIZADOR =====
|
| 439 |
+
with gr.TabItem("📊 Analizador"):
|
| 440 |
+
gr.Markdown("### Analiza la calidad y estructura de tu prompt")
|
| 441 |
+
|
| 442 |
+
with gr.Row():
|
| 443 |
+
with gr.Column():
|
| 444 |
+
analyze_input = gr.Textbox(
|
| 445 |
+
label="Prompt a analizar",
|
| 446 |
+
placeholder="Pega cualquier prompt para obtener un análisis detallado...",
|
| 447 |
+
lines=4
|
| 448 |
+
)
|
| 449 |
+
analyze_btn = gr.Button("📊 Analizar", variant="primary")
|
| 450 |
+
|
| 451 |
+
with gr.Column():
|
| 452 |
+
analyze_output = gr.Markdown("")
|
| 453 |
+
|
| 454 |
+
analyze_btn.click(
|
| 455 |
+
fn=analyze_only,
|
| 456 |
+
inputs=[analyze_input],
|
| 457 |
+
outputs=[analyze_output]
|
| 458 |
+
)
|
| 459 |
+
|
| 460 |
+
# ===== TAB 5: EJEMPLOS Y GUÍA =====
|
| 461 |
+
with gr.TabItem("📚 Guía y Ejemplos"):
|
| 462 |
+
gr.Markdown("### Aprende a crear mejores prompts")
|
| 463 |
+
|
| 464 |
+
with gr.Row():
|
| 465 |
+
with gr.Column():
|
| 466 |
+
example_style = gr.Dropdown(
|
| 467 |
+
choices=["Fotorealista", "Anime", "Arte Digital",
|
| 468 |
+
"Pintura", "3D", "Cinematico"],
|
| 469 |
+
value="Fotorealista",
|
| 470 |
+
label="Selecciona un estilo"
|
| 471 |
+
)
|
| 472 |
+
show_examples_btn = gr.Button("Ver ejemplos", variant="secondary")
|
| 473 |
+
|
| 474 |
+
with gr.Column():
|
| 475 |
+
examples_output = gr.Markdown("")
|
| 476 |
+
|
| 477 |
+
show_examples_btn.click(
|
| 478 |
+
fn=get_style_examples,
|
| 479 |
+
inputs=[example_style],
|
| 480 |
+
outputs=[examples_output]
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
+
gr.Markdown("""---
|
| 484 |
+
|
| 485 |
+
## 📖 Guía Rápida de Prompts
|
| 486 |
+
|
| 487 |
+
### Estructura recomendada:
|