hexanovapixel commited on
Commit
dc0b2cf
·
verified ·
1 Parent(s): 97ebbb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -29
app.py CHANGED
@@ -1,47 +1,34 @@
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
 
21
- respuesta = chatbot(
22
- prompt,
23
- max_length=200,
24
- do_sample=True,
25
- temperature=0.7
26
- )[0]["generated_text"]
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([])
44
 
45
- msg.submit(responder, [msg, estado], [chatbot_ui, estado])
46
 
47
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Cargar modelo ligero
5
+ generator = pipeline("text-generation", model="gpt2")
6
 
7
+ def responder(message, history):
8
+ history = history or []
9
 
10
+ prompt = "Eres Intelarya.ai, una IA educativa que explica claro y paso a paso.\n\n"
 
11
 
12
+ for h in history:
13
+ prompt += f"Usuario: {h[0]}\nIntelarya: {h[1]}\n"
 
 
 
14
 
15
+ prompt += f"Usuario: {message}\nIntelarya:"
16
 
17
+ result = generator(prompt, max_length=150, do_sample=True, temperature=0.7)
18
+ response = result[0]["generated_text"].split("Intelarya:")[-1].strip()
 
 
 
 
19
 
20
+ history.append((message, response))
21
+ return history, history
 
 
 
 
 
22
 
23
  with gr.Blocks() as demo:
24
  gr.Markdown("# 💎 intelarya.ai")
25
  gr.Markdown("Aprende más rápido. Entiende mejor. Sin complicaciones.")
26
 
27
+ chatbot = gr.Chatbot()
28
+ msg = gr.Textbox()
29
 
30
+ state = gr.State([])
31
 
32
+ msg.submit(responder, [msg, state], [chatbot, state])
33
 
34
  demo.launch()