shelbyallyssa commited on
Commit
91c9732
·
verified ·
1 Parent(s): edf906e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+
5
+ # Load pretrained image classification pipeline
6
+ classifier = pipeline(
7
+ "image-classification",
8
+ model="google/vit-base-patch16-224"
9
+ )
10
+
11
+ def classify_image(image):
12
+ results = classifier(image)
13
+ return {r["label"]: float(r["score"]) for r in results}
14
+
15
+ # Gradio interface
16
+ demo = gr.Interface(
17
+ fn=classify_image,
18
+ inputs=gr.Image(type="pil", label="Upload an animal image"),
19
+ outputs=gr.Label(num_top_classes=5),
20
+ title="Animal Image Classifier",
21
+ description="Upload an image of an animal and see the predicted class.",
22
+ examples=[
23
+ "animal_images/cat.jpg",
24
+ "animal_images/dog.jpg",
25
+ "animal_images/bird.jpg"
26
+ ]
27
+ )
28
+
29
+ demo.launch()