import transformers import gradio as gr import torch from transformers import GPT2LMHeadModel, GPT2Tokenizer tokenizer = GPT2Tokenizer.from_pretrained('dennis-fast/DialoGPT-ElonMusk') model = GPT2LMHeadModel.from_pretrained('dennis-fast/DialoGPT-ElonMusk') def chat(message, token_response): token_message = tokenizer.encode(message + tokenizer.eos_token, return_tensors='pt') token_response = model.generate(token_message, max_length=1000, pad_token_id=tokenizer.eos_token_id) response = tokenizer.decode(token_response[:, token_message.shape[-1]:][0], skip_special_tokens=True) return response, token_response gr.Interface(fn=predict, title="Chat with Elon", theme="default", css=".footer {display:none !important}", allow_screenshot=False, allow_flagging='never' inputs=["User", "state"], outputs=["Elon", "state"]).launch()