Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,27 @@
|
|
1 |
-
from transformers import
|
2 |
import gradio as gr
|
3 |
|
4 |
# Load the chatbot pipeline
|
5 |
-
chatbot = pipeline(model="facebook/blenderbot-400M-distill")
|
6 |
|
7 |
-
# Initialize message history
|
8 |
-
|
9 |
-
response_list = []
|
10 |
|
11 |
# Function to interact with the chatbot
|
12 |
def vanilla_chatbot(message, history):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
generated_responses=response_list
|
18 |
-
)
|
19 |
|
20 |
# Generate bot response
|
21 |
-
bot_response = chatbot(
|
22 |
|
23 |
-
# Append
|
24 |
-
|
25 |
-
response_list.append(bot_response[0]['generated_text'])
|
26 |
|
27 |
# Return the generated response
|
28 |
-
return bot_response[
|
29 |
|
30 |
# Create a Gradio chat interface
|
31 |
demo_chatbot = gr.Interface(
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
# Load the chatbot pipeline
|
5 |
+
chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
6 |
|
7 |
+
# Initialize message history
|
8 |
+
conversation_history = []
|
|
|
9 |
|
10 |
# Function to interact with the chatbot
|
11 |
def vanilla_chatbot(message, history):
|
12 |
+
global conversation_history
|
13 |
+
|
14 |
+
# Create a conversation turn
|
15 |
+
conversation_history.append({"role": "user", "content": message})
|
|
|
|
|
16 |
|
17 |
# Generate bot response
|
18 |
+
bot_response = chatbot(conversation_history)
|
19 |
|
20 |
+
# Append bot response to history
|
21 |
+
conversation_history.append({"role": "bot", "content": bot_response.generated_responses[-1]})
|
|
|
22 |
|
23 |
# Return the generated response
|
24 |
+
return bot_response.generated_responses[-1]
|
25 |
|
26 |
# Create a Gradio chat interface
|
27 |
demo_chatbot = gr.Interface(
|