Spaces:
Paused
Paused
File size: 831 Bytes
258e5e7 f900ba5 4a9540b f900ba5 c742ff6 f900ba5 c742ff6 f900ba5 c742ff6 f900ba5 c742ff6 4a9540b f900ba5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import gradio as gr
from transformers import AutoModel, AutoProcessor
import torch
# Load model and processor
model_name = "adarsh3601/my_gemma3_pt"
model = AutoModel.from_pretrained(model_name)
processor = AutoProcessor.from_pretrained(model_name)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
# Define a function to handle the chat interface
def chat(messages):
inputs = processor(messages, return_tensors="pt").to(device)
outputs = model.generate(**inputs)
return processor.decode(outputs[0], skip_special_tokens=True)
# Create the Gradio interface
iface = gr.Interface(fn=chat,
inputs=gr.Textbox(label="Your Message", lines=7),
outputs=gr.Textbox(label="Response"),
live=True)
# Launch the app
iface.launch(debug=True)
|