Añadir memoria de conversación a AURA
Browse filesHacer que AURA pueda tener un seguimiento de las conversaciones y reccuerde mensajes pasadps
app.py
CHANGED
@@ -3,11 +3,28 @@ from transformers import pipeline
|
|
3 |
|
4 |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
5 |
|
|
|
|
|
|
|
6 |
def responder(texto_usuario):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
iface = gr.Interface(
|
|
|
3 |
|
4 |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
5 |
|
6 |
+
# Variable para almacenar el historial de conversación
|
7 |
+
historial = ""
|
8 |
+
|
9 |
def responder(texto_usuario):
|
10 |
+
global historial
|
11 |
+
prompt_inicial = "Tú eres AURA, un asistente emocional escolar muy amable. Escucha sin juzgar y responde con empatía."
|
12 |
+
|
13 |
+
# Construir el nuevo prompt con el historial
|
14 |
+
prompt = (
|
15 |
+
f"{prompt_inicial}\n"
|
16 |
+
f"{historial}"
|
17 |
+
f"Usuario: {texto_usuario}\n"
|
18 |
+
f"AURA:"
|
19 |
+
)
|
20 |
+
|
21 |
+
resultado_completo = generator(prompt, max_length=100)[0]["text"]
|
22 |
+
respuesta = resultado_completo[len(prompt):].strip()
|
23 |
+
|
24 |
+
# Actualizar el historial
|
25 |
+
historial += f"Usuario: {texto_usuario}\nAURA: {respuesta}\n"
|
26 |
+
|
27 |
+
return respuesta
|
28 |
|
29 |
|
30 |
iface = gr.Interface(
|