afri-aya / app.py
KatoStevenMubiru's picture
Update app.py
3d16695 verified
import gradio as gr
from transformers import AutoProcessor, AutoModelForVision2Seq
import torch
# Load model
print("Loading Afri-Aya model...")
processor = AutoProcessor.from_pretrained("Bronsn/afri-aya-gemma-3-4b-vision")
model = AutoModelForVision2Seq.from_pretrained(
"Bronsn/afri-aya-gemma-3-4b-vision",
torch_dtype=torch.float16,
device_map="auto"
)
print("Model loaded successfully!")
def predict(image, question):
if image is None:
return "Please upload an image"
# Prepare input
inputs = processor(images=image, text=question, return_tensors="pt").to(model.device)
# Generate
output_ids = model.generate(**inputs, max_new_tokens=100)
# Decode
answer = processor.decode(output_ids[0], skip_special_tokens=True)
return answer
# Create interface
demo = gr.Interface(
fn=predict,
inputs=[
gr.Image(type="pil", label="Upload African Cultural Image"),
gr.Textbox(label="Ask a question", placeholder="What is shown in this image?")
],
outputs=gr.Textbox(label="Answer"),
title="🌍 Afri-Aya Vision Model",
description="Ask questions about African cultural images in multiple languages!"
)
demo.launch()