import gradio as gr | |
from transformers import pipeline | |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2") | |
# Variable para almacenar el historial de conversaci贸n | |
historial = "" | |
def responder(texto_usuario): | |
global historial | |
prompt_inicial = "T煤 eres AURA, un asistente emocional escolar muy amable. Escucha sin juzgar y responde con empat铆a." | |
# Construir el nuevo prompt con el historial | |
prompt = ( | |
f"{prompt_inicial}\n" | |
f"{historial}" | |
f"Usuario: {texto_usuario}\n" | |
f"AURA:" | |
) | |
resultado_completo = generator(prompt, max_length=100)[0]["text"] | |
respuesta = resultado_completo[len(prompt):].strip() | |
# Actualizar el historial | |
historial += f"Usuario: {texto_usuario}\nAURA: {respuesta}\n" | |
return respuesta | |
iface = gr.Interface( | |
fn=responder, | |
inputs="text", | |
outputs="text", | |
title="AURA", | |
description="Tu espacio seguro 馃挏" | |
) | |
iface.launch() | |