Spaces:
Sleeping
Sleeping
File size: 4,618 Bytes
ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 e002fe9 ad6d1b7 4574d8e e002fe9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import gradio as gr
import os
import random
from datetime import datetime
from huggingface_hub import InferenceClient
# Configuración
OUTPUT_DIR = "generated_images"
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Usamos el Token de los Secrets del Space
HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN") or os.getenv("HF_TOKEN")
client = InferenceClient(token=HF_TOKEN)
# Identidad de Sofía Rivera (Optimizada para realismo)
SOFIA_CORE = (
"sofia rivera, a beautiful 25-year-old latina cuban-american woman, "
"long dark wavy hair, mesmerizing hazel eyes, toned athletic fitness body, "
"natural radiant skin, miami influencer aesthetic, hyperrealistic, 8k"
)
CATEGORIES = {
"Fitness - Gym": {
"prompt": f"full body mirror selfie of {SOFIA_CORE}, wearing black sports bra and leggings, modern miami gym background, cinematic lighting",
"desc": "### 🏋️ Pilar Fitness\nIdeal para Lunes, Miércoles y Viernes."
},
"Lifestyle - Beach": {
"prompt": f"candid photo of {SOFIA_CORE}, tropical outfit, miami beach sunset, vibrant colors, bokeh background",
"desc": "### 🌴 Pilar Lifestyle\nIdeal para Martes y Jueves."
},
"Lifestyle - Luxury": {
"prompt": f"portrait of {SOFIA_CORE}, luxury miami apartment balcony, morning light, natural makeup, authentic vibe",
"desc": "### ☕ Pilar Personal\nIdeal para Sábados."
},
"Premium - Elegant": {
"prompt": f"tasteful photography of {SOFIA_CORE}, elegant black lace outfit, soft moody lighting, professional studio aesthetic",
"desc": "### 💎 Pilar Premium\nIdeal para Domingos."
}
}
def generate(category_name, tweak, model_id, steps, cfg, seed):
try:
if not HF_TOKEN:
return None, "❌ Error: No se encontró el HUGGINGFACE_TOKEN en los Secrets del Space."
cat = CATEGORIES[category_name]
prompt = f"{cat['prompt']}, {tweak}" if tweak else cat['prompt']
# Gestión de la Seed
final_seed = random.randint(0, 2**32 - 1) if seed == -1 else int(seed)
image = client.text_to_image(
prompt=prompt,
model=model_id,
num_inference_steps=int(steps),
guidance_scale=float(cfg),
seed=final_seed
)
return image, f"✅ Generada con {model_id} | Seed: {final_seed}"
except Exception as e:
return None, f"❌ Error: {str(e)}"
def create_interface():
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🌴 Sofia Rivera AI Workspace")
gr.Markdown("Generador de contenido oficial para la agencia de Sofía.")
with gr.Tab("🎨 Generador de Imágenes"):
with gr.Row():
with gr.Column(scale=1):
cat_drop = gr.Dropdown(choices=list(CATEGORIES.keys()), label="Selecciona el Pilar de Contenido", value="Fitness - Gym")
cat_info = gr.Markdown(CATEGORIES["Fitness - Gym"]["desc"])
tweak = gr.Textbox(label="Detalles extra (opcional)", placeholder="ej: holding a coffee, sunset, smiling...")
with gr.Accordion("Ajustes Técnicos (Avanzado)", open=True):
# CAMBIO CLAVE: 'schnell' es el modelo gratuito y rápido
model = gr.Dropdown(
choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-dev"],
label="Modelo (Schnell = Gratis)",
value="black-forest-labs/FLUX.1-schnell"
)
steps = gr.Slider(1, 12, 4, label="Pasos (Schnell funciona mejor con 4-8)")
cfg = gr.Slider(1, 20, 3.5, label="Guidance Scale")
seed = gr.Number(-1, label="Seed (-1 para aleatorio)")
btn = gr.Button("🚀 Generar Imagen de Sofía", variant="primary")
with gr.Column(scale=2):
out_img = gr.Image(label="Vista previa de Sofía")
out_log = gr.Textbox(label="Log de Estado", interactive=False)
cat_drop.change(lambda x: CATEGORIES[x]["desc"], inputs=[cat_drop], outputs=[cat_info])
btn.click(generate, [cat_drop, tweak, model, steps, cfg, seed], [out_img, out_log])
return demo
if __name__ == "__main__":
create_interface().launch()
|