Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -191,7 +191,7 @@ def buscar_por_genero(genero, k=5):
|
|
191 |
# Formatear las recomendaciones
|
192 |
recommendations = []
|
193 |
for title in recommended_titles:
|
194 |
-
recommendations.append(f"
|
195 |
|
196 |
return "\n".join(recommendations) if recommendations else f"No se encontraron K-Dramas del género '{genero}'."
|
197 |
|
@@ -203,7 +203,7 @@ def recomendar_kdramas_chat(entrada_usuario):
|
|
203 |
if preferencia_traducida:
|
204 |
return buscar_por_genero(preferencia_traducida, k=5)
|
205 |
else:
|
206 |
-
return
|
207 |
|
208 |
# Función para generar respuestas del chatbot
|
209 |
def generar_respuesta(entrada_usuario, historial_chat=""):
|
@@ -214,20 +214,27 @@ def generar_respuesta(entrada_usuario, historial_chat=""):
|
|
214 |
|
215 |
# Función para manejar la interacción del chatbot
|
216 |
def chat(entrada_usuario, historial_chat=""):
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
222 |
else:
|
223 |
respuesta = generar_respuesta(entrada_usuario, historial_chat)
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
if recomendacion
|
228 |
-
respuesta = f"
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
# ==================================================
|
233 |
# Interfaz de Gradio
|
|
|
191 |
# Formatear las recomendaciones
|
192 |
recommendations = []
|
193 |
for title in recommended_titles:
|
194 |
+
recommendations.append(f"- {title}")
|
195 |
|
196 |
return "\n".join(recommendations) if recommendations else f"No se encontraron K-Dramas del género '{genero}'."
|
197 |
|
|
|
203 |
if preferencia_traducida:
|
204 |
return buscar_por_genero(preferencia_traducida, k=5)
|
205 |
else:
|
206 |
+
return None # No se encontró una preferencia válida
|
207 |
|
208 |
# Función para generar respuestas del chatbot
|
209 |
def generar_respuesta(entrada_usuario, historial_chat=""):
|
|
|
214 |
|
215 |
# Función para manejar la interacción del chatbot
|
216 |
def chat(entrada_usuario, historial_chat=""):
|
217 |
+
# Agregar el mensaje del usuario al historial
|
218 |
+
historial_chat += f"Usuario: {entrada_usuario}\n"
|
219 |
+
|
220 |
+
# Generar una respuesta natural del chatbot
|
221 |
+
if not historial_chat.strip(): # Si es la primera interacción
|
222 |
+
respuesta = "¡Hola! Soy tu asistente para recomendar K-Dramas. ¿Qué tipo de K-Drama te gustaría ver hoy?"
|
223 |
else:
|
224 |
respuesta = generar_respuesta(entrada_usuario, historial_chat)
|
225 |
+
|
226 |
+
# Verificar si el usuario mencionó un género
|
227 |
+
recomendacion = recomendar_kdramas_chat(entrada_usuario)
|
228 |
+
if recomendacion:
|
229 |
+
respuesta = f"¡Genial! Aquí tienes algunas recomendaciones de K-Dramas que podrían gustarte:\n{recomendacion}"
|
230 |
+
else:
|
231 |
+
respuesta = "¿Qué tipo de K-Drama te gustaría ver? Puedo recomendarte dramas de acción, romance, misterio y más."
|
232 |
+
|
233 |
+
# Agregar la respuesta del chatbot al historial
|
234 |
+
historial_chat += f"Chatbot: {respuesta}\n"
|
235 |
+
|
236 |
+
# Devolver la respuesta y el historial actualizado
|
237 |
+
return respuesta, historial_chat, "" # Limpiar el cuadro de texto
|
238 |
|
239 |
# ==================================================
|
240 |
# Interfaz de Gradio
|