import gradio as gr import requests, io, os, random from PIL import Image HF_TOKEN = os.getenv("HF_TOKEN") SOFIA = { "name": "Sofía Rivera", "mascot": "Copito", "personality": "Fitness influencer from Miami, energetic and authentic." } def chat(m, h): if not HF_TOKEN: return "Mantenimiento..." try: url = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta" headers = {"Authorization": f"Bearer {HF_TOKEN}"} prompt = f"<|system|>Eres {SOFIA['name']}, influencer de fitness. Tienes un perro llamado {SOFIA['mascota']}. Habla en español.<|user|>{m}<|assistant|>" res = requests.post(url, headers=headers, json={"inputs": prompt}, timeout=10) return res.json()[0]['generated_text'].split("<|assistant|>")[-1].strip().replace("", "") except: return "Hola cariño, entrena duro hoy! ✨" def gen(p): if not HF_TOKEN: return None, "Sin Token" url = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5" try: r = requests.post(url, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json={"inputs": f"portrait of {SOFIA['name']}, latina influencer, {p}, 8k"}, timeout=60) return Image.open(io.BytesIO(r.content)), "✅ Listo" except: return None, "Error" with gr.Blocks(theme=gr.themes.Soft()) as app: gr.Markdown("# 👑 SOFÍA RIVERA AI FACTORY") with gr.Tabs(): with gr.Tab("💬 Chat"): chatbot = gr.Chatbot(height=400) msg = gr.Textbox() def respond(m, h): h.append((m, chat(m, h))); return "", h msg.submit(respond, [msg, chatbot], [msg, chatbot]) with gr.Tab("🎨 Fotos"): with gr.Row(): inp = gr.Textbox(); btn = gr.Button("Crear") out = gr.Image(); st = gr.Markdown() btn.click(gen, [inp], [out, st]) with gr.Tab("📊 VIP"): gr.Dataframe(value=[["Lunes", "Reel"], ["Jueves", "Novia IA"]]) gr.Button("💖 Modo Novia VIP") if __name__ == "__main__": app.launch()