Spaces:
Runtime error
Runtime error
updated
Browse files
app.py
CHANGED
|
@@ -1,21 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# --------
|
| 5 |
text_model = pipeline("text-generation", model="distilgpt2")
|
| 6 |
|
| 7 |
-
# --------
|
| 8 |
def respond(user_input, history):
|
| 9 |
-
# text response only (no crashes)
|
| 10 |
result = text_model(user_input, max_length=80)[0]["generated_text"]
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return history, history
|
| 13 |
|
| 14 |
# -------- UI --------
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
-
gr.Markdown("# Simple AI Chat (
|
| 17 |
|
| 18 |
-
chatbot = gr.Chatbot()
|
| 19 |
state = gr.State([])
|
| 20 |
|
| 21 |
with gr.Row():
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# -------- MODEL --------
|
| 5 |
text_model = pipeline("text-generation", model="distilgpt2")
|
| 6 |
|
| 7 |
+
# -------- FUNCTION --------
|
| 8 |
def respond(user_input, history):
|
|
|
|
| 9 |
result = text_model(user_input, max_length=80)[0]["generated_text"]
|
| 10 |
+
|
| 11 |
+
history = history + [
|
| 12 |
+
{"role": "user", "content": user_input},
|
| 13 |
+
{"role": "assistant", "content": result}
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
return history, history
|
| 17 |
|
| 18 |
# -------- UI --------
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
+
gr.Markdown("# Simple AI Chat (Fixed)")
|
| 21 |
|
| 22 |
+
chatbot = gr.Chatbot(type="messages") # β
IMPORTANT
|
| 23 |
state = gr.State([])
|
| 24 |
|
| 25 |
with gr.Row():
|