ChatBot / app.py
Siri23's picture
Update app.py
2c0b1a8 verified
raw
history blame
1.21 kB
from transformers import Conversation, pipeline
import gradio as gr
# Load the chatbot pipeline
chatbot = pipeline(model="facebook/blenderbot-400M-distill")
# Initialize message history lists
message_list = []
response_list = []
# Function to interact with the chatbot
def vanilla_chatbot(message, history):
# Create a Conversation object
conversation = Conversation(
text=message,
past_user_inputs=message_list,
generated_responses=response_list
)
# Generate bot response
bot_response = chatbot(conversation.messages[0]['content'])
# Append message and response to history lists
message_list.append(message)
response_list.append(bot_response[0]['generated_text'])
# Return the generated response
return bot_response[0]['generated_text']
# Create a Gradio chat interface
demo_chatbot = gr.Interface(
fn=vanilla_chatbot,
inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),
outputs=gr.Textbox(placeholder="Bot response will appear here...", readonly=True),
title="Mashdemy Chatbot",
description="Enter text to start chatting."
)
# Launch the Gradio interface
demo_chatbot.launch(share=True)