Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
6 |
|
7 |
def respond(message, chat_history):
|
|
|
|
|
|
|
8 |
chat_history = chat_history or []
|
9 |
chat_history.append(("User", message))
|
10 |
-
response = chatbot(message)[0]['generated_text']
|
11 |
chat_history.append(("Bot", response))
|
|
|
12 |
chat_display = ""
|
13 |
for speaker, text in chat_history:
|
14 |
chat_display += f"{speaker}: {text}\n"
|
@@ -20,7 +23,11 @@ with gr.Blocks() as demo:
|
|
20 |
user_input = gr.Textbox(label="Your Message")
|
21 |
send_button = gr.Button("Send")
|
22 |
|
23 |
-
send_button.click(
|
|
|
|
|
|
|
|
|
24 |
|
25 |
if __name__ == "__main__":
|
26 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the chatbot model using text-generation pipeline
|
5 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
6 |
|
7 |
def respond(message, chat_history):
|
8 |
+
# Generate a response using the model
|
9 |
+
response = chatbot(message, max_new_tokens=100)[0]['generated_text']
|
10 |
+
# Update chat history
|
11 |
chat_history = chat_history or []
|
12 |
chat_history.append(("User", message))
|
|
|
13 |
chat_history.append(("Bot", response))
|
14 |
+
# Format chat history for display
|
15 |
chat_display = ""
|
16 |
for speaker, text in chat_history:
|
17 |
chat_display += f"{speaker}: {text}\n"
|
|
|
23 |
user_input = gr.Textbox(label="Your Message")
|
24 |
send_button = gr.Button("Send")
|
25 |
|
26 |
+
send_button.click(
|
27 |
+
fn=respond,
|
28 |
+
inputs=[user_input, chat_history],
|
29 |
+
outputs=[chatbot_output, chat_history]
|
30 |
+
)
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
demo.launch()
|