Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,12 +47,40 @@ def predict(image):
|
|
| 47 |
except Exception as e:
|
| 48 |
return str(e)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
except Exception as e:
|
| 48 |
return str(e)
|
| 49 |
|
| 50 |
+
with gr.Blocks(title="MASFNet Object Detection",
|
| 51 |
+
css=".gradio-container {background:lightyellow;}"
|
| 52 |
+
) as demo:
|
| 53 |
+
#sample_index = gr.State([])
|
| 54 |
+
|
| 55 |
+
gr.HTML("""<div style="font-family:'Times New Roman', 'Serif'; font-size:16pt; font-weight:bold; text-align:center; color:royalblue;">MASFNet Object Detection</div>""")
|
| 56 |
+
|
| 57 |
+
gr.HTML("""<br/>""")
|
| 58 |
+
gr.HTML("""<h4 style="color:navy;">a. Select an example by clicking a thumbnail below.</h4>""")
|
| 59 |
+
gr.HTML("""<h4 style="color:navy;">b. Or upload an image by clicking on the canvas.</h4>""")
|
| 60 |
+
|
| 61 |
+
with gr.Row():
|
| 62 |
+
input_image = gr.Image(label="Input image", type="pil")
|
| 63 |
+
output_image = gr.Image(label="Output image with predicted instances", type="pil")
|
| 64 |
+
|
| 65 |
+
gr.Examples(['img/1.png', 'img/2.png'], inputs=input_image)
|
| 66 |
+
|
| 67 |
+
gr.HTML("""<br/>""")
|
| 68 |
+
gr.HTML("""<h4 style="color:navy;">3. Set a threshold value (default to 0.9)</h4>""")
|
| 69 |
+
|
| 70 |
+
# threshold = gr.Slider(0, 1.0, value=0.9, label='threshold')
|
| 71 |
+
|
| 72 |
+
gr.HTML("""<br/>""")
|
| 73 |
+
gr.HTML("""<h4 style="color:navy;">4. Then, click "Infer" button to predict object instances. It will take about 10 seconds (yolos-tiny) or 20 seconds (yolos-small).</h4>""")
|
| 74 |
+
|
| 75 |
+
send_btn = gr.Button("Infer")
|
| 76 |
+
send_btn.click(fn=infer, inputs=[input_image], outputs=[output_image])
|
| 77 |
+
|
| 78 |
+
gr.HTML("""<br/>""")
|
| 79 |
+
gr.HTML("""<h4 style="color:navy;">Reference</h4>""")
|
| 80 |
+
gr.HTML("""<ul>""")
|
| 81 |
+
gr.HTML("""<li><a href="https://huggingface.co/docs/transformers/model_doc/yolos" target="_blank">Hugging Face Transformers - YOLOS</a>""")
|
| 82 |
+
gr.HTML("""</ul>""")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
#demo.queue()
|
| 86 |
+
demo.launch(debug=True)
|