liuyizhang commited on
Commit
ca589ef
1 Parent(s): 6061d17

update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -180,7 +180,7 @@ def show_box(box, ax, label):
180
  ax.text(x0, y0, label)
181
 
182
 
183
- config_file = 'Grounding_DINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
184
  ckpt_repo_id = "ShilongLiu/GroundingDINO"
185
  ckpt_filenmae = "groundingdino_swint_ogc.pth"
186
  sam_checkpoint = './sam_vit_h_4b8939.pth'
@@ -281,6 +281,12 @@ def run_grounded_sam(image_path, text_prompt, task_type, inpaint_prompt, box_thr
281
  else:
282
  print("task_type:{} error!".format(task_type))
283
 
 
 
 
 
 
 
284
  if __name__ == "__main__":
285
 
286
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
@@ -295,9 +301,10 @@ if __name__ == "__main__":
295
  with gr.Row():
296
  with gr.Column():
297
  input_image = gr.Image(source='upload', type="pil")
298
- text_prompt = gr.Textbox(label="Detection Prompt")
299
- task_type = gr.Textbox(label="task type: det/seg/inpainting")
300
- inpaint_prompt = gr.Textbox(label="Inpaint Prompt")
 
301
  run_button = gr.Button(label="Run")
302
  with gr.Accordion("Advanced options", open=False):
303
  box_threshold = gr.Slider(
@@ -314,6 +321,6 @@ if __name__ == "__main__":
314
 
315
  run_button.click(fn=run_grounded_sam, inputs=[
316
  input_image, text_prompt, task_type, inpaint_prompt, box_threshold, text_threshold], outputs=[gallery])
 
317
 
318
- # block.launch(server_name='0.0.0.0', server_port=7589, debug=args.debug, share=args.share)
319
  block.launch(server_name='0.0.0.0', debug=args.debug, share=args.share)
 
180
  ax.text(x0, y0, label)
181
 
182
 
183
+ config_file = 'GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
184
  ckpt_repo_id = "ShilongLiu/GroundingDINO"
185
  ckpt_filenmae = "groundingdino_swint_ogc.pth"
186
  sam_checkpoint = './sam_vit_h_4b8939.pth'
 
281
  else:
282
  print("task_type:{} error!".format(task_type))
283
 
284
+ def change_task_type(task_type):
285
+ if task_type == "inpainting":
286
+ return gr.Textbox.update(visible=True)
287
+ else:
288
+ return gr.Textbox.update(visible=False)
289
+
290
  if __name__ == "__main__":
291
 
292
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
 
301
  with gr.Row():
302
  with gr.Column():
303
  input_image = gr.Image(source='upload', type="pil")
304
+ task_type = gr.Radio(["detection", "segment", "inpainting"], value="detection",
305
+ label='Task type:',interactive=True, visible=True)
306
+ text_prompt = gr.Textbox(label="Detection Prompt")
307
+ inpaint_prompt = gr.Textbox(label="Inpaint Prompt", visible=False)
308
  run_button = gr.Button(label="Run")
309
  with gr.Accordion("Advanced options", open=False):
310
  box_threshold = gr.Slider(
 
321
 
322
  run_button.click(fn=run_grounded_sam, inputs=[
323
  input_image, text_prompt, task_type, inpaint_prompt, box_threshold, text_threshold], outputs=[gallery])
324
+ task_type.change(fn=change_task_type, inputs=[task_type], outputs=[inpaint_prompt])
325
 
 
326
  block.launch(server_name='0.0.0.0', debug=args.debug, share=args.share)