Update app.py
Browse files
app.py
CHANGED
@@ -62,6 +62,12 @@ def detect_objects(model_name,url_input,image_input,webcam_input,threshold):
|
|
62 |
|
63 |
if validators.url(url_input):
|
64 |
image = Image.open(requests.get(url_input, stream=True).raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
elif image_input:
|
67 |
image = image_input
|
@@ -75,7 +81,7 @@ def detect_objects(model_name,url_input,image_input,webcam_input,threshold):
|
|
75 |
#Visualize prediction
|
76 |
viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
|
77 |
|
78 |
-
return viz_img,
|
79 |
|
80 |
def set_example_image(example: list) -> dict:
|
81 |
return gr.Image.update(value=example[0])
|
@@ -153,9 +159,9 @@ with demo:
|
|
153 |
|
154 |
cam_but = gr.Button('Detect')
|
155 |
|
156 |
-
url_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_url,
|
157 |
-
img_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_upload,
|
158 |
-
cam_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_webcam,
|
159 |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
|
160 |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
|
161 |
|
|
|
62 |
|
63 |
if validators.url(url_input):
|
64 |
image = Image.open(requests.get(url_input, stream=True).raw)
|
65 |
+
#Make prediction
|
66 |
+
processed_outputs = make_prediction(image, feature_extractor, model)
|
67 |
+
#Visualize prediction
|
68 |
+
viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
|
69 |
+
|
70 |
+
return viz_img, image
|
71 |
|
72 |
elif image_input:
|
73 |
image = image_input
|
|
|
81 |
#Visualize prediction
|
82 |
viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
|
83 |
|
84 |
+
return viz_img, None
|
85 |
|
86 |
def set_example_image(example: list) -> dict:
|
87 |
return gr.Image.update(value=example[0])
|
|
|
159 |
|
160 |
cam_but = gr.Button('Detect')
|
161 |
|
162 |
+
url_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_url,original_image],queue=True)
|
163 |
+
img_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_upload,original_image],queue=True)
|
164 |
+
cam_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_webcam,original_image],queue=True)
|
165 |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
|
166 |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
|
167 |
|