Update app.py
Browse files
app.py
CHANGED
|
@@ -53,7 +53,7 @@ def visualize_prediction(pil_img, output_dict, threshold=0.5, id2label=None):
|
|
| 53 |
plt.axis("off")
|
| 54 |
return fig2img(plt.gcf())
|
| 55 |
|
| 56 |
-
def detect_objects(model_name,url_input,image_input,threshold):
|
| 57 |
|
| 58 |
#Extract model and feature extractor
|
| 59 |
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
|
@@ -65,6 +65,9 @@ def detect_objects(model_name,url_input,image_input,threshold):
|
|
| 65 |
|
| 66 |
elif image_input:
|
| 67 |
image = image_input
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
#Make prediction
|
| 70 |
processed_outputs = make_prediction(image, feature_extractor, model)
|
|
@@ -139,10 +142,17 @@ with demo:
|
|
| 139 |
|
| 140 |
|
| 141 |
img_but = gr.Button('Detect')
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
|
| 147 |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
|
| 148 |
|
|
|
|
| 53 |
plt.axis("off")
|
| 54 |
return fig2img(plt.gcf())
|
| 55 |
|
| 56 |
+
def detect_objects(model_name,url_input,image_input,webcam_input,threshold):
|
| 57 |
|
| 58 |
#Extract model and feature extractor
|
| 59 |
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
|
|
|
| 65 |
|
| 66 |
elif image_input:
|
| 67 |
image = image_input
|
| 68 |
+
|
| 69 |
+
elif webcam_input:
|
| 70 |
+
image = webcam_input
|
| 71 |
|
| 72 |
#Make prediction
|
| 73 |
processed_outputs = make_prediction(image, feature_extractor, model)
|
|
|
|
| 142 |
|
| 143 |
|
| 144 |
img_but = gr.Button('Detect')
|
| 145 |
+
|
| 146 |
+
with gr.TabItem('WebCam'):
|
| 147 |
+
with gr.Row():
|
| 148 |
+
web_input = gr.Image(source='webcam',type='pil',shape=(750,750))
|
| 149 |
+
img_output_from_webcam= gr.Image(shape=(750,750))
|
| 150 |
+
|
| 151 |
+
cam_but = gr.Button('Detect')
|
| 152 |
+
|
| 153 |
+
url_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=img_output_from_url,queue=True)
|
| 154 |
+
img_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=img_output_from_upload,queue=True)
|
| 155 |
+
cam_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=img_output_from_webcam,queue=True)
|
| 156 |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
|
| 157 |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
|
| 158 |
|