Spaces:
Running
on
Zero
Running
on
Zero
markany-yhkwon
commited on
Commit
·
88b7365
1
Parent(s):
fbd28e2
bug fix
Browse files
app.py
CHANGED
|
@@ -8,9 +8,6 @@ from PIL import Image
|
|
| 8 |
import numpy as np
|
| 9 |
from pathlib import Path
|
| 10 |
import gradio as gr
|
| 11 |
-
from gradio.inputs import Image as GradioImage
|
| 12 |
-
from gradio.outputs import Image as GradioOutputImage
|
| 13 |
-
from gradio.components import Textbox, Button, Slider
|
| 14 |
|
| 15 |
import warnings
|
| 16 |
|
|
@@ -88,6 +85,7 @@ if __name__ == "__main__":
|
|
| 88 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
| 89 |
parser.add_argument("--share", action="store_true", help="share the app")
|
| 90 |
args = parser.parse_args()
|
|
|
|
| 91 |
css = """
|
| 92 |
#mkd {
|
| 93 |
height: 500px;
|
|
@@ -95,32 +93,45 @@ if __name__ == "__main__":
|
|
| 95 |
border: 1px solid #ccc;
|
| 96 |
}
|
| 97 |
"""
|
| 98 |
-
|
| 99 |
-
block = gr.Blocks()
|
| 100 |
-
with block:
|
| 101 |
gr.Markdown("<h1><center>Grounding DINO<h1><center>")
|
| 102 |
gr.Markdown("<h3><center>Open-World Detection with <a href='https://github.com/IDEA-Research/GroundingDINO'>Grounding DINO</a><h3><center>")
|
| 103 |
gr.Markdown("<h3><center>Note the model runs on CPU, so it may take a while to run the model.<h3><center>")
|
| 104 |
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
| 107 |
-
input_image =
|
| 108 |
-
grounding_caption = Textbox("Detection Prompt")
|
| 109 |
-
run_button = Button("Run")
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
with gr.Column():
|
| 119 |
-
gallery =
|
|
|
|
| 120 |
type="pil"
|
| 121 |
-
)
|
| 122 |
|
| 123 |
-
run_button.click(
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import numpy as np
|
| 9 |
from pathlib import Path
|
| 10 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
import warnings
|
| 13 |
|
|
|
|
| 85 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
| 86 |
parser.add_argument("--share", action="store_true", help="share the app")
|
| 87 |
args = parser.parse_args()
|
| 88 |
+
|
| 89 |
css = """
|
| 90 |
#mkd {
|
| 91 |
height: 500px;
|
|
|
|
| 93 |
border: 1px solid #ccc;
|
| 94 |
}
|
| 95 |
"""
|
| 96 |
+
with gr.Blocks(css=css) as demo:
|
|
|
|
|
|
|
| 97 |
gr.Markdown("<h1><center>Grounding DINO<h1><center>")
|
| 98 |
gr.Markdown("<h3><center>Open-World Detection with <a href='https://github.com/IDEA-Research/GroundingDINO'>Grounding DINO</a><h3><center>")
|
| 99 |
gr.Markdown("<h3><center>Note the model runs on CPU, so it may take a while to run the model.<h3><center>")
|
| 100 |
|
| 101 |
with gr.Row():
|
| 102 |
with gr.Column():
|
| 103 |
+
input_image = gr.Image(label="Input Image")
|
| 104 |
+
grounding_caption = gr.Textbox(label="Detection Prompt")
|
| 105 |
+
run_button = gr.Button("Run")
|
| 106 |
+
|
| 107 |
+
with gr.Accordion("Advanced options", open=False):
|
| 108 |
+
box_threshold = gr.Slider(
|
| 109 |
+
minimum=0.0, maximum=1.0, value=0.25, step=0.001,
|
| 110 |
+
label="Box Threshold"
|
| 111 |
+
)
|
| 112 |
+
text_threshold = gr.Slider(
|
| 113 |
+
minimum=0.0, maximum=1.0, value=0.25, step=0.001,
|
| 114 |
+
label="Text Threshold"
|
| 115 |
+
)
|
| 116 |
|
| 117 |
with gr.Column():
|
| 118 |
+
gallery = gr.Image(
|
| 119 |
+
label="Detection Result",
|
| 120 |
type="pil"
|
| 121 |
+
)
|
| 122 |
|
| 123 |
+
run_button.click(
|
| 124 |
+
fn=run_grounding,
|
| 125 |
+
inputs=[input_image, grounding_caption, box_threshold, text_threshold],
|
| 126 |
+
outputs=[gallery]
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
gr.Examples(
|
| 130 |
+
examples=[["this_is_fine.png", "coffee cup", 0.25, 0.25]],
|
| 131 |
+
inputs=[input_image, grounding_caption, box_threshold, text_threshold],
|
| 132 |
+
outputs=[gallery],
|
| 133 |
+
fn=run_grounding,
|
| 134 |
+
cache_examples=True,
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
demo.launch(share=args.share, debug=args.debug, show_error=True)
|