Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
headers = {}
|
| 7 |
|
| 8 |
def chat(message, history=[]):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
|
| 12 |
-
result = response.json()
|
| 13 |
-
reply = result[0]['generated_text']
|
| 14 |
-
except Exception as e:
|
| 15 |
-
reply = f"⚠️ Error: {str(e)}"
|
| 16 |
history.append((message, reply))
|
| 17 |
return history, history
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
-
gr.Markdown("## 🤖 Permanent AI Chatbot
|
| 21 |
chat_ui = gr.Chatbot()
|
| 22 |
-
msg = gr.Textbox(label="Type your message")
|
| 23 |
clear = gr.Button("Clear Chat")
|
| 24 |
|
| 25 |
msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
|
| 26 |
clear.click(lambda: None, None, chat_ui, queue=False)
|
| 27 |
|
| 28 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Tiny, CPU-friendly model
|
| 5 |
+
chatbot_pipeline = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
|
|
|
| 6 |
|
| 7 |
def chat(message, history=[]):
|
| 8 |
+
result = chatbot_pipeline(message, max_new_tokens=50)
|
| 9 |
+
reply = result[0]['generated_text'].replace(message, "").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
history.append((message, reply))
|
| 11 |
return history, history
|
| 12 |
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown("## 🤖 Permanent Tiny AI Chatbot")
|
| 15 |
chat_ui = gr.Chatbot()
|
| 16 |
+
msg = gr.Textbox(label="Type your message here")
|
| 17 |
clear = gr.Button("Clear Chat")
|
| 18 |
|
| 19 |
msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
|
| 20 |
clear.click(lambda: None, None, chat_ui, queue=False)
|
| 21 |
|
| 22 |
demo.launch()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|