Spaces:
Sleeping
Sleeping
File size: 1,458 Bytes
ec1e168 eeec6c9 ec1e168 eeec6c9 ec1e168 69e4902 ec1e168 69e4902 ec1e168 eeec6c9 ec1e168 eeec6c9 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
from transformers import pipeline
vit_classifier = pipeline("image-classification", model="MichaelMM2000/vit-base-animals10")
clip_detector = pipeline(model="openai/clip-vit-base-patch32", task="zero-shot-image-classification")
# Animals-10 class names
labels_animals10 = [
"butterfly", "cat", "chicken", "cow", "dog",
"elephant", "horse", "sheep", "spider", "squirrel"
]
def classify_animal(image):
vit_results = vit_classifier(image)
vit_output = {str(result['label']): float(result['score']) for result in vit_results}
clip_results = clip_detector(image, candidate_labels=[f"a photo of a {label}" for label in labels_animals10])
clip_output = {str(result['label']): float(result['score']) for result in clip_results}
return {
"ViT Classification": vit_output,
"CLIP Zero-Shot Classification": clip_output
}
# Optional: you can add example images
example_images = [
"example_images/cat.jpeg",
"example_images/chicken1.jpeg",
"example_images/chicken2.jpeg",
"example_images/elefant.jpg",
"example_images/butterfly.jpg"
]
iface = gr.Interface(
fn=classify_animal,
inputs=gr.Image(type="filepath"),
outputs=gr.JSON(),
title="Animals-10 Classification: ViT vs CLIP",
description="Upload an animal image to compare predictions from your trained ViT model and a zero-shot CLIP model.",
examples=example_images
)
iface.launch(ssr_mode=False) |