Vo1dAbyss's picture
Update app.py
bec8cb8 verified
raw
history blame contribute delete
917 Bytes
import time
from transformers import pipeline, Conversation, GPT2LMHeadModel, AutoTokenizer
import gradio as gr
model_name = "ingen51/DialoGPT-medium-GPT4"
model = GPT2LMHeadModel.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side='left')
chatbot = pipeline(task="conversational", model = model, tokenizer = tokenizer)
past_user_inputs = []
generated_responses = []
def chocolate_ai(message, history):
conversation = Conversation(message, past_user_inputs = past_user_inputs, generated_responses = generated_responses)
conversation = chatbot(conversation)
past_user_inputs.append(message)
generated_responses.append(conversation.generated_responses[-1])
return conversation.generated_responses[-1]
gradio_interface = gr.ChatInterface(chocolate_ai, title="DialoGPT4-Chatbot", description="Type to start a conversation.")
gradio_interface.launch()