Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
import torch | |
# Load the model and tokenizer | |
model_name = "google/gemma-2b-it" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
# Define the chatbot function | |
def chatbot(input_text): | |
inputs = tokenizer(input_text, return_tensors="pt") | |
outputs = model.generate(inputs.input_ids, max_length=100, num_return_sequences=1) | |
response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return response | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=chatbot, | |
inputs="text", | |
outputs="text", | |
title="AI Chatbot", | |
description="A chatbot using the google/gemma-2b-it model." | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
iface.launch() |