Mohuu0601 commited on
Commit
b628b61
·
verified ·
1 Parent(s): 8ea7786

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a pre-trained image classification pipeline from Hugging Face
5
+ model = pipeline("image-classification", model="google/vit-base-patch16-224")
6
+
7
+ # Define the prediction function
8
+ def classify_image(image):
9
+ predictions = model(image)
10
+ return {pred["label"]: pred["score"] for pred in predictions}
11
+
12
+ # Set up the Gradio interface
13
+ interface = gr.Interface(
14
+ fn=classify_image,
15
+ inputs=gr.Image(type="pil"),
16
+ outputs=gr.Label(),
17
+ title="Image Classification App",
18
+ description="Upload an image, and the app will classify it using a Vision Transformer (ViT) model."
19
+ )
20
+
21
+ # Launch the app
22
+ if _name_ == "_main_":
23
+ interface.launch()