Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a pre-trained image classification model 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
+ # Gradio Interface
13
+ demo = gr.Interface(
14
+ fn=classify_image,
15
+ inputs=gr.Image(type="pil"),
16
+ outputs=gr.Label(num_top_classes=5),
17
+ title="Image Recognition AI",
18
+ description="Upload an image to classify it using a pre-trained model from Hugging Face."
19
+ )
20
+
21
+ # Launch the app
22
+ demo.launch()