CatGPT / app.py
SusiePHaltmann's picture
Update app.py
b087f1f verified
raw
history blame
1.19 kB
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the model and tokenizer
model_name = "CatGPT" # Replace with the exact model name if necessary
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define the chat function
def chat(input_text):
try:
# Tokenize the input
inputs = tokenizer(input_text, return_tensors="pt")
# Generate a response from the model
outputs = model.generate(**inputs, max_length=150)
# Decode and return the response
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
except Exception as e:
return f"An error occurred: {str(e)}"
# Create the Gradio interface
iface = gr.Interface(fn=chat,
inputs=gr.inputs.Textbox(lines=7, label="Enter your message"),
outputs=gr.outputs.Textbox(label="Response"),
title="CatGPT - Chatbot",
description="Chat with CatGPT, a fun and intelligent chatbot!")
# Launch the interface
if __name__ == "__main__":
iface.launch()