WK3 / app_v4.py
Maria-tamu's picture
Upload 10 files
660cdb2 verified
import gradio as gr
from transformers import pipeline
# Load the image classification pipeline
classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
def predict(image):
if image is None:
return None
predictions = classifier(image)
return {p["label"]: p["score"] for p in predictions}
# Updated examples list to use cat.jpeg instead of cat.png
examples = [
"animal_images/hippo.png",
"animal_images/jaguar.png",
"animal_images/toucan.png",
"animal_images/sloth.png",
"animal_images/cat.jpeg", # Changed to jpeg
"animal_images/frog.png",
"animal_images/turtle.png"
]
demo = gr.Interface(
fn=predict,
inputs=gr.Image(
type="pil",
label="Input Image",
interactive=True,
height=None
),
outputs=gr.Label(num_top_classes=3, label="Predictions"),
examples=examples,
title="Animal Classifier",
description="Upload an image of an animal."
)
if __name__ == "__main__":
demo.launch()