Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,21 +18,6 @@ COLORS = [
|
|
18 |
[0.301, 0.745, 0.933]
|
19 |
]
|
20 |
|
21 |
-
title = 'Object Detection App with DETR and YOLOS'
|
22 |
-
|
23 |
-
description = """
|
24 |
-
Links to HuggingFace Models:
|
25 |
-
|
26 |
-
- [facebook/detr-resnet-50](https://huggingface.co/facebook/detr-resnet-50)
|
27 |
-
- [facebook/detr-resnet-101](https://huggingface.co/facebook/detr-resnet-101)
|
28 |
-
- [hustvl/yolos-small](https://huggingface.co/hustvl/yolos-small)
|
29 |
-
|
30 |
-
"""
|
31 |
-
|
32 |
-
models = ["facebook/detr-resnet-50","facebook/detr-resnet-101",'hustvl/yolos-small']
|
33 |
-
|
34 |
-
options = gr.Dropdown(choices=models,label='Select Object Detection Model',show_label=True)
|
35 |
-
|
36 |
def make_prediction(img, feature_extractor, model):
|
37 |
inputs = feature_extractor(img, return_tensors="pt")
|
38 |
outputs = model(**inputs)
|
@@ -95,13 +80,47 @@ def detect_objects(model_name,url,image_upload,threshold):
|
|
95 |
examples=[['facebook/detr-resnet-50','https://media-cldnry.s-nbcnews.com/image/upload/t_fit-1500w,f_auto,q_auto:best/newscms/2020_14/3290756/200331-wall-street-ew-343p.jpg',,0.7],
|
96 |
['facebook/detr-resnet-50',,'IMG_5205.JPG',0.7]]
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
[0.301, 0.745, 0.933]
|
19 |
]
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def make_prediction(img, feature_extractor, model):
|
22 |
inputs = feature_extractor(img, return_tensors="pt")
|
23 |
outputs = model(**inputs)
|
|
|
80 |
examples=[['facebook/detr-resnet-50','https://media-cldnry.s-nbcnews.com/image/upload/t_fit-1500w,f_auto,q_auto:best/newscms/2020_14/3290756/200331-wall-street-ew-343p.jpg',,0.7],
|
81 |
['facebook/detr-resnet-50',,'IMG_5205.JPG',0.7]]
|
82 |
|
83 |
+
title = 'Object Detection App with DETR and YOLOS'
|
84 |
+
|
85 |
+
description = """
|
86 |
+
Links to HuggingFace Models:
|
87 |
+
|
88 |
+
- [facebook/detr-resnet-50](https://huggingface.co/facebook/detr-resnet-50)
|
89 |
+
- [facebook/detr-resnet-101](https://huggingface.co/facebook/detr-resnet-101)
|
90 |
+
- [hustvl/yolos-small](https://huggingface.co/hustvl/yolos-small)
|
91 |
+
|
92 |
+
"""
|
93 |
+
|
94 |
+
models = ["facebook/detr-resnet-50","facebook/detr-resnet-101",'hustvl/yolos-small']
|
95 |
+
|
96 |
+
options = gr.Dropdown(choices=models,label='Select Object Detection Model',show_label=True)
|
97 |
+
|
98 |
+
app = gr.blocks()
|
99 |
+
|
100 |
+
with app:
|
101 |
+
gr.Markdown(title)
|
102 |
+
gr.Markdown(description)
|
103 |
+
options
|
104 |
+
slider_input = gr.Slider(minimum=0.2,maximum=1,value=0.7,label='Prediction Threshold')
|
105 |
+
|
106 |
+
with gr.Tabs():
|
107 |
+
with gr.Tabitem('Image URL'):
|
108 |
+
with gr.Row():
|
109 |
+
url_input = gr.Textbox(lines=1,label='Enter valid image URL here..')
|
110 |
+
img_output_from_url = gr.Image(shape=(450,450))
|
111 |
+
|
112 |
+
url_but = gr.Button('Detect')
|
113 |
+
|
114 |
+
with gr.Tabitem('Image Upload):
|
115 |
+
with gr.Row():
|
116 |
+
img_input = gr.Image(type='pil')
|
117 |
+
img_output_from_upload= gr.Image(shape=(450,450))
|
118 |
+
|
119 |
+
img_but = gr.Button('Detect')
|
120 |
+
|
121 |
+
|
122 |
+
url_but.click(detect_objects,inputs=[options,url_input,None,slider_input],outputs=img_output_from_url,queue=True)
|
123 |
+
img_but.click(detect_objects,inputs=[options,None,img_input,slider_input],outputsimg_output_from_upload,queue=True)
|
124 |
+
|
125 |
+
|
126 |
+
app.launch(enable_queue=True)
|