manva-chatbot / app.py
manoharpatil's picture
update app.py
219d94a verified
raw
history blame contribute delete
766 Bytes
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()