File size: 1,211 Bytes
3d7b150
2519508
3d7b150
 
2519508
3d7b150
 
2519508
 
 
3d7b150
2519508
3d7b150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2519508
3d7b150
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)