hudaakram commited on
Commit
c00b118
·
verified ·
1 Parent(s): 87e7edc

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +2 -12
  2. app.py +21 -0
  3. requirements.txt +6 -0
README.md CHANGED
@@ -1,12 +1,2 @@
1
- ---
2
- title: Vit Image Classification
3
- emoji: 🐠
4
- colorFrom: green
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.45.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # ViT Image Classification
2
+ Uses google/vit-base-patch16-224.
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ clf = pipeline("image-classification",
6
+ model="google/vit-base-patch16-224",
7
+ device_map="auto")
8
+
9
+ def predict(img):
10
+ out = clf(img)[:5]
11
+ return {o['label']: float(o['score']) for o in out}
12
+
13
+ demo = gr.Interface(
14
+ fn=predict,
15
+ inputs=gr.Image(type="pil"),
16
+ outputs=gr.Label(num_top_classes=5),
17
+ title="Image Classification (ViT)"
18
+ )
19
+
20
+ if __name__ == "__main__":
21
+ demo.launch(share=True) # share=True gives you a temporary Colab link
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio>=4.44.0
2
+ transformers>=4.43.0
3
+ accelerate>=0.33.0
4
+ sentencepiece
5
+ safetensors
6
+ torch