Update app.py
Browse filesTrying to simplify the output
app.py
CHANGED
@@ -86,7 +86,14 @@ def detect_objects(model_name,url_input,image_input,threshold):
|
|
86 |
|
87 |
# return [viz_img, processed_outputs]
|
88 |
# print(type(viz_img))
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
def set_example_image(example: list) -> dict:
|
92 |
return gr.Image.update(value=example[0])
|
@@ -154,6 +161,7 @@ with demo:
|
|
154 |
img_but = gr.Button('Detect')
|
155 |
|
156 |
output_text1 = gr.outputs.Textbox(label="Confidence Values")
|
|
|
157 |
|
158 |
url_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=[img_output_from_url, output_text1],queue=True)
|
159 |
img_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=[img_output_from_upload, output_text1],queue=True)
|
|
|
86 |
|
87 |
# return [viz_img, processed_outputs]
|
88 |
# print(type(viz_img))
|
89 |
+
|
90 |
+
final_str = ""
|
91 |
+
for score, label, box in zip(processed_outputs["scores"], processed_outputs["labels"], processed_outputs["boxes"]):
|
92 |
+
box = [round(i, 2) for i in box.tolist()]
|
93 |
+
final_str += f"Detected {model.config.id2label[label.item()]} with confidence {score.item(), 3} at location {box}"
|
94 |
+
|
95 |
+
|
96 |
+
return viz_img, final_str
|
97 |
|
98 |
def set_example_image(example: list) -> dict:
|
99 |
return gr.Image.update(value=example[0])
|
|
|
161 |
img_but = gr.Button('Detect')
|
162 |
|
163 |
output_text1 = gr.outputs.Textbox(label="Confidence Values")
|
164 |
+
# https://huggingface.co/spaces/vishnun/CLIPnCROP/blob/main/app.py -- Got .outputs. from this
|
165 |
|
166 |
url_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=[img_output_from_url, output_text1],queue=True)
|
167 |
img_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=[img_output_from_upload, output_text1],queue=True)
|