Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 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
|
| 11 |
|
| 12 |
-
for
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 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(
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Modelo
|
| 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 paso a paso de forma clara.\n\n"
|
| 11 |
|
| 12 |
+
for msg in history:
|
| 13 |
+
if msg["role"] == "user":
|
| 14 |
+
prompt += f"Usuario: {msg['content']}\n"
|
| 15 |
+
else:
|
| 16 |
+
prompt += f"Intelarya: {msg['content']}\n"
|
| 17 |
|
| 18 |
prompt += f"Usuario: {message}\nIntelarya:"
|
| 19 |
|
| 20 |
result = generator(prompt, max_length=150, do_sample=True, temperature=0.7)
|
| 21 |
response = result[0]["generated_text"].split("Intelarya:")[-1].strip()
|
| 22 |
|
| 23 |
+
history.append({"role": "user", "content": message})
|
| 24 |
+
history.append({"role": "assistant", "content": response})
|
| 25 |
+
|
| 26 |
return history, history
|
| 27 |
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
gr.Markdown("# 💎 intelarya.ai")
|
| 30 |
gr.Markdown("Aprende más rápido. Entiende mejor. Sin complicaciones.")
|
| 31 |
|
| 32 |
+
chatbot = gr.Chatbot(type="messages")
|
| 33 |
+
msg = gr.Textbox(placeholder="Escribe tu tarea aquí...")
|
| 34 |
|
| 35 |
state = gr.State([])
|
| 36 |
|