Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| from PIL import Image | |
| # Load pretrained image classification pipeline | |
| classifier = pipeline( | |
| "image-classification", | |
| model="google/vit-base-patch16-224" | |
| ) | |
| def classify_image(image): | |
| results = classifier(image) | |
| return {r["label"]: float(r["score"]) for r in results} | |
| # Gradio interface | |
| demo = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Image(type="pil", label="Upload an animal image"), | |
| outputs=gr.Label(num_top_classes=5), | |
| title="Animal Image Classifier", | |
| description="Upload an image of an animal and see the predicted class.", | |
| examples=[ | |
| "animal_images/cat.jpg", | |
| "animal_images/dog.jpg", | |
| "animal_images/bird.jpg" | |
| ] | |
| ) | |
| demo.launch() | |