Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- .gitattributes +7 -0
- animal_images/animal_images/cat.png +3 -0
- animal_images/animal_images/frog.png +3 -0
- animal_images/animal_images/hippo.png +3 -0
- animal_images/animal_images/jaguar.png +3 -0
- animal_images/animal_images/sloth.png +3 -0
- animal_images/animal_images/toucan.png +3 -0
- animal_images/animal_images/turtle.png +3 -0
- app.py +43 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
animal_images/animal_images/cat.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
animal_images/animal_images/frog.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
animal_images/animal_images/hippo.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
animal_images/animal_images/jaguar.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
animal_images/animal_images/sloth.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
animal_images/animal_images/toucan.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
animal_images/animal_images/turtle.png filter=lfs diff=lfs merge=lfs -text
|
animal_images/animal_images/cat.png
ADDED
|
Git LFS Details
|
animal_images/animal_images/frog.png
ADDED
|
Git LFS Details
|
animal_images/animal_images/hippo.png
ADDED
|
Git LFS Details
|
animal_images/animal_images/jaguar.png
ADDED
|
Git LFS Details
|
animal_images/animal_images/sloth.png
ADDED
|
Git LFS Details
|
animal_images/animal_images/toucan.png
ADDED
|
Git LFS Details
|
animal_images/animal_images/turtle.png
ADDED
|
Git LFS Details
|
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the image classification pipeline with the Google ViT model
|
| 5 |
+
# This model is trained on ImageNet-1k and works well for general animal classification
|
| 6 |
+
classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 7 |
+
|
| 8 |
+
def classify_image(image):
|
| 9 |
+
"""
|
| 10 |
+
Takes an image, runs it through the classifier, and returns the top predictions.
|
| 11 |
+
"""
|
| 12 |
+
if image is None:
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
predictions = classifier(image)
|
| 16 |
+
# Gradio's Label component expects a dictionary of {label: confidence}
|
| 17 |
+
return {p["label"]: p["score"] for p in predictions}
|
| 18 |
+
|
| 19 |
+
# List of example images located in the nested animal_images folder
|
| 20 |
+
# Note: Based on your folder structure, the images are in 'animal_images/animal_images/'
|
| 21 |
+
examples = [
|
| 22 |
+
["animal_images/animal_images/cat.png"],
|
| 23 |
+
["animal_images/animal_images/frog.png"],
|
| 24 |
+
["animal_images/animal_images/hippo.png"],
|
| 25 |
+
["animal_images/animal_images/jaguar.png"],
|
| 26 |
+
["animal_images/animal_images/sloth.png"],
|
| 27 |
+
["animal_images/animal_images/toucan.png"],
|
| 28 |
+
["animal_images/animal_images/turtle.png"]
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
# Create the Gradio Interface
|
| 32 |
+
# We map the inputs and outputs to match the labels seen in your screenshot ("inp", "output")
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=classify_image,
|
| 35 |
+
inputs=gr.Image(type="pil", label="inp"),
|
| 36 |
+
outputs=gr.Label(num_top_classes=3, label="output"),
|
| 37 |
+
examples=examples,
|
| 38 |
+
title="Animal Classifier",
|
| 39 |
+
description="Upload an image of an animal to classify it using the Google ViT model."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
demo.launch()
|