|
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration |
|
import gradio as gr |
|
|
|
|
|
model_name = "facebook/blenderbot-400M-distill" |
|
tokenizer = BlenderbotTokenizer.from_pretrained(model_name) |
|
model = BlenderbotForConditionalGeneration.from_pretrained(model_name) |
|
|
|
|
|
conversation_history = [] |
|
|
|
|
|
def vanilla_chatbot(message, history): |
|
global conversation_history |
|
|
|
|
|
conversation_history.append(message) |
|
|
|
|
|
inputs = tokenizer([message], return_tensors='pt') |
|
|
|
|
|
reply_ids = model.generate(**inputs) |
|
bot_response = tokenizer.batch_decode(reply_ids, skip_special_tokens=True)[0] |
|
|
|
|
|
conversation_history.append(bot_response) |
|
|
|
|
|
return bot_response |
|
|
|
|
|
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..."), |
|
title="Mashdemy Chatbot", |
|
description="Enter text to start chatting." |
|
) |
|
|
|
|
|
demo_chatbot.launch(share=True) |
|
|
|
|