Shangkhonil commited on
Commit
1ab6be2
·
verified ·
1 Parent(s): a6aae9b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the object detection pipeline with the microsoft/table-transformer-detection model
5
+ pipe = pipeline("object-detection", model="microsoft/table-transformer-detection")
6
+
7
+ # Define the function to detect objects in an image
8
+ def detect_objects(image):
9
+ result = pipe(image)
10
+ # Format the result to show detected objects and their scores
11
+ detections = [{"label": item["label"], "score": item["score"], "box": item["box"]} for item in result]
12
+ return detections
13
+
14
+ # Set up the Gradio interface
15
+ app = gr.Interface(
16
+ fn=detect_objects, # Function for object detection
17
+ inputs=gr.Image(type="filepath"), # Input field to upload an image
18
+ outputs=gr.JSON(), # Output field for detected objects (JSON format)
19
+ title="Object Detection", # Title of the app
20
+ description="Upload an image to detect objects using Microsoft's Table Transformer model."
21
+ )
22
+
23
+ # Launch the app
24
+ if __name__ == "__main__":
25
+ app.launch()