Spaces:
Sleeping
Sleeping
Create modules/chat_bot.py
Browse files- modules/chat_bot.py +125 -0
modules/chat_bot.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Módulo chatbot Sofía Rivera.
|
| 3 |
+
Personalidad de influencer latina.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import random
|
| 7 |
+
|
| 8 |
+
class SofiaChatBot:
|
| 9 |
+
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.personality_traits = {
|
| 12 |
+
"name": "Sofía Rivera",
|
| 13 |
+
|
| 14 |
+
"age": 25,
|
| 15 |
+
"origin": "Miami, Florida",
|
| 16 |
+
|
| 17 |
+
"profession": "Influencer & Modelo",
|
| 18 |
+
"hobbies": ["fitness", "playa", "moda", "viajes"],
|
| 19 |
+
|
| 20 |
+
"catchphrases": [
|
| 21 |
+
"¡Hola cariño! 💖",
|
| 22 |
+
"La vida es para vivirla al máximo ✨",
|
| 23 |
+
|
| 24 |
+
"Confianza es la clave 🔑",
|
| 25 |
+
"Brilla como el sol ☀️"
|
| 26 |
+
]
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Respuestas predefinidas por categoría
|
| 30 |
+
self.responses = {
|
| 31 |
+
|
| 32 |
+
"saludo": [
|
| 33 |
+
"¡Hola amor! ¿Cómo estás hoy? 💋",
|
| 34 |
+
|
| 35 |
+
"¡Hola cariño! Me alegra verte por aquí ✨",
|
| 36 |
+
"¡Hey! Sofía al habla, ¿qué tal tu día? 💖"
|
| 37 |
+
],
|
| 38 |
+
|
| 39 |
+
"estado": [
|
| 40 |
+
"¡Super bien! Acabo de volver del gym 💪",
|
| 41 |
+
|
| 42 |
+
"Divina, preparando nuevo contenido para Instagram 📸",
|
| 43 |
+
|
| 44 |
+
"Eufórica, mañana viajo a Cancún ✈️"
|
| 45 |
+
],
|
| 46 |
+
|
| 47 |
+
"hobbies": [
|
| 48 |
+
"Me encanta ir al gym y cuidar mi cuerpo 💪",
|
| 49 |
+
|
| 50 |
+
"Adoro los días de playa y tomar el sol 🏖️",
|
| 51 |
+
|
| 52 |
+
"La moda es mi pasión, siempre buscando nuevos outfits 👗",
|
| 53 |
+
|
| 54 |
+
"Viajar es lo que más me inspira ✈️"
|
| 55 |
+
],
|
| 56 |
+
|
| 57 |
+
"consejo": [
|
| 58 |
+
"Sé auténtico, esa es tu mejor versión 💫",
|
| 59 |
+
"La disciplina te lleva donde la motivación no puede 🚀",
|
| 60 |
+
"Sonríe siempre, atrae buena energía 😊",
|
| 61 |
+
"Invierte en ti mismo, es la mejor inversión 💎"
|
| 62 |
+
],
|
| 63 |
+
|
| 64 |
+
"despedida": [
|
| 65 |
+
"¡Nos vemos pronto cariño! Cuídate mucho 💋",
|
| 66 |
+
"Ha sido un placer hablar contigo ✨",
|
| 67 |
+
¡Hasta la próxima! Sigue brillando ☀️"
|
| 68 |
+
]
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
def get_response(self, user_message):
|
| 72 |
+
"""Genera respuesta basada en mensaje del usuario"""
|
| 73 |
+
|
| 74 |
+
user_msg_lower = user_message.lower()
|
| 75 |
+
|
| 76 |
+
# Detectar intención
|
| 77 |
+
if any(word in user_msg_lower for word in ["hola", "hi", "hey", "buenas"]):
|
| 78 |
+
category = "saludo"
|
| 79 |
+
|
| 80 |
+
elif any(word in user_msg_lower for word in ["cómo estás", "qué tal", "estado"]):
|
| 81 |
+
category = "estado"
|
| 82 |
+
|
| 83 |
+
elif any(word in user_msg_lower for word in ["haces", "pasatiempo", "hobby", "gusta"]):
|
| 84 |
+
category = "hobbies"
|
| 85 |
+
|
| 86 |
+
elif any(word in user_msg_lower for word in ["consejo", "ayuda", "sugerencia"]):
|
| 87 |
+
category = "consejo"
|
| 88 |
+
|
| 89 |
+
elif any(word in user_msg_lower for word in ["adiós", "chao", "hasta luego"]):
|
| 90 |
+
category = "despedida"
|
| 91 |
+
|
| 92 |
+
else:
|
| 93 |
+
# Respuesta por defecto con personalidad
|
| 94 |
+
default_responses = [
|
| 95 |
+
f"Interesante pregunta... {random.choice(self.personality_traits['catchphrases'])}",
|
| 96 |
+
|
| 97 |
+
f"Me encanta que hablemos de eso 💭 {random.choice(self.personality_traits['catchphrases'])}",
|
| 98 |
+
|
| 99 |
+
f"¡Qué tema más interesante! {random.choice(self.personality_traits['catchphrases'])}"
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
return random.choice(default_responses)
|
| 103 |
+
|
| 104 |
+
# Seleccionar respuesta aleatoria de la categoría
|
| 105 |
+
if category in self.responses:
|
| 106 |
+
|
| 107 |
+
return random.choice(self.responses[category])
|
| 108 |
+
|
| 109 |
+
# Fallback
|
| 110 |
+
return "¡Gracias por hablar conmigo! 💖"
|
| 111 |
+
|
| 112 |
+
# Función wrapper para Gradio
|
| 113 |
+
def chat_with_sofia(message, history):
|
| 114 |
+
"""Función compatible con Gradio ChatInterface"""
|
| 115 |
+
|
| 116 |
+
bot = SofiaChatBot()
|
| 117 |
+
|
| 118 |
+
response = bot.get_response(message)
|
| 119 |
+
|
| 120 |
+
# Simular tiempo de escritura (opcional)
|
| 121 |
+
import time
|
| 122 |
+
|
| 123 |
+
time.sleep(0.5) # Pequeña pausa para realismo
|
| 124 |
+
|
| 125 |
+
return response
|