Spaces:
Sleeping
Sleeping
Gmagl commited on
Commit ·
4574d8e
1
Parent(s): 9e668f2
Deploy: Enhanced app with persistent gallery and prompt selector
Browse files- __pycache__/app_enhanced.cpython-314.pyc +0 -0
- app.py +238 -0
- app_enhanced.py +51 -5
- requirements.txt +3 -0
- verify_changes.py +53 -0
__pycache__/app_enhanced.cpython-314.pyc
ADDED
|
Binary file (14.2 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sofia Rivera Workspace - Enhanced Version
|
| 3 |
+
Workspace mejorado con galería y generador de imágenes
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import os
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
from huggingface_hub import InferenceClient
|
| 10 |
+
import random
|
| 11 |
+
import glob
|
| 12 |
+
|
| 13 |
+
# Ensure output directory exists
|
| 14 |
+
OUTPUT_DIR = "generated_images"
|
| 15 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 16 |
+
|
| 17 |
+
# Initialize Inference Client
|
| 18 |
+
client = InferenceClient()
|
| 19 |
+
|
| 20 |
+
# Sofia Rivera - Perfil Completo
|
| 21 |
+
PROFILE = {
|
| 22 |
+
"nombre": "Sofia Rivera",
|
| 23 |
+
"edad": 25,
|
| 24 |
+
"origen": "Miami, Florida",
|
| 25 |
+
"etnia": "Latina (Cubana-Americana)",
|
| 26 |
+
"profesion": "Influencer de Lifestyle & Fitness",
|
| 27 |
+
"nichos": ["Fitness", "Wellness", "Fashion", "Lifestyle", "Motivación"],
|
| 28 |
+
"idiomas": ["Español", "Inglés"],
|
| 29 |
+
"instagram_bio": "✨ Sofia Rivera | Miami 🌴\n💪 Fitness & Wellness Journey\n🎯 Lifestyle Content Creator\n👗 Fashion | Beauty | Motivation\n📩 DM for collabs\n🔥 Premium content below ⬇️"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# Prompts para generar imágenes
|
| 33 |
+
PROMPTS = [
|
| 34 |
+
{
|
| 35 |
+
"id": 1,
|
| 36 |
+
"tipo": "Lifestyle - Golden Hour Selfie",
|
| 37 |
+
"prompt": "professional iphone selfie photo of sofia rivera, beautiful 25 year old latina cuban-american woman, long dark wavy hair, warm genuine smile, hazel eyes, natural makeup, wearing white crop tank top, black yoga pants, taken in luxury miami apartment with ocean view, golden hour lighting from floor-to-ceiling windows, bokeh background, shot on iPhone 15 Pro Max, instagram influencer aesthetic, fitness lifestyle content creator, authentic candid moment",
|
| 38 |
+
"negative_prompt": "blurry, low quality, distorted, deformed, ugly, bad anatomy",
|
| 39 |
+
"uso": "Instagram feed, posts casuales, get to know me"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"id": 2,
|
| 43 |
+
"tipo": "Fitness - Gym Mirror Selfie",
|
| 44 |
+
"prompt": "full body mirror selfie of sofia rivera, 25 year old latina fitness influencer, toned athletic body, wearing black sports bra and matching high-waist leggings, taken in modern home gym with mirrors, natural window lighting, confident pose showing fitness results, authentic instagram fitness post, shot on iphone, miami lifestyle content creator",
|
| 45 |
+
"negative_prompt": "blurry, low quality, distorted, bad proportions",
|
| 46 |
+
"uso": "Contenido fitness/wellness, Stories, motivación"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"id": 3,
|
| 50 |
+
"tipo": "Premium - Boudoir",
|
| 51 |
+
"prompt": "sofia rivera bedroom selfie, 25 year old latina influencer, wearing delicate white lace lingerie set, soft morning light through sheer curtains, sitting on edge of luxurious bed with silk sheets, natural messy hair, sultry confident expression, shot on iPhone 15 Pro, premium onlyfans content style, tasteful boudoir photography aesthetic, professional quality, authentic intimate moment",
|
| 52 |
+
"negative_prompt": "explicit, blurry, low quality, distorted",
|
| 53 |
+
"uso": "Contenido premium monetizable, Fansly/OF, PPV"
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"id": 4,
|
| 57 |
+
"tipo": "Fashion - Street Style",
|
| 58 |
+
"prompt": "sofia rivera street style photo, 25 year old latina fashion influencer, wearing trendy miami outfit, designer sunglasses, natural confident pose, urban miami background, golden hour street photography, instagram fashion aesthetic, professional quality",
|
| 59 |
+
"negative_prompt": "blurry, low quality, bad lighting",
|
| 60 |
+
"uso": "Fashion content, Instagram feed"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"id": 5,
|
| 64 |
+
"tipo": "Beach Lifestyle",
|
| 65 |
+
"prompt": "sofia rivera beach lifestyle photo, 25 year old latina influencer, miami beach background, sunset lighting, casual beach outfit, natural happy expression, tropical vibes, instagram lifestyle content",
|
| 66 |
+
"negative_prompt": "blurry, low quality, distorted",
|
| 67 |
+
"uso": "Lifestyle content, Stories, feed"
|
| 68 |
+
}
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# Modelos disponibles para generación
|
| 73 |
+
MODELS = [
|
| 74 |
+
"black-forest-labs/FLUX.1-dev",
|
| 75 |
+
"black-forest-labs/FLUX.1-schnell",
|
| 76 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 77 |
+
"runwayml/stable-diffusion-v1-5"
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
# Función para generar imagen
|
| 81 |
+
def generate_image(prompt, negative_prompt="", model="black-forest-labs/FLUX.1-dev", seed=None):
|
| 82 |
+
try:
|
| 83 |
+
if seed is None:
|
| 84 |
+
seed = random.randint(0, 2147483647)
|
| 85 |
+
|
| 86 |
+
image = client.text_to_image(
|
| 87 |
+
prompt=prompt,
|
| 88 |
+
negative_prompt=negative_prompt,
|
| 89 |
+
model=model,
|
| 90 |
+
guidance_scale=7.5,
|
| 91 |
+
num_inference_steps=50
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Save image locally
|
| 95 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 96 |
+
filename = f"sofia_{timestamp}_{seed}.png"
|
| 97 |
+
filepath = os.path.join(OUTPUT_DIR, filename)
|
| 98 |
+
image.save(filepath)
|
| 99 |
+
|
| 100 |
+
status = f"✅ Imagen generada y guardada: {filename}\nModelo: {model}\nSeed: {seed}"
|
| 101 |
+
return image, status
|
| 102 |
+
|
| 103 |
+
except Exception as e:
|
| 104 |
+
error_msg = f"❌ Error al generar imagen: {str(e)}"
|
| 105 |
+
return None, error_msg
|
| 106 |
+
|
| 107 |
+
# Función para cargar imágenes de la galería
|
| 108 |
+
def get_gallery_images():
|
| 109 |
+
images = []
|
| 110 |
+
# Get all png files from the output directory, sorted by modification time (newest first)
|
| 111 |
+
files = glob.glob(os.path.join(OUTPUT_DIR, "*.png"))
|
| 112 |
+
files.sort(key=os.path.getmtime, reverse=True)
|
| 113 |
+
return files
|
| 114 |
+
|
| 115 |
+
# Función para actualizar inputs basado en la selección del prompt
|
| 116 |
+
def update_prompt_inputs(prompt_name):
|
| 117 |
+
# Buscar el prompt seleccionado
|
| 118 |
+
selected = next((p for p in PROMPTS if p["tipo"] == prompt_name), None)
|
| 119 |
+
if selected:
|
| 120 |
+
return selected["prompt"], selected["negative_prompt"]
|
| 121 |
+
return "", ""
|
| 122 |
+
|
| 123 |
+
# Función de perfil
|
| 124 |
+
def show_profile():
|
| 125 |
+
profile_text = f"""# 👤 Perfil de Sofia Rivera
|
| 126 |
+
|
| 127 |
+
**Nombre:** {PROFILE['nombre']}
|
| 128 |
+
**Edad:** {PROFILE['edad']} años
|
| 129 |
+
**Origen:** {PROFILE['origen']}
|
| 130 |
+
**Etnia:** {PROFILE['etnia']}
|
| 131 |
+
**Profesión:** {PROFILE['profesion']}
|
| 132 |
+
|
| 133 |
+
**Nichos:** {', '.join(PROFILE['nichos'])}
|
| 134 |
+
**Idiomas:** {', '.join(PROFILE['idiomas'])}
|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
## 📱 Bio de Instagram:
|
| 139 |
+
```
|
| 140 |
+
{PROFILE['instagram_bio']}
|
| 141 |
+
```
|
| 142 |
+
"""
|
| 143 |
+
return profile_text
|
| 144 |
+
|
| 145 |
+
# Función para mostrar prompts
|
| 146 |
+
def show_prompts():
|
| 147 |
+
prompts_text = "# 🎨 Prompts para Generación de Contenido\n\n"
|
| 148 |
+
for p in PROMPTS:
|
| 149 |
+
prompts_text += f"""## {p['tipo']}\n**ID:** {p['id']}\n**Uso:** {p['uso']}\n\n**Prompt:**\n```\n{p['prompt']}\n```\n\n**Negative Prompt:**\n```\n{p['negative_prompt']}\n```\n\n---\n\n"""
|
| 150 |
+
return prompts_text
|
| 151 |
+
|
| 152 |
+
# Función para mostrar información de monetización
|
| 153 |
+
def show_monetization():
|
| 154 |
+
return """# 💰 Estrategia de Monetización\n\n## Plataformas de Contenido Premium:\n- **OnlyFans**: Contenido exclusivo de fitness y lifestyle\n- **Fansly**: Contenido premium variado\n- **Patreon**: Acceso a rutinas y planes personalizados\n\n## Tipos de Contenido:\n1. **Free Feed (Instagram/TikTok)**: Contenido motivacional, fitness tips, lifestyle\n2. **Premium Content**: Fotos profesionales, behind-the-scenes, contenido más personal\n3. **PPV (Pay-Per-View)**: Contenido exclusivo de alta calidad\n\n## Precios Sugeridos:\n- Suscripción mensual: $9.99 - $19.99\n- PPV individual: $5 - $25\n- Custom content: $50+\n"""
|
| 155 |
+
|
| 156 |
+
# Función para mostrar herramientas
|
| 157 |
+
def show_tools():
|
| 158 |
+
return """# 🛠️ Herramientas y Apps HuggingFace\n\n## Generadores de Imágenes:\n- **FLUX.1-dev**: Modelo principal de alta calidad\n- **FLUX.1-schnell**: Generación rápida\n- **Stable Diffusion XL**: Alternativa de alta resolución\n\n## Otras Herramientas Recomendadas:\n- **Upscaling**: Mejorar calidad de imágenes\n- **Background Removal**: Remover fondos\n- **Face Enhancement**: Mejorar detalles faciales\n"""
|
| 159 |
+
|
| 160 |
+
# Función para mostrar estadísticas
|
| 161 |
+
def show_stats():
|
| 162 |
+
return f"""# 📊 Estadísticas del Workspace\n\n**Fecha de creación:** {datetime.now().strftime('%Y-%m-%d')}\n**Prompts disponibles:** {len(PROMPTS)}\n**Modelos de IA:** {len(MODELS)}\n\n## Actividad Reciente:\n- Workspace inicializado correctamente\n- Sistema de generación de imágenes activo\n- Todos los prompts configurados\n"""
|
| 163 |
+
|
| 164 |
+
# Crear la interfaz de Gradio
|
| 165 |
+
with gr.Blocks(title="Sofia Rivera Workspace") as demo:
|
| 166 |
+
gr.Markdown("# ✨ Sofia Rivera - AI Influencer Workspace")
|
| 167 |
+
gr.Markdown("Workspace profesional para creación de contenido con IA")
|
| 168 |
+
|
| 169 |
+
with gr.Tabs():
|
| 170 |
+
# Tab 1: Galería de Contenido
|
| 171 |
+
with gr.Tab("🖼️ Galería"):
|
| 172 |
+
gr.Markdown("## Galería de Contenido Generado")
|
| 173 |
+
gr.Markdown("Todas las imágenes se guardan automáticamente en la carpeta `generated_images/`")
|
| 174 |
+
refresh_btn = gr.Button("🔄 Actualizar Galería")
|
| 175 |
+
gallery_output = gr.Gallery(label="Imágenes Guardadas", value=get_gallery_images(), columns=4, height="auto")
|
| 176 |
+
|
| 177 |
+
refresh_btn.click(
|
| 178 |
+
fn=get_gallery_images,
|
| 179 |
+
inputs=None,
|
| 180 |
+
outputs=gallery_output
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
# Tab 2: Generador de Imágenes
|
| 184 |
+
with gr.Tab("🎨 Generador"):
|
| 185 |
+
gr.Markdown("## Generador de Imágenes de Sofia Rivera")
|
| 186 |
+
|
| 187 |
+
with gr.Row():
|
| 188 |
+
with gr.Column():
|
| 189 |
+
# Crear lista de nombres de prompts para el dropdown
|
| 190 |
+
prompt_names = [p["tipo"] for p in PROMPTS]
|
| 191 |
+
prompt_selector = gr.Dropdown(choices=prompt_names, label="📋 Cargar Prompt Predefinido", value=None)
|
| 192 |
+
|
| 193 |
+
prompt_input = gr.Textbox(label="Prompt", lines=5, placeholder="Escribe tu prompt aquí o selecciona uno arriba...")
|
| 194 |
+
negative_prompt_input = gr.Textbox(label="Negative Prompt", lines=2, value="blurry, low quality, distorted")
|
| 195 |
+
|
| 196 |
+
# Evento al seleccionar un prompt
|
| 197 |
+
prompt_selector.change(
|
| 198 |
+
fn=update_prompt_inputs,
|
| 199 |
+
inputs=[prompt_selector],
|
| 200 |
+
outputs=[prompt_input, negative_prompt_input]
|
| 201 |
+
)
|
| 202 |
+
model_dropdown = gr.Dropdown(choices=MODELS, value=MODELS[0], label="Modelo")
|
| 203 |
+
seed_input = gr.Number(label="Seed (opcional)", value=None)
|
| 204 |
+
generate_btn = gr.Button("🚀 Generar Imagen", variant="primary")
|
| 205 |
+
|
| 206 |
+
with gr.Column():
|
| 207 |
+
image_output = gr.Image(label="Imagen Generada")
|
| 208 |
+
status_output = gr.Textbox(label="Estado", lines=3)
|
| 209 |
+
|
| 210 |
+
generate_btn.click(
|
| 211 |
+
fn=generate_image,
|
| 212 |
+
inputs=[prompt_input, negative_prompt_input, model_dropdown, seed_input],
|
| 213 |
+
outputs=[image_output, status_output]
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
# Tab 3: Perfil
|
| 217 |
+
with gr.Tab("👤 Perfil"):
|
| 218 |
+
profile_display = gr.Markdown(show_profile())
|
| 219 |
+
|
| 220 |
+
# Tab 4: Prompts
|
| 221 |
+
with gr.Tab("📝 Prompts"):
|
| 222 |
+
prompts_display = gr.Markdown(show_prompts())
|
| 223 |
+
|
| 224 |
+
# Tab 5: Monetización
|
| 225 |
+
with gr.Tab("💰 Monetización"):
|
| 226 |
+
monetization_display = gr.Markdown(show_monetization())
|
| 227 |
+
|
| 228 |
+
# Tab 6: Herramientas
|
| 229 |
+
with gr.Tab("🛠️ Herramientas"):
|
| 230 |
+
tools_display = gr.Markdown(show_tools())
|
| 231 |
+
|
| 232 |
+
# Tab 7: Estadísticas
|
| 233 |
+
with gr.Tab("📊 Estadísticas"):
|
| 234 |
+
stats_display = gr.Markdown(show_stats())
|
| 235 |
+
|
| 236 |
+
# Lanzar la aplicación
|
| 237 |
+
if __name__ == "__main__":
|
| 238 |
+
demo.launch()
|
app_enhanced.py
CHANGED
|
@@ -8,6 +8,11 @@ import os
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Initialize Inference Client
|
| 13 |
client = InferenceClient()
|
|
@@ -61,6 +66,7 @@ PROMPTS = [
|
|
| 61 |
"negative_prompt": "blurry, low quality, distorted",
|
| 62 |
"uso": "Lifestyle content, Stories, feed"
|
| 63 |
}
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
# Modelos disponibles para generación
|
|
@@ -85,13 +91,35 @@ def generate_image(prompt, negative_prompt="", model="black-forest-labs/FLUX.1-d
|
|
| 85 |
num_inference_steps=50
|
| 86 |
)
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return image, status
|
| 90 |
|
| 91 |
except Exception as e:
|
| 92 |
error_msg = f"❌ Error al generar imagen: {str(e)}"
|
| 93 |
return None, error_msg
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Función de perfil
|
| 96 |
def show_profile():
|
| 97 |
profile_text = f"""# 👤 Perfil de Sofia Rivera
|
|
@@ -112,7 +140,7 @@ def show_profile():
|
|
| 112 |
{PROFILE['instagram_bio']}
|
| 113 |
```
|
| 114 |
"""
|
| 115 |
-
return profile_text
|
| 116 |
|
| 117 |
# Función para mostrar prompts
|
| 118 |
def show_prompts():
|
|
@@ -142,8 +170,15 @@ with gr.Blocks(title="Sofia Rivera Workspace") as demo:
|
|
| 142 |
# Tab 1: Galería de Contenido
|
| 143 |
with gr.Tab("🖼️ Galería"):
|
| 144 |
gr.Markdown("## Galería de Contenido Generado")
|
| 145 |
-
gr.Markdown("
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
# Tab 2: Generador de Imágenes
|
| 149 |
with gr.Tab("🎨 Generador"):
|
|
@@ -151,8 +186,19 @@ with gr.Blocks(title="Sofia Rivera Workspace") as demo:
|
|
| 151 |
|
| 152 |
with gr.Row():
|
| 153 |
with gr.Column():
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", lines=2, value="blurry, low quality, distorted")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
model_dropdown = gr.Dropdown(choices=MODELS, value=MODELS[0], label="Modelo")
|
| 157 |
seed_input = gr.Number(label="Seed (opcional)", value=None)
|
| 158 |
generate_btn = gr.Button("🚀 Generar Imagen", variant="primary")
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
import random
|
| 11 |
+
import glob
|
| 12 |
+
|
| 13 |
+
# Ensure output directory exists
|
| 14 |
+
OUTPUT_DIR = "generated_images"
|
| 15 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 16 |
|
| 17 |
# Initialize Inference Client
|
| 18 |
client = InferenceClient()
|
|
|
|
| 66 |
"negative_prompt": "blurry, low quality, distorted",
|
| 67 |
"uso": "Lifestyle content, Stories, feed"
|
| 68 |
}
|
| 69 |
+
]
|
| 70 |
|
| 71 |
|
| 72 |
# Modelos disponibles para generación
|
|
|
|
| 91 |
num_inference_steps=50
|
| 92 |
)
|
| 93 |
|
| 94 |
+
# Save image locally
|
| 95 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 96 |
+
filename = f"sofia_{timestamp}_{seed}.png"
|
| 97 |
+
filepath = os.path.join(OUTPUT_DIR, filename)
|
| 98 |
+
image.save(filepath)
|
| 99 |
+
|
| 100 |
+
status = f"✅ Imagen generada y guardada: {filename}\nModelo: {model}\nSeed: {seed}"
|
| 101 |
return image, status
|
| 102 |
|
| 103 |
except Exception as e:
|
| 104 |
error_msg = f"❌ Error al generar imagen: {str(e)}"
|
| 105 |
return None, error_msg
|
| 106 |
|
| 107 |
+
# Función para cargar imágenes de la galería
|
| 108 |
+
def get_gallery_images():
|
| 109 |
+
images = []
|
| 110 |
+
# Get all png files from the output directory, sorted by modification time (newest first)
|
| 111 |
+
files = glob.glob(os.path.join(OUTPUT_DIR, "*.png"))
|
| 112 |
+
files.sort(key=os.path.getmtime, reverse=True)
|
| 113 |
+
return files
|
| 114 |
+
|
| 115 |
+
# Función para actualizar inputs basado en la selección del prompt
|
| 116 |
+
def update_prompt_inputs(prompt_name):
|
| 117 |
+
# Buscar el prompt seleccionado
|
| 118 |
+
selected = next((p for p in PROMPTS if p["tipo"] == prompt_name), None)
|
| 119 |
+
if selected:
|
| 120 |
+
return selected["prompt"], selected["negative_prompt"]
|
| 121 |
+
return "", ""
|
| 122 |
+
|
| 123 |
# Función de perfil
|
| 124 |
def show_profile():
|
| 125 |
profile_text = f"""# 👤 Perfil de Sofia Rivera
|
|
|
|
| 140 |
{PROFILE['instagram_bio']}
|
| 141 |
```
|
| 142 |
"""
|
| 143 |
+
return profile_text
|
| 144 |
|
| 145 |
# Función para mostrar prompts
|
| 146 |
def show_prompts():
|
|
|
|
| 170 |
# Tab 1: Galería de Contenido
|
| 171 |
with gr.Tab("🖼️ Galería"):
|
| 172 |
gr.Markdown("## Galería de Contenido Generado")
|
| 173 |
+
gr.Markdown("Todas las imágenes se guardan automáticamente en la carpeta `generated_images/`")
|
| 174 |
+
refresh_btn = gr.Button("🔄 Actualizar Galería")
|
| 175 |
+
gallery_output = gr.Gallery(label="Imágenes Guardadas", value=get_gallery_images(), columns=4, height="auto")
|
| 176 |
+
|
| 177 |
+
refresh_btn.click(
|
| 178 |
+
fn=get_gallery_images,
|
| 179 |
+
inputs=None,
|
| 180 |
+
outputs=gallery_output
|
| 181 |
+
)
|
| 182 |
|
| 183 |
# Tab 2: Generador de Imágenes
|
| 184 |
with gr.Tab("🎨 Generador"):
|
|
|
|
| 186 |
|
| 187 |
with gr.Row():
|
| 188 |
with gr.Column():
|
| 189 |
+
# Crear lista de nombres de prompts para el dropdown
|
| 190 |
+
prompt_names = [p["tipo"] for p in PROMPTS]
|
| 191 |
+
prompt_selector = gr.Dropdown(choices=prompt_names, label="📋 Cargar Prompt Predefinido", value=None)
|
| 192 |
+
|
| 193 |
+
prompt_input = gr.Textbox(label="Prompt", lines=5, placeholder="Escribe tu prompt aquí o selecciona uno arriba...")
|
| 194 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", lines=2, value="blurry, low quality, distorted")
|
| 195 |
+
|
| 196 |
+
# Evento al seleccionar un prompt
|
| 197 |
+
prompt_selector.change(
|
| 198 |
+
fn=update_prompt_inputs,
|
| 199 |
+
inputs=[prompt_selector],
|
| 200 |
+
outputs=[prompt_input, negative_prompt_input]
|
| 201 |
+
)
|
| 202 |
model_dropdown = gr.Dropdown(choices=MODELS, value=MODELS[0], label="Modelo")
|
| 203 |
seed_input = gr.Number(label="Seed (opcional)", value=None)
|
| 204 |
generate_btn = gr.Button("🚀 Generar Imagen", variant="primary")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
huggingface_hub
|
| 3 |
+
pillow
|
verify_changes.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
# Add the project directory to sys.path
|
| 5 |
+
sys.path.append(r"c:\Users\gemag\Proyectos y repos\sofia-rivera-workspace")
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
from unittest.mock import MagicMock
|
| 9 |
+
|
| 10 |
+
# Mock gradio and huggingface_hub
|
| 11 |
+
sys.modules["gradio"] = MagicMock()
|
| 12 |
+
sys.modules["huggingface_hub"] = MagicMock()
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
import app_enhanced
|
| 16 |
+
print("✅ Successfully imported app_enhanced")
|
| 17 |
+
except ImportError as e:
|
| 18 |
+
print(f"❌ Failed to import app_enhanced: {e}")
|
| 19 |
+
sys.exit(1)
|
| 20 |
+
|
| 21 |
+
# Check 1: Directory Creation
|
| 22 |
+
if os.path.isdir("generated_images"):
|
| 23 |
+
print("✅ 'generated_images' directory exists")
|
| 24 |
+
else:
|
| 25 |
+
print("❌ 'generated_images' directory was not created")
|
| 26 |
+
|
| 27 |
+
# Check 2: Prompt Function
|
| 28 |
+
try:
|
| 29 |
+
prompt, neg = app_enhanced.update_prompt_inputs("Fitness - Gym Mirror Selfie")
|
| 30 |
+
if "full body mirror selfie" in prompt and "blurry" in neg:
|
| 31 |
+
print("✅ update_prompt_inputs working correctly")
|
| 32 |
+
else:
|
| 33 |
+
print(f"❌ update_prompt_inputs returned unexpected values: {prompt[:20]}...")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"❌ Error testing update_prompt_inputs: {e}")
|
| 36 |
+
|
| 37 |
+
# Check 3: Gallery Function
|
| 38 |
+
try:
|
| 39 |
+
# Create a dummy file to test listing
|
| 40 |
+
with open("generated_images/test_dummy.png", "w") as f:
|
| 41 |
+
f.write("dummy")
|
| 42 |
+
|
| 43 |
+
images = app_enhanced.get_gallery_images()
|
| 44 |
+
if any("test_dummy.png" in img for img in images):
|
| 45 |
+
print("✅ get_gallery_images found the dummy file")
|
| 46 |
+
else:
|
| 47 |
+
print("❌ get_gallery_images failed to find files")
|
| 48 |
+
print(f"Found: {images}")
|
| 49 |
+
|
| 50 |
+
# Cleanup
|
| 51 |
+
os.remove("generated_images/test_dummy.png")
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print(f"❌ Error testing get_gallery_images: {e}")
|