lruizap commited on
Commit
c331809
·
1 Parent(s): 67f555a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a pipeline as a high-level helper
2
+ import transformres
3
+ from transformers import pipeline
4
+ import gradio
5
+ import gradio as gr
6
+
7
+ image_processor = pipeline("image-classification", model="google/vit-base-patch16-224")
8
+
9
+ # Define a Gradio function for classification
10
+ def classify_image(image):
11
+ # Use the image_classification pipeline to classify the image
12
+ result = image_processor(image)
13
+ # Return the class label and confidence score
14
+ return result[0]["label"], round(result[0]["score"], 4)
15
+
16
+ # Create a Gradio interface
17
+ interface = gr.Interface(
18
+ fn=classify_image,
19
+ inputs=gr.Image(type="pil"),
20
+ outputs="text",
21
+ live=True,
22
+ title="Image Classification",
23
+ )
24
+
25
+ # Start the Gradio interface
26
+ interface.launch()