hexanovapixel commited on
Commit
efa0f7b
·
verified ·
1 Parent(s): ded379a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -1,17 +1,20 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Cargar modelo (ligero para que funcione bien)
5
  chatbot = pipeline("text-generation", model="gpt2")
6
 
7
- # Función del chatbot
8
  def responder(mensaje, historial):
9
  historial = historial or []
10
 
11
- prompt = "Eres Intelarya.ai, una IA educativa elegante e inteligente. Explicas paso a paso, de forma clara, sencilla y útil para estudiantes.\n\n"
 
12
 
13
- for user, bot in historial:
14
- prompt += f"Usuario: {user}\nIntelarya: {bot}\n"
 
 
 
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.append((mensaje, texto))
 
 
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([])