Jamalshah commited on
Commit
c1f2647
·
2 Parent(s): ccfd5aad315061

Merge branch 'main' of https://huggingface.co/spaces/Jamal811/Test-Chatbot

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,17 +1,19 @@
1
- from transformers import pipeline, Conversation
2
  import gradio as gr
3
 
4
- chatbot = pipeline(model="facebook/blenderbot-400M-distill")
5
-
6
- message_list = []
7
- response_list = []
8
 
 
9
  def vanilla_chatbot(message, history):
10
- conversation = Conversation(text=message, past_user_inputs=message_list, generated_responses=response_list)
11
- conversation = chatbot(conversation)
12
-
13
- return conversation.generated_responses[-1]
 
14
 
15
- demo_chatbot = gr.ChatInterface(vanilla_chatbot, title="Vanilla Chatbot", description="Enter text to start chatting.")
 
16
 
17
- demo_chatbot.launch()
 
 
1
+ from transformers import pipeline
2
  import gradio as gr
3
 
4
+ # Use the BlenderBot model with the 'text2text-generation' task
5
+ chatbot = pipeline("text2text-generation", model="facebook/blenderbot-400M-distill")
 
 
6
 
7
+ # Function to handle conversation
8
  def vanilla_chatbot(message, history):
9
+ # Generate a response using the chatbot model
10
+ response = chatbot(message)
11
+
12
+ # Return the generated response
13
+ return response[0]['generated_text']
14
 
15
+ # Initialize the Gradio ChatInterface with 'messages' format
16
+ demo_chatbot = gr.ChatInterface(vanilla_chatbot, title="Vanilla Chatbot", description="Enter text to start chatting.", type="messages")
17
 
18
+ # Launch the Gradio interface with a public link
19
+ demo_chatbot.launch(share=True)