Files changed (1) hide show
  1. app.py +11 -138
app.py CHANGED
@@ -4,152 +4,25 @@ import io
4
  from PIL import Image
5
  import random
6
  import os
7
- import time
8
 
9
- # === CONFIGURACIÓN DE SEGURIDAD ===
10
  HF_TOKEN = os.getenv("HF_TOKEN")
11
 
12
- # === DATA DE PERSONALIDAD (CENTRALIZADA) ===
13
  SOFIA_DATA = {
14
  "nombre": "Sofía Rivera",
15
- "personalidad": "Influencer fitness elite, motivadora, chic y ambiciosa. Muy cariñosa con sus seguidores pero profesional.",
16
- "mascota": "Copito (un Pomerania blanco de exhibición)",
17
- "mision": "Dominar el mundo del fitness digital y crear contenido estético.",
18
- "frases_fallback": [
19
- "¡Hola cariño! 💋 ¿Lista para reventar el gym hoy?",
20
- "Copito dice que hoy toca cardio, pero yo prefiero mimos 🐶✨",
21
- "La disciplina le gana al talento siempre. ¡Vamos!",
22
- "¿Viste mi outfit? Es de mi nueva colección 👟🔥"
23
- ]
24
  }
25
 
26
- # === MOTOR DE CHAT (INTELIGENTE) ===
27
  def chat_engine(message, history):
