Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def responder(
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
prompt = "Eres Intelarya.ai, una IA educativa que explica paso a paso de forma clara.\n\n"
|
| 12 |
|
| 13 |
-
for
|
| 14 |
-
|
| 15 |
-
prompt += f"Usuario: {msg['content']}\n"
|
| 16 |
-
else:
|
| 17 |
-
prompt += f"Intelarya: {msg['content']}\n"
|
| 18 |
|
| 19 |
-
prompt += f"Usuario: {
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
max_length=200,
|
| 24 |
-
do_sample=True,
|
| 25 |
-
temperature=0.7
|
| 26 |
-
)[0]["generated_text"]
|
| 27 |
|
| 28 |
-
|
| 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 |
-
|
| 41 |
-
msg = gr.Textbox(
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
-
msg.submit(responder, [msg,
|
| 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()
|