Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,141 +1,80 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import random
|
| 4 |
-
from datetime import datetime
|
| 5 |
-
from huggingface_hub import InferenceClient
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Configuración de entorno y directorios
|
| 9 |
-
OUTPUT_DIR = "generated_images"
|
| 10 |
-
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 11 |
-
|
| 12 |
-
# Inicialización del cliente de inferencia
|
| 13 |
-
# En Hugging Face Spaces, el token se maneja automáticamente si el Space tiene permisos
|
| 14 |
-
client = InferenceClient()
|
| 15 |
-
|
| 16 |
-
# --- PERFIL DE SOFIA RIVERA ---
|
| 17 |
-
SOFIA_CORE = (
|
| 18 |
-
"sofia rivera, a beautiful 25-year-old latina cuban-american woman, "
|
| 19 |
-
"long dark wavy hair, mesmerizing hazel eyes, toned athletic fitness body, "
|
| 20 |
-
"natural radiant skin, miami influencer aesthetic"
|
| 21 |
-
)
|
| 22 |
-
|
| 23 |
-
# --- CATEGORÍAS DE CONTENIDO ---
|
| 24 |
-
CATEGORIES = {
|
| 25 |
-
"Fitness - Gym Mirror": {
|
| 26 |
-
"prompt": f"full body mirror selfie of {SOFIA_CORE}, wearing professional black sports bra and matching high-waist leggings, standing in a modern high-end miami gym, mirrors reflecting gym equipment, natural window lighting, confident pose, authentic fitness instagram post, shot on iPhone 15 Pro, high detail, 8k",
|
| 27 |
-
"negative": "blurry, low quality, distorted, bad proportions, cartoon, anime, 3d render",
|
| 28 |
-
"description": "### 🏋️ Pilar Fitness (40%)\nIdeal para Lunes, Miércoles y Viernes. Enfoque en motivación y resultados."
|
| 29 |
-
},
|
| 30 |
-
"Lifestyle - Miami Beach": {
|
| 31 |
-
"prompt": f"candid lifestyle photo of {SOFIA_CORE}, wearing a stylish tropical summer outfit, standing on miami beach with turquoise ocean background, sunset golden hour lighting, palm trees, warm breeze, happy genuine smile, high fashion photography, vibrant colors, shot on professional camera, cinematic lighting",
|
| 32 |
-
"negative": "blurry, low quality, distorted, bad anatomy, overexposed, crowded beach",
|
| 33 |
-
"description": "### 🌴 Pilar Lifestyle Miami (30%)\nIdeal para Martes y Jueves. Fotos en exteriores, playa y vibras tropicales."
|
| 34 |
-
},
|
| 35 |
-
"Lifestyle - Luxury Apartment": {
|
| 36 |
-
"prompt": f"close up portrait of {SOFIA_CORE} in a luxury miami apartment, floor-to-ceiling windows with city skyline view, wearing casual white silk loungewear, soft morning light, natural makeup, holding a coffee cup, relaxed and authentic vibe, 8k resolution, photorealistic",
|
| 37 |
-
"negative": "blurry, low quality, distorted, messy room, dark lighting",
|
| 38 |
-
"description": "### ☕ Pilar Personal/BTS (20%)\nIdeal para Sábados. Contenido 'Detrás de cámaras' y rutinas diarias."
|
| 39 |
-
},
|
| 40 |
-
"Premium - Elegant Boudoir": {
|
| 41 |
-
"prompt": f"tasteful boudoir photography of {SOFIA_CORE}, wearing elegant black lace lingerie, soft moody lighting in a luxury bedroom, silk sheets, artistic shadows, confident and sultry expression, professional photography aesthetic, high class and elegant",
|
| 42 |
-
"negative": "explicit, pornographic, blurry, low quality, distorted, cheap aesthetic",
|
| 43 |
-
"description": "### 💎 Pilar Premium (10%)\nIdeal para Domingos. Teasers exclusivos con elegancia y clase."
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
def generate_sofia_image(category_name, custom_tweak, model_id, steps, cfg_scale, seed):
|
| 48 |
-
try:
|
| 49 |
-
category = CATEGORIES[category_name]
|
| 50 |
-
final_prompt = category["prompt"]
|
| 51 |
-
if custom_tweak:
|
| 52 |
-
final_prompt += f", {custom_tweak}"
|
| 53 |
-
|
| 54 |
-
if seed == -1:
|
| 55 |
-
seed = random.randint(0, 2**32 - 1)
|
| 56 |
-
|
| 57 |
-
image = client.text_to_image(
|
| 58 |
-
prompt=final_prompt,
|
| 59 |
-
negative_prompt=category["negative"],
|
| 60 |
-
model=model_id,
|
| 61 |
-
num_inference_steps=int(steps),
|
| 62 |
-
guidance_scale=float(cfg_scale),
|
| 63 |
-
seed=int(seed)
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 67 |
-
filename = f"sofia_{timestamp}.png"
|
| 68 |
-
filepath = os.path.join(OUTPUT_DIR, filename)
|
| 69 |
-
image.save(filepath)
|
| 70 |
-
|
| 71 |
-
return image, f"✅ Imagen generada: {filename}\nSeed: {seed}"
|
| 72 |
-
except Exception as e:
|
| 73 |
-
return None, f"❌ Error: {str(e)}"
|
| 74 |
-
|
| 75 |
-
# --- INTERFAZ DE GRADIO ---
|
| 76 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 77 |
-
gr.Markdown(f"""
|
| 78 |
-
# 🌴 Sofia Rivera - AI Influencer Workspace
|
| 79 |
-
Bienvenido al panel de control de **Sofía Rivera**. Genera contenido consistente basado en la estrategia oficial.
|
| 80 |
-
""")
|
| 81 |
-
|
| 82 |
-
with gr.Tab("🎨 Generador"):
|
| 83 |
-
with gr.Row():
|
| 84 |
-
with gr.Column(scale=1):
|
| 85 |
-
category_dropdown = gr.Dropdown(
|
| 86 |
-
choices=list(CATEGORIES.keys()),
|
| 87 |
-
label="Pilar de Contenido",
|
| 88 |
-
value="Fitness - Gym Mirror"
|
| 89 |
-
)
|
| 90 |
-
category_desc = gr.Markdown(CATEGORIES["Fitness - Gym Mirror"]["description"])
|
| 91 |
-
|
| 92 |
-
custom_tweak = gr.Textbox(
|
| 93 |
-
label="Personalizar Escena",
|
| 94 |
-
placeholder="ej: holding a water bottle, wearing sunglasses, laughing..."
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
with gr.Accordion("Configuración Técnica", open=False):
|
| 98 |
-
model_id = gr.Dropdown(
|
| 99 |
-
choices=["black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"],
|
| 100 |
-
label="Modelo",
|
| 101 |
-
value="black-forest-labs/FLUX.1-dev"
|
| 102 |
-
)
|
| 103 |
-
steps = gr.Slider(minimum=1, maximum=50, step=1, value=28, label="Pasos")
|
| 104 |
-
cfg = gr.Slider(minimum=1, maximum=20, step=0.5, value=7.0, label="CFG Scale")
|
| 105 |
-
seed = gr.Number(label="Seed (-1 = Aleatorio)", value=-1)
|
| 106 |
-
|
| 107 |
-
generate_btn = gr.Button("🚀 Generar Contenido", variant="primary")
|
| 108 |
-
|
| 109 |
-
with gr.Column(scale=2):
|
| 110 |
-
output_image = gr.Image(label="Vista Previa de Sofía")
|
| 111 |
-
status_text = gr.Textbox(label="Log de Sistema", interactive=False)
|
| 112 |
-
|
| 113 |
-
with gr.Tab("📊 Estrategia & Perfil"):
|
| 114 |
-
gr.Markdown(f"""
|
| 115 |
-
### 👤 Identidad de Sofía Rivera
|
| 116 |
-
- **Nombre:** Sofía Rivera
|
| 117 |
-
- **Edad:** 25 años
|
| 118 |
-
- **Etnia:** Latina (Cubana-Americana)
|
| 119 |
-
- **Ubicación:** Miami, Florida
|
| 120 |
-
- **Rasgos:** Cabello oscuro ondulado, ojos avellana, cuerpo atlético.
|
| 121 |
-
|
| 122 |
-
### 📅 Calendario de Publicación
|
| 123 |
-
- **Lunes/Miércoles/Viernes:** Fitness & Gym
|
| 124 |
-
- **Martes/Jueves:** Lifestyle & Miami Vibes
|
| 125 |
-
- **Sábados:** Personal & Detrás de Cámaras
|
| 126 |
-
- **Domingos:** Premium Teasers
|
| 127 |
-
""")
|
| 128 |
-
|
| 129 |
-
def update_desc(cat):
|
| 130 |
-
return CATEGORIES[cat]["description"]
|
| 131 |
-
|
| 132 |
-
category_dropdown.change(update_desc, inputs=[category_dropdown], outputs=[category_desc])
|
| 133 |
-
|
| 134 |
-
generate_btn.click(
|
| 135 |
-
fn=generate_sofia_image,
|
| 136 |
-
inputs=[category_dropdown, custom_tweak, model_id, steps, cfg, seed],
|
| 137 |
-
outputs=[output_image, status_text]
|
| 138 |
-
)
|
| 139 |
-
|
| 140 |
-
if __name__ == "__main__":
|
| 141 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from huggingface_hub import InferenceClient
|
| 6 |
+
|
| 7 |
+
# Configuración
|
| 8 |
+
OUTPUT_DIR = "generated_images"
|
| 9 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 10 |
+
client = InferenceClient()
|
| 11 |
+
|
| 12 |
+
# Identidad de Sofía Rivera
|
| 13 |
+
SOFIA_CORE = (
|
| 14 |
+
"sofia rivera, a beautiful 25-year-old latina cuban-american woman, "
|
| 15 |
+
"long dark wavy hair, mesmerizing hazel eyes, toned athletic fitness body, "
|
| 16 |
+
"natural radiant skin, miami influencer aesthetic"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
CATEGORIES = {
|
| 20 |
+
"Fitness - Gym": {
|
| 21 |
+
"prompt": f"full body mirror selfie of {SOFIA_CORE}, wearing black sports bra and leggings, modern miami gym background, 8k, photorealistic",
|
| 22 |
+
"desc": "### 🏋️ Pilar Fitness\nIdeal para Lunes, Miércoles y Viernes."
|
| 23 |
+
},
|
| 24 |
+
"Lifestyle - Beach": {
|
| 25 |
+
"prompt": f"candid photo of {SOFIA_CORE}, tropical outfit, miami beach sunset, cinematic lighting, vibrant colors",
|
| 26 |
+
"desc": "### 🌴 Pilar Lifestyle\nIdeal para Martes y Jueves."
|
| 27 |
+
},
|
| 28 |
+
"Lifestyle - Luxury": {
|
| 29 |
+
"prompt": f"portrait of {SOFIA_CORE}, luxury miami apartment, morning light, natural makeup, authentic vibe",
|
| 30 |
+
"desc": "### ☕ Pilar Personal\nIdeal para Sábados."
|
| 31 |
+
},
|
| 32 |
+
"Premium - Elegant": {
|
| 33 |
+
"prompt": f"tasteful photography of {SOFIA_CORE}, elegant black lace, soft moody lighting, professional aesthetic",
|
| 34 |
+
"desc": "### 💎 Pilar Premium\nIdeal para Domingos."
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
def generate(category_name, tweak, model_id, steps, cfg, seed):
|
| 39 |
+
try:
|
| 40 |
+
cat = CATEGORIES[category_name]
|
| 41 |
+
prompt = f"{cat['prompt']}, {tweak}" if tweak else cat['prompt']
|
| 42 |
+
seed = random.randint(0, 2**32 - 1) if seed == -1 else int(seed)
|
| 43 |
+
|
| 44 |
+
image = client.text_to_image(
|
| 45 |
+
prompt=prompt,
|
| 46 |
+
model=model_id,
|
| 47 |
+
num_inference_steps=int(steps),
|
| 48 |
+
guidance_scale=float(cfg),
|
| 49 |
+
seed=seed
|
| 50 |
+
)
|
| 51 |
+
return image, f"✅ Generada: {category_name} | Seed: {seed}"
|
| 52 |
+
except Exception as e:
|
| 53 |
+
return None, f"❌ Error: {str(e)}"
|
| 54 |
+
|
| 55 |
+
def create_interface():
|
| 56 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 57 |
+
gr.Markdown("# 🌴 Sofia Rivera AI Workspace")
|
| 58 |
+
with gr.Tab("🎨 Generador"):
|
| 59 |
+
with gr.Row():
|
| 60 |
+
with gr.Column(scale=1):
|
| 61 |
+
cat_drop = gr.Dropdown(choices=list(CATEGORIES.keys()), label="Pilar", value="Fitness - Gym")
|
| 62 |
+
cat_info = gr.Markdown(CATEGORIES["Fitness - Gym"]["desc"])
|
| 63 |
+
tweak = gr.Textbox(label="Detalles extra", placeholder="ej: wearing sunglasses...")
|
| 64 |
+
with gr.Accordion("Avanzado", open=False):
|
| 65 |
+
model = gr.Dropdown(choices=["black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"], label="Modelo", value="black-forest-labs/FLUX.1-dev")
|
| 66 |
+
steps = gr.Slider(1, 50, 28, label="Pasos")
|
| 67 |
+
cfg = gr.Slider(1, 20, 7, label="Realismo")
|
| 68 |
+
seed = gr.Number(-1, label="Seed")
|
| 69 |
+
btn = gr.Button("🚀 Generar", variant="primary")
|
| 70 |
+
with gr.Column(scale=2):
|
| 71 |
+
out_img = gr.Image(label="Sofía Rivera")
|
| 72 |
+
out_log = gr.Textbox(label="Estado", interactive=False)
|
| 73 |
+
|
| 74 |
+
cat_drop.change(lambda x: CATEGORIES[x]["desc"], inputs=[cat_drop], outputs=[cat_info])
|
| 75 |
+
btn.click(generate, [cat_drop, tweak, model, steps, cfg, seed], [out_img, out_log])
|
| 76 |
+
return demo
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
create_interface().launch()
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|