Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Better
|
| 5 |
chatbot = pipeline(
|
| 6 |
-
"
|
| 7 |
model="google/flan-t5-small"
|
| 8 |
)
|
| 9 |
|
| 10 |
def reply(message, history):
|
| 11 |
if not message.strip():
|
| 12 |
-
return
|
| 13 |
|
| 14 |
-
# Instruction-based prompt
|
| 15 |
prompt = f"User: {message}\nAssistant:"
|
| 16 |
|
| 17 |
result = chatbot(
|
|
@@ -23,16 +22,19 @@ def reply(message, history):
|
|
| 23 |
|
| 24 |
output = result[0]["generated_text"]
|
| 25 |
|
| 26 |
-
# Extract only assistant
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
return history
|
| 31 |
|
|
|
|
| 32 |
demo = gr.ChatInterface(
|
| 33 |
fn=reply,
|
| 34 |
title="💬 Smart Dialogue System",
|
| 35 |
-
description="
|
| 36 |
)
|
| 37 |
|
| 38 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Better chatbot model
|
| 5 |
chatbot = pipeline(
|
| 6 |
+
"text2text-generation",
|
| 7 |
model="google/flan-t5-small"
|
| 8 |
)
|
| 9 |
|
| 10 |
def reply(message, history):
|
| 11 |
if not message.strip():
|
| 12 |
+
return "Please enter a message."
|
| 13 |
|
|
|
|
| 14 |
prompt = f"User: {message}\nAssistant:"
|
| 15 |
|
| 16 |
result = chatbot(
|
|
|
|
| 22 |
|
| 23 |
output = result[0]["generated_text"]
|
| 24 |
|
| 25 |
+
# Extract only assistant response
|
| 26 |
+
if "Assistant:" in output:
|
| 27 |
+
response = output.split("Assistant:")[-1].strip()
|
| 28 |
+
else:
|
| 29 |
+
response = output.strip()
|
| 30 |
|
| 31 |
+
return response # ✅ ONLY RETURN STRING
|
|
|
|
| 32 |
|
| 33 |
+
# Chat UI
|
| 34 |
demo = gr.ChatInterface(
|
| 35 |
fn=reply,
|
| 36 |
title="💬 Smart Dialogue System",
|
| 37 |
+
description="Chatbot using FLAN-T5"
|
| 38 |
)
|
| 39 |
|
| 40 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|