Spaces:
Runtime error
Runtime error
File size: 766 Bytes
50d644a 219d94a 50d644a 219d94a 50d644a 219d94a 50d644a 219d94a 50d644a 219d94a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the model and tokenizer
model_name = "microsoft/DialoGPT-medium"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define the function to generate responses
def respond_to_input(user_input):
inputs = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors='pt')
reply_ids = model.generate(inputs, max_length=1000, pad_token_id=tokenizer.eos_token_id)
reply = tokenizer.decode(reply_ids[:, inputs.shape[-1]:][0], skip_special_tokens=True)
return reply
# Create the Gradio interface
iface = gr.Interface(fn=respond_to_input, inputs="text", outputs="text")
# Launch the app
iface.launch() |