Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
chatbot = pipeline("text-generation", model="gpt2")
|
| 6 |
|
| 7 |
-
# Función del chatbot
|
| 8 |
def responder(mensaje, historial):
|
| 9 |
historial = historial or []
|
| 10 |
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
for
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
prompt += f"Usuario: {mensaje}\nIntelarya:"
|
| 17 |
|
|
@@ -24,16 +27,17 @@ def responder(mensaje, historial):
|
|
| 24 |
|
| 25 |
texto = respuesta.split("Intelarya:")[-1].strip()
|
| 26 |
|
| 27 |
-
historial
|
|
|
|
|
|
|
| 28 |
|
| 29 |
return historial, historial
|
| 30 |
|
| 31 |
-
# Interfaz PRO tipo chat
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
gr.Markdown("# 💎 intelarya.ai")
|
| 34 |
gr.Markdown("Aprende más rápido. Entiende mejor. Sin complicaciones.")
|
| 35 |
|
| 36 |
-
chatbot_ui = gr.Chatbot()
|
| 37 |
msg = gr.Textbox(placeholder="Escribe tu tarea aquí...")
|
| 38 |
|
| 39 |
estado = gr.State([])
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Modelo (ligero)
|
| 5 |
chatbot = pipeline("text-generation", model="gpt2")
|
| 6 |
|
|
|
|
| 7 |
def responder(mensaje, historial):
|
| 8 |
historial = historial or []
|
| 9 |
|
| 10 |
+
# Crear prompt con historial
|
| 11 |
+
prompt = "Eres Intelarya.ai, una IA educativa que explica paso a paso de forma clara.\n\n"
|
| 12 |
|
| 13 |
+
for msg in historial:
|
| 14 |
+
if msg["role"] == "user":
|
| 15 |
+
prompt += f"Usuario: {msg['content']}\n"
|
| 16 |
+
else:
|
| 17 |
+
prompt += f"Intelarya: {msg['content']}\n"
|
| 18 |
|
| 19 |
prompt += f"Usuario: {mensaje}\nIntelarya:"
|
| 20 |
|
|
|
|
| 27 |
|
| 28 |
texto = respuesta.split("Intelarya:")[-1].strip()
|
| 29 |
|
| 30 |
+
# Agregar al historial en formato correcto
|
| 31 |
+
historial.append({"role": "user", "content": mensaje})
|
| 32 |
+
historial.append({"role": "assistant", "content": texto})
|
| 33 |
|
| 34 |
return historial, historial
|
| 35 |
|
|
|
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
gr.Markdown("# 💎 intelarya.ai")
|
| 38 |
gr.Markdown("Aprende más rápido. Entiende mejor. Sin complicaciones.")
|
| 39 |
|
| 40 |
+
chatbot_ui = gr.Chatbot(type="messages")
|
| 41 |
msg = gr.Textbox(placeholder="Escribe tu tarea aquí...")
|
| 42 |
|
| 43 |
estado = gr.State([])
|