Mohuu0601 commited on
Commit
5f1afc7
·
verified ·
1 Parent(s): b98f44c

Create app.py

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