Kaustubh96 commited on
Commit
f66e527
·
verified ·
1 Parent(s): ba8e0ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -1,23 +1,25 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- # Load the pre-trained Image Classification pipeline
5
- classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
6
-
7
- def predict(image):
8
- # Get predictions from the model
9
- results = classifier(image)
10
- # Reformat for Gradio's Label component: {"Label": Score}
11
- return {res["label"]: res["score"] for res in results}
12
-
13
- # Define the Gradio Interface
14
- demo = gr.Interface(
15
- fn=predict,
16
- inputs=gr.Image(type="pil"),
17
- outputs=gr.Label(num_top_classes=3),
18
- title="AI Image Classifier",
19
- description="Upload any image to see what the Vision Transformer thinks it is!"
20
- )
21
-
22
- if __name__ == "__main__":
23
- demo.launch()
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained Image Classification pipeline
5
+ classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
6
+
7
+ def predict(image):
8
+ # Get predictions from the model
9
+ results = classifier(image)
10
+ # Reformat for Gradio's Label component: {"Label": Score}
11
+ return {res["label"]: res["score"] for res in results}
12
+
13
+ # Define the Gradio Interface
14
+ demo = gr.Interface(
15
+ fn=predict,
16
+ inputs=gr.Image(type="pil"),
17
+ outputs=gr.Label(num_top_classes=3),
18
+ title="AI Image Classifier",
19
+ description="Upload any image to see what the Vision Transformer thinks it is!"
20
+ )
21
+
22
+ if __name__ == "__main__":
23
+ demo.launch()
24
+
25
+