gradio / app.py
teaevo's picture
Update app.py
abad0fd
raw
history blame
950 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
def chatbot_response(user_message):
model_name = "gpt2" # You can change this to any other model from the list above
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
inputs = tokenizer.encode("User: " + user_message, return_tensors="pt")
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
# Define the chatbot interface using Gradio
iface = gr.Interface(
fn=chatbot_response,
inputs=gr.Textbox(prompt="You:"),
outputs=gr.Textbox(),
live=True,
capture_session=True,
title="Chatbot",
description="Type your message in the box above, and the chatbot will respond.",
)
# Launch the Gradio interface
if __name__ == "__main__":
iface.launch()