markany-yhkwon commited on
Commit
88b7365
·
1 Parent(s): fbd28e2
Files changed (1) hide show
  1. app.py +33 -22
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
- # Using a simpler block creation method
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 = GradioImage(type="pil")
108
- grounding_caption = Textbox("Detection Prompt")
109
- run_button = Button("Run")
110
- # Advanced options in a collapsible section
111
- box_threshold = Slider(
112
- minimum=0.0, maximum=1.0, value=0.25, step=0.001, label="Box Threshold"
113
- )
114
- text_threshold = Slider(
115
- minimum=0.0, maximum=1.0, value=0.25, step=0.001, label="Text Threshold"
116
- )
 
 
 
117
 
118
  with gr.Column():
119
- gallery = GradioOutputImage(
 
120
  type="pil"
121
- ).scale(full_width=True)
122
 
123
- run_button.click(fn=run_grounding, inputs=[
124
- input_image, grounding_caption, box_threshold, text_threshold], outputs=[gallery])
125
- # Example setup removed - older versions may not support Examples component
126
- block.launch(share=False, show_api=False, show_error=True)
 
 
 
 
 
 
 
 
 
 
 
 
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)