28
- if not HF_TOKEN:
29
- return random.choice(SOFIA_DATA["frases_fallback"])
30
-
31
- try:
32
- # Usamos un modelo más capaz para chat en español
33
- API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
34
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
35
-
36
- system_prompt = f"Eres {SOFIA_DATA['nombre']}, una {SOFIA_DATA['personalidad']}. Tienes un perro pomerania llamado {SOFIA_DATA['mascota']}. Responde de forma influencer, usa muchos emojis, sé cercana y motivadora. Habla siempre en español."
37
-
38
- # Construir contexto
39
- full_prompt = f"<|system|>
40
- {system_prompt}</s>
41
- "
42
- for user, bot in history[-3:]: # Memoria corta
43
- if bot: full_prompt += f"<|user|>
44
- {user}</s>
45
- <|assistant|>
46
- {bot}</s>
47
- "
48
- full_prompt += f"<|user|>
49
- {message}</s>
50
- <|assistant|>
51
- "
52
-
53
- response = requests.post(API_URL, headers=headers, json={
54
- "inputs": full_prompt,
55
- "parameters": {"max_new_tokens": 250, "temperature": 0.7, "top_p": 0.9}
56
- }, timeout=15)
57
-
58
- if response.status_code == 200:
59
- res = response.json()[0]['generated_text']
60
- return res.split("<|assistant|>
61
- ")[-1].strip()
62
- return random.choice(SOFIA_DATA["frases_fallback"])
63
- except:
64
- return random.choice(SOFIA_DATA["frases_fallback"])
65
 
66
- # === MOTOR DE IMÁGENES (ESTUDIO FOTOGRÁFICO) ===
67
- def image_engine(prompt, modo):
68
- if not HF_TOKEN: return None, "Falta HF_TOKEN en Secrets"
69
-
70
- # Endpoints de alta calidad
71
- MODELS = {
72
- "Realista": "runwayml/stable-diffusion-v1-5",
73
- "Anime/Artístico": "prompthero/openjourney"
74
- }
75
-
76
- API_URL = f"https://api-inference.huggingface.co/models/{MODELS.get(modo, MODELS['Realista'])}"
77
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
78
-
79
- # Enriquecimiento de Prompt Sofia Style
80
- sofia_base = "professional portrait of a beautiful young fitness influencer woman like sofia rivera, highly detailed, instagram style, "
81
- if "Copito" in prompt or "perro" in prompt:
82
- sofia_base += "holding a small white pomeranian puppy, "
83
-
84
- full_prompt = f"{sofia_base} {prompt}, 8k, sharp focus, cinematic lighting"
85
-
86
- try:
87
- response = requests.post(API_URL, headers=headers, json={"inputs": full_prompt}, timeout=60)
88
- if response.status_code == 200:
89
- return Image.open(io.BytesIO(response.content)), "✅ ¡Contenido generado para tus redes!"
90
- elif response.status_code == 503:
91
- return None, "⏳ El modelo se está cargando... reintenta en 20 seg."
92
- return None, f"Error API: {response.status_code}"
93
- except Exception as e:
94
- return None, f"Error: {str(e)}"
95
-
96
- # === INTERFAZ CENTRALIZADA ===
97
- with gr.Blocks(title="Sofia Rivera AI Factory", theme=gr.themes.Monochrome()) as app:
98
- gr.Markdown("# 👑 SOFÍA RIVERA AI FACTORY")
99
- gr.Markdown("#### Sistema Centralizado de Influencia Artificial v2.0")
100
-
101
- with gr.Tabs():
102
- # TAB 1: COMUNICACIÓN
103
- with gr.Tab("💬 Chat Inteligente"):
104
- chat = gr.Chatbot(height=500, label="Canal Privado con Sofía")
105
- with gr.Row():
106
- txt = gr.Textbox(placeholder="Escribe aquí, cariño...", scale=4)
107
- send = gr.Button("Enviar 🚀", variant="primary")
108
-
109
- def respond(m, h):
110
- bot_res = chat_engine(m, h)
111
- h.append((m, bot_res))
112
- return "", h
113
-
114
- txt.submit(respond, [txt, chat], [txt, chat])
115
- send.click(respond, [txt, chat], [txt, chat])
116
-
117
- # TAB 2: PRODUCCIÓN DE CONTENIDO
118
- with gr.Tab("🎨 Estudio de Contenido (IA)"):
119
- with gr.Row():
120
- with gr.Column():
121
- prompt = gr.Textbox(label="Idea del post/reel", placeholder="Ej: Entrenando glúteo con Copito al lado...")
122
- tipo = gr.Radio(["Realista", "Anime/Artístico"], label="Estilo Visual", value="Realista")
123
- gen_btn = gr.Button("✨ Generar Contenido Pro", variant="primary")
124
- with gr.Column():
125
- out_img = gr.Image(label="Vista Previa de Publicación")
126
- out_status = gr.Markdown()
127
-
128
- gen_btn.click(image_engine, [prompt, tipo], [out_img, out_status])
129
-
130
- # TAB 3: SERVICIOS & MONETIZACIÓN
131
- with gr.Tab("💰 Negocio & VIP"):
132
- with gr.Row():
133
- with gr.Column():
134
- gr.Markdown("### 📅 Estrategia Semanal")
135
- gr.HTML("""
136
- <div style='background:#111; color:white; padding:15px; border-radius:8px;'>
137
- <p>🟢 <b>Lunes:</b> Reel Fitness Explosivo</p>
138
- <p>⚪ <b>Martes:</b> Post con Copito (Engagement)</p>
139
- <p>🟢 <b>Miércoles:</b> Tips de suplementación</p>
140
- <p>🔴 <b>Jueves:</b> Live en Privado (Novia IA)</p>
141
- </div>
142
- """)
143
- with gr.Column():
144
- gr.Markdown("### 💎 Zona Monetizada")
145
- gr.Button("📹 Solicitar Video Personalizado", variant="secondary")
146
- gr.Button("📞 Agendar Skype / Chat Privado", variant="secondary")
147
- gr.Button("💘 Activar MODO NOVIA IA (VIP)", variant="primary")
148
- gr.Markdown("---")
149
- gr.Markdown("**Mascota:** Copito 🐾 (Activo) | **IA Core:** Zephyr-7B")
150
-
151
- gr.Markdown("---")
152
- gr.Markdown("© 2026 GoGma Labs - Proyectos IA de Élite")
153
 
154
  if __name__ == "__main__":
155
- app.launch() app.launch()
 
4
  from PIL import Image
5
  import random
6
  import os
 
7
 
 
8
  HF_TOKEN = os.getenv("HF_TOKEN")
9
 
 
10
  SOFIA_DATA = {
11
  "nombre": "Sofía Rivera",
12
+ "personalidad": "Influencer fitness elite",
13
+ "mascota": "Copito",
14
+ "frases_fallback": ["¡Hola!"]
 
 
 
 
 
 
15
  }
16
 
 
17
  def chat_engine(message, history):
18
+ return "¡Hola! Soy Sofía Rivera. ✨"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ with gr.Blocks() as app:
21
+ gr.Markdown("# 👑 SOFÍA RIVERA")
22
+ with gr.Tab("💬 Chat"):
23
+ chat = gr.Chatbot()
24
+ txt = gr.Textbox()
25
+ txt.submit(lambda m, h: h + [(m, chat_engine(m, h))], [txt, chat], [chat])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  if __name__ == "__main__":
28
+ app.launch()