Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -248,4 +248,287 @@ def get_style_examples(style: str) -> str:
|
|
| 248 |
|
| 249 |
GUIDE_TEXT = """## 📖 Guía Rápida de Prompts
|
| 250 |
|
| 251 |
-
### Estructura recomendada:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
GUIDE_TEXT = """## 📖 Guía Rápida de Prompts
|
| 250 |
|
| 251 |
+
### Estructura recomendada: [Calidad] + [Sujeto principal] + [Estilo] + [Detalles] + [Iluminación] + [Composición]
|
| 252 |
+
|
| 253 |
+
### Ejemplo práctico: masterpiece, best quality, a beautiful elven princess with silver hair,
|
| 254 |
+
fantasy art style, intricate jewelry, magical forest background,
|
| 255 |
+
ethereal lighting, portrait shot, highly detailed
|
| 256 |
+
|
| 257 |
+
---
|
| 258 |
+
|
| 259 |
+
### ⚡ Diferencias entre modelos:
|
| 260 |
+
|
| 261 |
+
| Modelo | Tokens | Pesos | Estilo de prompt |
|
| 262 |
+
|--------|--------|-------|------------------|
|
| 263 |
+
| SD 1.5 | 77 | ✅ (word:1.2) | Tags separados por comas |
|
| 264 |
+
| SDXL | 77 | ✅ (word:1.2) | Similar a SD, más natural |
|
| 265 |
+
| FLUX | 256 | ❌ | Descripciones naturales |
|
| 266 |
+
| Midjourney | 500 | ✅ ::peso | Natural + parámetros |
|
| 267 |
+
| DALL-E 3 | 4000 | ❌ | Oraciones descriptivas |
|
| 268 |
+
|
| 269 |
+
---
|
| 270 |
+
|
| 271 |
+
### 🎯 Palabras clave por categoría:
|
| 272 |
+
|
| 273 |
+
**Calidad:** masterpiece, best quality, highly detailed, 8k, uhd, professional
|
| 274 |
+
|
| 275 |
+
**Iluminación:** dramatic lighting, soft light, golden hour, studio lighting, rim light
|
| 276 |
+
|
| 277 |
+
**Composición:** portrait, full body, close-up, wide shot, bird's eye view
|
| 278 |
+
|
| 279 |
+
**Estilos:** oil painting, digital art, photograph, 3d render, watercolor, sketch
|
| 280 |
+
"""
|
| 281 |
+
|
| 282 |
+
TIPS_TEXT = """### 💡 Tips para cada componente:
|
| 283 |
+
|
| 284 |
+
- **Sujeto**: Sé específico. "young woman with curly red hair" > "woman"
|
| 285 |
+
- **Estilo**: Define la estética visual del resultado
|
| 286 |
+
- **Iluminación**: Afecta dramáticamente el mood de la imagen
|
| 287 |
+
- **Ambiente**: Establece el tono emocional
|
| 288 |
+
- **Encuadre**: Controla la composición de la imagen
|
| 289 |
+
"""
|
| 290 |
+
|
| 291 |
+
FOOTER_TEXT = """---
|
| 292 |
+
|
| 293 |
+
<div style="text-align: center;">
|
| 294 |
+
<strong>Prompt Enhancer Pro</strong> | Creado para la comunidad de generación de imágenes con IA<br>
|
| 295 |
+
Compatible con: Stable Diffusion, SDXL, FLUX, Midjourney y DALL-E 3
|
| 296 |
+
</div>
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
HEADER_HTML = """
|
| 300 |
+
<div style="text-align: center; margin-bottom: 1.5em;">
|
| 301 |
+
<h1 style="color: #2563eb; margin-bottom: 0.3em;">🎨 Prompt Enhancer Pro</h1>
|
| 302 |
+
<p style="color: #6b7280; font-size: 1.1em;">Mejora y optimiza tus prompts para generación de imágenes con IA</p>
|
| 303 |
+
</div>
|
| 304 |
+
"""
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
# ===== INTERFAZ GRADIO 6.0+ =====
|
| 308 |
+
|
| 309 |
+
def create_app():
|
| 310 |
+
"""Crea la aplicación Gradio"""
|
| 311 |
+
|
| 312 |
+
with gr.Blocks(title="Prompt Enhancer Pro") as app:
|
| 313 |
+
|
| 314 |
+
gr.HTML(HEADER_HTML)
|
| 315 |
+
|
| 316 |
+
with gr.Tabs():
|
| 317 |
+
|
| 318 |
+
# ===== TAB 1: MEJORAR PROMPT =====
|
| 319 |
+
with gr.TabItem("✨ Mejorar Prompt"):
|
| 320 |
+
gr.Markdown("### Transforma tu prompt simple en uno profesional")
|
| 321 |
+
|
| 322 |
+
with gr.Row():
|
| 323 |
+
with gr.Column(scale=1):
|
| 324 |
+
input_prompt = gr.Textbox(
|
| 325 |
+
label="Tu prompt original",
|
| 326 |
+
placeholder="Escribe tu prompt aquí... (puede ser en español o inglés)",
|
| 327 |
+
lines=3
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
with gr.Row():
|
| 331 |
+
model_select = gr.Dropdown(
|
| 332 |
+
choices=["Stable Diffusion 1.5", "Stable Diffusion XL",
|
| 333 |
+
"FLUX.1", "Midjourney", "DALL-E 3"],
|
| 334 |
+
value="Stable Diffusion XL",
|
| 335 |
+
label="Modelo destino"
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
style_select = gr.Dropdown(
|
| 339 |
+
choices=["Ninguno", "Fotorealista", "Anime", "Arte Digital",
|
| 340 |
+
"Pintura", "3D", "Cinematico", "Minimalista", "Fantasia"],
|
| 341 |
+
value="Ninguno",
|
| 342 |
+
label="Estilo artístico"
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
with gr.Row():
|
| 346 |
+
add_quality = gr.Checkbox(label="Añadir tokens de calidad", value=True)
|
| 347 |
+
add_negative = gr.Checkbox(label="Generar negative prompt", value=True)
|
| 348 |
+
|
| 349 |
+
enhance_btn = gr.Button("🚀 Mejorar Prompt", variant="primary")
|
| 350 |
+
|
| 351 |
+
with gr.Column(scale=1):
|
| 352 |
+
output_prompt = gr.Textbox(
|
| 353 |
+
label="✅ Prompt mejorado",
|
| 354 |
+
lines=4,
|
| 355 |
+
interactive=False
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
output_negative = gr.Textbox(
|
| 359 |
+
label="❌ Negative prompt",
|
| 360 |
+
lines=2,
|
| 361 |
+
interactive=False
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
model_info = gr.Markdown("")
|
| 365 |
+
|
| 366 |
+
with gr.Row():
|
| 367 |
+
with gr.Column():
|
| 368 |
+
analysis_output = gr.Markdown(label="Análisis")
|
| 369 |
+
with gr.Column():
|
| 370 |
+
variations_output = gr.Markdown(label="Variaciones sugeridas")
|
| 371 |
+
|
| 372 |
+
enhance_btn.click(
|
| 373 |
+
fn=enhance_prompt,
|
| 374 |
+
inputs=[input_prompt, model_select, style_select, add_quality, add_negative],
|
| 375 |
+
outputs=[output_prompt, output_negative, analysis_output, variations_output, model_info]
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
# ===== TAB 2: CORRECTOR =====
|
| 379 |
+
with gr.TabItem("🔧 Corrector de Errores"):
|
| 380 |
+
gr.Markdown("### Detecta y corrige errores comunes en tus prompts")
|
| 381 |
+
|
| 382 |
+
with gr.Row():
|
| 383 |
+
with gr.Column():
|
| 384 |
+
fix_input = gr.Textbox(
|
| 385 |
+
label="Prompt con posibles errores",
|
| 386 |
+
placeholder="Pega aquí un prompt que quieras revisar...",
|
| 387 |
+
lines=4
|
| 388 |
+
)
|
| 389 |
+
fix_btn = gr.Button("🔍 Analizar y Corregir", variant="primary")
|
| 390 |
+
|
| 391 |
+
with gr.Column():
|
| 392 |
+
fix_output = gr.Textbox(
|
| 393 |
+
label="Prompt corregido",
|
| 394 |
+
lines=4,
|
| 395 |
+
interactive=False
|
| 396 |
+
)
|
| 397 |
+
fixes_log = gr.Markdown("")
|
| 398 |
+
|
| 399 |
+
fix_btn.click(
|
| 400 |
+
fn=fix_prompt,
|
| 401 |
+
inputs=[fix_input],
|
| 402 |
+
outputs=[fix_output, fixes_log]
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
+
# ===== TAB 3: CONSTRUCTOR =====
|
| 406 |
+
with gr.TabItem("🏗️ Constructor de Prompts"):
|
| 407 |
+
gr.Markdown("### Construye un prompt paso a paso")
|
| 408 |
+
|
| 409 |
+
with gr.Row():
|
| 410 |
+
with gr.Column():
|
| 411 |
+
build_subject = gr.Textbox(
|
| 412 |
+
label="Sujeto principal *",
|
| 413 |
+
placeholder="Ej: a young woman with red hair, a futuristic city..."
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
with gr.Row():
|
| 417 |
+
build_style = gr.Dropdown(
|
| 418 |
+
choices=["Ninguno", "Clasico", "Impresionista", "Surrealista",
|
| 419 |
+
"Pop Art", "Art Nouveau", "Concept Art", "Anime",
|
| 420 |
+
"Fantasia", "Sci-fi", "Horror"],
|
| 421 |
+
value="Ninguno",
|
| 422 |
+
label="Estilo artístico"
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
build_lighting = gr.Dropdown(
|
| 426 |
+
choices=["Ninguno", "Dramatica", "Suave", "Natural",
|
| 427 |
+
"Estudio", "Neon", "Cinematica"],
|
| 428 |
+
value="Ninguno",
|
| 429 |
+
label="Iluminación"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
with gr.Row():
|
| 433 |
+
build_mood = gr.Dropdown(
|
| 434 |
+
choices=["Ninguno", "Oscuro", "Alegre", "Melancolico",
|
| 435 |
+
"Epico", "Sereno", "Intenso"],
|
| 436 |
+
value="Ninguno",
|
| 437 |
+
label="Ambiente/Mood"
|
| 438 |
+
)
|
| 439 |
+
|
| 440 |
+
build_camera = gr.Dropdown(
|
| 441 |
+
choices=["Ninguno", "Cercano", "Lejano", "Retrato",
|
| 442 |
+
"Aereo", "Bajo", "Alto"],
|
| 443 |
+
value="Ninguno",
|
| 444 |
+
label="Ángulo/Encuadre"
|
| 445 |
+
)
|
| 446 |
+
|
| 447 |
+
build_quality = gr.CheckboxGroup(
|
| 448 |
+
choices=["Alta definición (8K)", "Muy detallado", "Masterpiece",
|
| 449 |
+
"Fotografía profesional", "Arte de alta calidad"],
|
| 450 |
+
label="Calidad"
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
build_extra = gr.Textbox(
|
| 454 |
+
label="Detalles adicionales",
|
| 455 |
+
placeholder="Añade cualquier detalle extra..."
|
| 456 |
+
)
|
| 457 |
+
|
| 458 |
+
build_btn = gr.Button("🔨 Construir Prompt", variant="primary")
|
| 459 |
+
|
| 460 |
+
with gr.Column():
|
| 461 |
+
build_output = gr.Textbox(
|
| 462 |
+
label="Prompt construido",
|
| 463 |
+
lines=6,
|
| 464 |
+
interactive=False
|
| 465 |
+
)
|
| 466 |
+
|
| 467 |
+
gr.Markdown(TIPS_TEXT)
|
| 468 |
+
|
| 469 |
+
build_btn.click(
|
| 470 |
+
fn=build_prompt,
|
| 471 |
+
inputs=[build_subject, build_style, build_lighting, build_mood,
|
| 472 |
+
build_camera, build_quality, build_extra],
|
| 473 |
+
outputs=[build_output]
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
# ===== TAB 4: ANALIZADOR =====
|
| 477 |
+
with gr.TabItem("📊 Analizador"):
|
| 478 |
+
gr.Markdown("### Analiza la calidad y estructura de tu prompt")
|
| 479 |
+
|
| 480 |
+
with gr.Row():
|
| 481 |
+
with gr.Column():
|
| 482 |
+
analyze_input = gr.Textbox(
|
| 483 |
+
label="Prompt a analizar",
|
| 484 |
+
placeholder="Pega cualquier prompt para obtener un análisis detallado...",
|
| 485 |
+
lines=4
|
| 486 |
+
)
|
| 487 |
+
analyze_btn = gr.Button("📊 Analizar", variant="primary")
|
| 488 |
+
|
| 489 |
+
with gr.Column():
|
| 490 |
+
analyze_output = gr.Markdown("")
|
| 491 |
+
|
| 492 |
+
analyze_btn.click(
|
| 493 |
+
fn=analyze_only,
|
| 494 |
+
inputs=[analyze_input],
|
| 495 |
+
outputs=[analyze_output]
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
# ===== TAB 5: EJEMPLOS Y GUÍA =====
|
| 499 |
+
with gr.TabItem("📚 Guía y Ejemplos"):
|
| 500 |
+
gr.Markdown("### Aprende a crear mejores prompts")
|
| 501 |
+
|
| 502 |
+
with gr.Row():
|
| 503 |
+
with gr.Column():
|
| 504 |
+
example_style = gr.Dropdown(
|
| 505 |
+
choices=["Fotorealista", "Anime", "Arte Digital",
|
| 506 |
+
"Pintura", "3D", "Cinematico"],
|
| 507 |
+
value="Fotorealista",
|
| 508 |
+
label="Selecciona un estilo"
|
| 509 |
+
)
|
| 510 |
+
show_examples_btn = gr.Button("Ver ejemplos", variant="secondary")
|
| 511 |
+
|
| 512 |
+
with gr.Column():
|
| 513 |
+
examples_output = gr.Markdown("")
|
| 514 |
+
|
| 515 |
+
show_examples_btn.click(
|
| 516 |
+
fn=get_style_examples,
|
| 517 |
+
inputs=[example_style],
|
| 518 |
+
outputs=[examples_output]
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
gr.Markdown("---")
|
| 522 |
+
gr.Markdown(GUIDE_TEXT)
|
| 523 |
+
|
| 524 |
+
# Footer
|
| 525 |
+
gr.Markdown(FOOTER_TEXT)
|
| 526 |
+
|
| 527 |
+
return app
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
# Crear y lanzar la aplicación
|
| 531 |
+
app = create_app()
|
| 532 |
+
|
| 533 |
+
if __name__ == "__main__":
|
| 534 |
+
app.launch()
|