Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from typing import Dict, Any, List
|
|
| 7 |
import json
|
| 8 |
import datetime
|
| 9 |
|
|
|
|
| 10 |
ETHNICITIES = [
|
| 11 |
"Mediterranean", "Scandinavian", "Slavic", "Latin American",
|
| 12 |
"Middle Eastern", "East Asian", "South Asian", "African",
|
|
@@ -201,7 +202,7 @@ import datetime
|
|
| 201 |
"stay-up stockings with French lace band and bow details",
|
| 202 |
"glossy finish stockings with sandalwood foot and sheer legs"
|
| 203 |
]
|
| 204 |
-
|
| 205 |
HEEL_STYLES = [
|
| 206 |
"black patent leather stilettos with pointed toe and slim heel",
|
| 207 |
"nude pumps with platform and ankle strap for stability",
|
|
@@ -260,7 +261,6 @@ import datetime
|
|
| 260 |
CAMERAS = ["Canon EOS R5", "Sony α7R V", "Nikon Z9", "Hasselblad X2D", "Phase One IQ4"]
|
| 261 |
LENSES = ["85mm f/1.2", "50mm f/1.4", "24-70mm f/2.8", "100mm f/2.8 macro", "135mm f/1.8"]
|
| 262 |
|
| 263 |
-
|
| 264 |
class HyperRealisticPromptGenerator:
|
| 265 |
def __init__(self):
|
| 266 |
self.config = HyperRealisticConfig()
|
|
@@ -394,13 +394,11 @@ def generate_batch_with_blocks(count, prompt_type, nsfw):
|
|
| 394 |
prompts = generator.generate_batch_prompts(count, prompt_type, nsfw)
|
| 395 |
blocks_html = ""
|
| 396 |
for i, prompt in enumerate(prompts, 1):
|
| 397 |
-
# Escapar comillas dobles para que el string de JavaScript funcione correctamente
|
| 398 |
-
escaped_prompt = prompt.replace('"', '\\"')
|
| 399 |
blocks_html += f"""
|
| 400 |
<div class="prompt-block">
|
| 401 |
<h4>📋 Prompt #{i}:</h4>
|
| 402 |
-
<textarea
|
| 403 |
-
<button class="copy-btn" onclick="copyToClipboard(`{
|
| 404 |
</div>
|
| 405 |
"""
|
| 406 |
return prompts, blocks_html
|
|
@@ -411,21 +409,9 @@ def export_history():
|
|
| 411 |
return "No history to export"
|
| 412 |
|
| 413 |
filename = f"prompt_history_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
|
| 414 |
-
|
| 415 |
-
temp_path = f"/tmp/{filename}"
|
| 416 |
-
with open(temp_path, 'w', encoding='utf-8') as f:
|
| 417 |
json.dump(history, f, indent=2, ensure_ascii=False)
|
| 418 |
-
|
| 419 |
-
# Devolver el archivo para descarga. Gradio maneja esto automáticamente si se devuelve un archivo.
|
| 420 |
-
# Sin embargo, la función de Gradio debe estar diseñada para devolver un gr.File.
|
| 421 |
-
# Como la función original devuelve un string, la mantendré así y asumiré que el usuario
|
| 422 |
-
# manejará la descarga del archivo generado en el entorno de Gradio.
|
| 423 |
-
# Para el despliegue en Hugging Face, el archivo se crea en el directorio del Space.
|
| 424 |
-
|
| 425 |
-
# Para la prueba local, se puede devolver el path. Para Gradio en HF Spaces,
|
| 426 |
-
# es mejor que el usuario acceda al archivo directamente si es necesario.
|
| 427 |
-
# Para simplificar y seguir el código original, devolveré un mensaje de estado.
|
| 428 |
-
return f"History exported to {filename}. Check the Space's file system."
|
| 429 |
|
| 430 |
# Interfaz Gradio
|
| 431 |
with gr.Blocks(title="HyperRealistic Humanized Perfection Generator", theme=gr.themes.Soft(), css="""
|
|
@@ -505,24 +491,18 @@ with gr.Blocks(title="HyperRealistic Humanized Perfection Generator", theme=gr.t
|
|
| 505 |
)
|
| 506 |
role_prompt_block = gr.HTML(label="Prompt Block")
|
| 507 |
|
| 508 |
-
# Uso de .then() para actualizar el bloque HTML después de generar el prompt
|
| 509 |
-
def update_role_prompt_block(prompt):
|
| 510 |
-
# Escapar comillas dobles para el string de JavaScript
|
| 511 |
-
escaped_prompt = prompt.replace('"', '\\"')
|
| 512 |
-
return f"""
|
| 513 |
-
<div class="prompt-block">
|
| 514 |
-
<h4>📋 Prompt Ready to Copy:</h4>
|
| 515 |
-
<div class="generated-prompt">{prompt}</div>
|
| 516 |
-
<button class="copy-btn" onclick="copyToClipboard(`{escaped_prompt}`)">📋 Copy Prompt</button>
|
| 517 |
-
</div>
|
| 518 |
-
"""
|
| 519 |
-
|
| 520 |
generate_role_btn.click(
|
| 521 |
fn=generator.generate_role_prompt,
|
| 522 |
inputs=[role_ethnicity, role_selection, role_nsfw],
|
| 523 |
outputs=[role_output]
|
| 524 |
).then(
|
| 525 |
-
fn=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
inputs=[role_output],
|
| 527 |
outputs=[role_prompt_block]
|
| 528 |
)
|
|
@@ -562,24 +542,18 @@ with gr.Blocks(title="HyperRealistic Humanized Perfection Generator", theme=gr.t
|
|
| 562 |
)
|
| 563 |
moment_prompt_block = gr.HTML(label="Prompt Block")
|
| 564 |
|
| 565 |
-
# Uso de .then() para actualizar el bloque HTML después de generar el prompt
|
| 566 |
-
def update_moment_prompt_block(prompt):
|
| 567 |
-
# Escapar comillas dobles para el string de JavaScript
|
| 568 |
-
escaped_prompt = prompt.replace('"', '\\"')
|
| 569 |
-
return f"""
|
| 570 |
-
<div class="prompt-block">
|
| 571 |
-
<h4>📋 Prompt Ready to Copy:</h4>
|
| 572 |
-
<div class="generated-prompt">{prompt}</div>
|
| 573 |
-
<button class="copy-btn" onclick="copyToClipboard(`{escaped_prompt}`)">📋 Copy Prompt</button>
|
| 574 |
-
</div>
|
| 575 |
-
"""
|
| 576 |
-
|
| 577 |
generate_moment_btn.click(
|
| 578 |
fn=generator.generate_moment_prompt,
|
| 579 |
inputs=[moment_ethnicity, moment_selection, moment_nsfw],
|
| 580 |
outputs=[moment_output]
|
| 581 |
).then(
|
| 582 |
-
fn=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
inputs=[moment_output],
|
| 584 |
outputs=[moment_prompt_block]
|
| 585 |
)
|
|
@@ -632,8 +606,7 @@ with gr.Blocks(title="HyperRealistic Humanized Perfection Generator", theme=gr.t
|
|
| 632 |
"🗑️ Clear History",
|
| 633 |
variant="secondary"
|
| 634 |
)
|
| 635 |
-
|
| 636 |
-
with gr.Column():
|
| 637 |
export_btn = gr.Button(
|
| 638 |
"💾 Export History as JSON",
|
| 639 |
variant="primary"
|
|
@@ -645,18 +618,62 @@ with gr.Blocks(title="HyperRealistic Humanized Perfection Generator", theme=gr.t
|
|
| 645 |
|
| 646 |
clear_history_btn.click(
|
| 647 |
fn=generator.clear_history,
|
| 648 |
-
|
| 649 |
-
outputs=[export_status]
|
| 650 |
).then(
|
| 651 |
-
fn=
|
| 652 |
-
inputs=[],
|
| 653 |
outputs=[history_display]
|
|
|
|
|
|
|
|
|
|
| 654 |
)
|
| 655 |
|
| 656 |
export_btn.click(
|
| 657 |
fn=export_history,
|
| 658 |
-
inputs=[],
|
| 659 |
outputs=[export_status]
|
|
|
|
|
|
|
|
|
|
| 660 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 661 |
|
| 662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import json
|
| 8 |
import datetime
|
| 9 |
|
| 10 |
+
class HyperRealisticConfig:
|
| 11 |
ETHNICITIES = [
|
| 12 |
"Mediterranean", "Scandinavian", "Slavic", "Latin American",
|
| 13 |
"Middle Eastern", "East Asian", "South Asian", "African",
|
|
|
|
| 202 |
"stay-up stockings with French lace band and bow details",
|
| 203 |
"glossy finish stockings with sandalwood foot and sheer legs"
|
| 204 |
]
|
| 205 |
+
|
| 206 |
HEEL_STYLES = [
|
| 207 |
"black patent leather stilettos with pointed toe and slim heel",
|
| 208 |
"nude pumps with platform and ankle strap for stability",
|
|
|
|
| 261 |
CAMERAS = ["Canon EOS R5", "Sony α7R V", "Nikon Z9", "Hasselblad X2D", "Phase One IQ4"]
|
| 262 |
LENSES = ["85mm f/1.2", "50mm f/1.4", "24-70mm f/2.8", "100mm f/2.8 macro", "135mm f/1.8"]
|
| 263 |
|
|
|
|
| 264 |
class HyperRealisticPromptGenerator:
|
| 265 |
def __init__(self):
|
| 266 |
self.config = HyperRealisticConfig()
|
|
|
|
| 394 |
prompts = generator.generate_batch_prompts(count, prompt_type, nsfw)
|
| 395 |
blocks_html = ""
|
| 396 |
for i, prompt in enumerate(prompts, 1):
|
|
|
|
|
|
|
| 397 |
blocks_html += f"""
|
| 398 |
<div class="prompt-block">
|
| 399 |
<h4>📋 Prompt #{i}:</h4>
|
| 400 |
+
<textarea style="width: 100%; height: 150px; padding: 10px; border: 1px solid #ddd; border-radius: 5px; font-family: monospace; margin-bottom: 10px;" readonly>{prompt}</textarea>
|
| 401 |
+
<button class="copy-btn" onclick="copyToClipboard(`{prompt}`)">📋 Copy Prompt #{i}</button>
|
| 402 |
</div>
|
| 403 |
"""
|
| 404 |
return prompts, blocks_html
|
|
|
|
| 409 |
return "No history to export"
|
| 410 |
|
| 411 |
filename = f"prompt_history_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
|
| 412 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
|
|
|
|
|
| 413 |
json.dump(history, f, indent=2, ensure_ascii=False)
|
| 414 |
+
return f"History exported to {filename}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
# Interfaz Gradio
|
| 417 |
with gr.Blocks(title="HyperRealistic Humanized Perfection Generator", theme=gr.themes.Soft(), css="""
|
|
|
|
| 491 |
)
|
| 492 |
role_prompt_block = gr.HTML(label="Prompt Block")
|
| 493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
generate_role_btn.click(
|
| 495 |
fn=generator.generate_role_prompt,
|
| 496 |
inputs=[role_ethnicity, role_selection, role_nsfw],
|
| 497 |
outputs=[role_output]
|
| 498 |
).then(
|
| 499 |
+
fn=lambda prompt: f"""
|
| 500 |
+
<div class="prompt-block">
|
| 501 |
+
<h4>📋 Prompt Ready to Copy:</h4>
|
| 502 |
+
<div class="generated-prompt">{prompt}</div>
|
| 503 |
+
<button class="copy-btn" onclick="copyToClipboard(`{prompt}`)">📋 Copy Prompt</button>
|
| 504 |
+
</div>
|
| 505 |
+
""",
|
| 506 |
inputs=[role_output],
|
| 507 |
outputs=[role_prompt_block]
|
| 508 |
)
|
|
|
|
| 542 |
)
|
| 543 |
moment_prompt_block = gr.HTML(label="Prompt Block")
|
| 544 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
generate_moment_btn.click(
|
| 546 |
fn=generator.generate_moment_prompt,
|
| 547 |
inputs=[moment_ethnicity, moment_selection, moment_nsfw],
|
| 548 |
outputs=[moment_output]
|
| 549 |
).then(
|
| 550 |
+
fn=lambda prompt: f"""
|
| 551 |
+
<div class="prompt-block">
|
| 552 |
+
<h4>📋 Prompt Ready to Copy:</h4>
|
| 553 |
+
<div class="generated-prompt">{prompt}</div>
|
| 554 |
+
<button class="copy-btn" onclick="copyToClipboard(`{prompt}`)">📋 Copy Prompt</button>
|
| 555 |
+
</div>
|
| 556 |
+
""",
|
| 557 |
inputs=[moment_output],
|
| 558 |
outputs=[moment_prompt_block]
|
| 559 |
)
|
|
|
|
| 606 |
"🗑️ Clear History",
|
| 607 |
variant="secondary"
|
| 608 |
)
|
| 609 |
+
with gr.Column():
|
|
|
|
| 610 |
export_btn = gr.Button(
|
| 611 |
"💾 Export History as JSON",
|
| 612 |
variant="primary"
|
|
|
|
| 618 |
|
| 619 |
clear_history_btn.click(
|
| 620 |
fn=generator.clear_history,
|
| 621 |
+
outputs=[]
|
|
|
|
| 622 |
).then(
|
| 623 |
+
fn=lambda: [],
|
|
|
|
| 624 |
outputs=[history_display]
|
| 625 |
+
).then(
|
| 626 |
+
fn=lambda: "History cleared",
|
| 627 |
+
outputs=[export_status]
|
| 628 |
)
|
| 629 |
|
| 630 |
export_btn.click(
|
| 631 |
fn=export_history,
|
|
|
|
| 632 |
outputs=[export_status]
|
| 633 |
+
).then(
|
| 634 |
+
fn=generator.get_history,
|
| 635 |
+
outputs=[history_display]
|
| 636 |
)
|
| 637 |
+
|
| 638 |
+
with gr.Tab("ℹ️ Instructions"):
|
| 639 |
+
gr.Markdown("""
|
| 640 |
+
## 🎯 How to Use This Generator
|
| 641 |
+
|
| 642 |
+
### 🖼️ Hyper-Realistic Features:
|
| 643 |
+
- **9:16 Vertical Format** - Perfect for mobile viewing
|
| 644 |
+
- **Low-Angle Shots** - Strategic angles for intimate composition
|
| 645 |
+
- **Ultra HD 16K** - Extreme detail and realism
|
| 646 |
+
- **Humanized Perfection** - Natural skin textures and imperfections
|
| 647 |
+
|
| 648 |
+
### 🎨 Prompt Types:
|
| 649 |
+
- **👔 Professional Roles**: 10 different professional scenarios
|
| 650 |
+
- **🏠 Everyday Moments**: 10 natural, intimate situations
|
| 651 |
+
- **🔄 Batch Generation**: Generate multiple prompts at once
|
| 652 |
+
|
| 653 |
+
### ⚙️ Settings:
|
| 654 |
+
- **Ethnicity**: Choose from 11 diverse ethnic backgrounds
|
| 655 |
+
- **NSFW Mode**: Toggle artistic sensuality levels
|
| 656 |
+
- **Auto-Copy**: One-click copying from formatted blocks
|
| 657 |
+
|
| 658 |
+
### 📋 Copying Prompts:
|
| 659 |
+
1. Click the **"Generate"** button for your desired prompt type
|
| 660 |
+
2. Use the **"Copy Prompt"** button in the formatted block
|
| 661 |
+
3. Paste directly into your AI image generator
|
| 662 |
+
|
| 663 |
+
### 🎯 Perfect For:
|
| 664 |
+
- Midjourney, Stable Diffusion, DALL-E
|
| 665 |
+
- Professional photography simulations
|
| 666 |
+
- Artistic and creative projects
|
| 667 |
+
- Hyper-realistic character creation
|
| 668 |
|
| 669 |
+
### 📸 Technical Specifications:
|
| 670 |
+
- **Format**: 9:16 Vertical
|
| 671 |
+
- **Resolution**: 16K Ultra HD
|
| 672 |
+
- **Angles**: Low-angle, intimate perspectives
|
| 673 |
+
- **Lighting**: Professional studio and natural
|
| 674 |
+
- **Details**: Skin pores, fabric textures, subsurface scattering
|
| 675 |
+
""")
|
| 676 |
+
|
| 677 |
+
# Launch the application
|
| 678 |
+
if __name__ == "__main__":
|
| 679 |
+
demo.launch()
|