maceythm commited on
Commit
04996a9
·
verified ·
1 Parent(s): cb7711a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ vit_classifier = pipeline("image-classification", model="dein-nutzername/vit-90-animals")
5
+ clip_detector = pipeline(model="openai/clip-vit-large-patch14", task="zero-shot-image-classification")
6
+
7
+ labels_animals = [
8
+ 'antelope', 'badger', 'bat', 'bear', 'bee', 'beetle', 'bison', 'boar', 'butterfly', 'cat', 'caterpillar',
9
+ 'chimpanzee', 'cockroach', 'cow', 'coyote', 'crab', 'crow', 'deer', 'dog', 'dolphin', 'donkey',
10
+ 'dragonfly', 'duck', 'eagle', 'elephant', 'flamingo', 'fly', 'fox', 'goat', 'goldfish', 'goose',
11
+ 'gorilla', 'grasshopper', 'hamster', 'hare', 'hedgehog', 'hippopotamus', 'hornbill', 'horse',
12
+ 'hummingbird', 'hyena', 'jellyfish', 'kangaroo', 'koala', 'ladybugs', 'leopard', 'lion', 'lizard',
13
+ 'lobster', 'mosquito', 'moth', 'mouse', 'octopus', 'okapi', 'orangutan', 'otter', 'owl', 'ox',
14
+ 'oyster', 'panda', 'parrot', 'pelecaniformes', 'penguin', 'pig', 'pigeon', 'porcupine', 'possum',
15
+ 'raccoon', 'rat', 'reindeer', 'rhinoceros', 'sandpiper', 'seahorse', 'seal', 'shark', 'sheep',
16
+ 'snake', 'sparrow', 'squid', 'squirrel', 'starfish', 'swan', 'tiger', 'turkey', 'turtle', 'whale',
17
+ 'wolf', 'wombat', 'woodpecker', 'zebra'
18
+ ]
19
+
20
+ def classify_animal(image):
21
+ vit_results = vit_classifier(image)
22
+ vit_output = {result['label']: round(result['score'], 3) for result in vit_results}
23
+
24
+ clip_results = clip_detector(image, candidate_labels=labels_animals)
25
+ clip_output = {result['label']: round(result['score'], 3) for result in clip_results}
26
+
27
+ return {
28
+ "ViT Fine-Tuned": vit_output,
29
+ "CLIP Zero-Shot": clip_output
30
+ }
31
+ example_images = [
32
+ ["example_images/lion.jpg"],
33
+ ["example_images/bee.jpg"],
34
+ ["example_images/dog.jpg"]
35
+ ]
36
+
37
+ iface = gr.Interface(
38
+ fn=classify_animal,
39
+ inputs=gr.Image(type="filepath"),
40
+ outputs=gr.JSON(),
41
+ title="Animal Classification Comparison",
42
+ description="Upload an image of an animal and compare predictions between a fine-tuned ViT model and a zero-shot CLIP model.",
43
+ examples=example_images
44
+ )
45
+
46
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
4
+ kagglehub
5
+ datasets