liuyizhang commited on
Commit
1c6fec7
1 Parent(s): 4962329

update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -481,9 +481,6 @@ mask_source_segment = "type what to detect below"
481
 
482
  def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_threshold, text_threshold,
483
  iou_threshold, inpaint_mode, mask_source_radio, remove_mode, remove_mask_extend, num_relation):
484
- if task_type == "relate anything":
485
- return relate_anything(input_image['image'], num_relation)
486
-
487
  text_prompt = text_prompt.strip()
488
  if not ((task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_draw):
489
  if text_prompt == '':
@@ -664,13 +661,13 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
664
  logger.info(f'run_anything_task_[{file_temp}]_9_9_')
665
  return output_images, gr.Gallery.update(label='result images')
666
 
667
- def change_radio_display(task_type, mask_source_radio, num_relation): #, gsa_gallery, ram_gallery):
668
  text_prompt_visible = True
669
  inpaint_prompt_visible = False
670
  mask_source_radio_visible = False
671
  num_relation_visible = False
672
- # gsa_gallery_visible = True
673
- # ram_gallery_visible = False
674
  if task_type == "inpainting":
675
  inpaint_prompt_visible = True
676
  if task_type == "inpainting" or task_type == "remove":
@@ -680,10 +677,9 @@ def change_radio_display(task_type, mask_source_radio, num_relation): #, gsa_gal
680
  if task_type == "relate anything":
681
  text_prompt_visible = False
682
  num_relation_visible = True
683
- # gsa_gallery_visible = False
684
- # ram_gallery_visible = True
685
- return gr.Textbox.update(visible=text_prompt_visible), gr.Textbox.update(visible=inpaint_prompt_visible), gr.Radio.update(visible=mask_source_radio_visible), gr.Slider.update(visible=num_relation_visible)
686
- # gr.Gallery.update(visible=gsa_gallery_visible), gr.Gallery.update(visible=ram_gallery_visible)
687
 
688
  if __name__ == "__main__":
689
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
@@ -706,7 +702,8 @@ if __name__ == "__main__":
706
  text_prompt = gr.Textbox(label="Detection Prompt[To detect multiple objects, seperating each name with '.', like this: cat . dog . chair ]", placeholder="Cannot be empty")
707
  inpaint_prompt = gr.Textbox(label="Inpaint Prompt (if this is empty, then remove)", visible=False)
708
  num_relation = gr.Slider(label="How many relations do you want to see", minimum=1, maximum=20, value=5, step=1, visible=False)
709
- run_button = gr.Button(label="Run")
 
710
  with gr.Accordion("Advanced options", open=False) as advanced_options:
711
  box_threshold = gr.Slider(
712
  label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.001
@@ -725,16 +722,15 @@ if __name__ == "__main__":
725
  remove_mask_extend = gr.Textbox(label="remove_mask_extend", value='10')
726
 
727
  with gr.Column():
728
- # gsa_gallery = gr.Gallery(
729
- # label="result images", show_label=True, elem_id="gsa_gallery"
730
- # ).style(grid=[2], full_width=True, full_height=True)
731
  gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery"
732
  ).style(preview=True, columns=5, object_fit="scale-down", full_width=True, full_height=True)
733
 
734
  run_button.click(fn=run_anything_task, inputs=[
735
- input_image, text_prompt, task_type, inpaint_prompt, box_threshold, text_threshold, iou_threshold, inpaint_mode, mask_source_radio, remove_mode, remove_mask_extend, num_relation], outputs=[gallery, gallery])
736
- task_type.change(fn=change_radio_display, inputs=[task_type, mask_source_radio], outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation])
737
- mask_source_radio.change(fn=change_radio_display, inputs=[task_type, mask_source_radio], outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation])
 
 
738
 
739
  DESCRIPTION = '### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
740
  DESCRIPTION += 'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
 
481
 
482
  def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_threshold, text_threshold,
483
  iou_threshold, inpaint_mode, mask_source_radio, remove_mode, remove_mask_extend, num_relation):
 
 
 
484
  text_prompt = text_prompt.strip()
485
  if not ((task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_draw):
486
  if text_prompt == '':
 
661
  logger.info(f'run_anything_task_[{file_temp}]_9_9_')
662
  return output_images, gr.Gallery.update(label='result images')
663
 
664
+ def change_radio_display(task_type, mask_source_radio, num_relation, run_button, relate_all_button):
665
  text_prompt_visible = True
666
  inpaint_prompt_visible = False
667
  mask_source_radio_visible = False
668
  num_relation_visible = False
669
+ run_button_visible = True
670
+ relate_all_button_visible = False
671
  if task_type == "inpainting":
672
  inpaint_prompt_visible = True
673
  if task_type == "inpainting" or task_type == "remove":
 
677
  if task_type == "relate anything":
678
  text_prompt_visible = False
679
  num_relation_visible = True
680
+ run_button_visible = False
681
+ relate_all_button_visible = True
682
+ return gr.Textbox.update(visible=text_prompt_visible), gr.Textbox.update(visible=inpaint_prompt_visible), gr.Radio.update(visible=mask_source_radio_visible), gr.Slider.update(visible=num_relation_visible), gr.Button.update(visible=run_button_visible), gr.Button.update(visible=relate_all_button_visible)
 
683
 
684
  if __name__ == "__main__":
685
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
 
702
  text_prompt = gr.Textbox(label="Detection Prompt[To detect multiple objects, seperating each name with '.', like this: cat . dog . chair ]", placeholder="Cannot be empty")
703
  inpaint_prompt = gr.Textbox(label="Inpaint Prompt (if this is empty, then remove)", visible=False)
704
  num_relation = gr.Slider(label="How many relations do you want to see", minimum=1, maximum=20, value=5, step=1, visible=False)
705
+ run_button = gr.Button(label="Run", visible=True)
706
+ relate_all_button = gr.Button(label="Run", visible=False)
707
  with gr.Accordion("Advanced options", open=False) as advanced_options:
708
  box_threshold = gr.Slider(
709
  label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.001
 
722
  remove_mask_extend = gr.Textbox(label="remove_mask_extend", value='10')
723
 
724
  with gr.Column():
 
 
 
725
  gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery"
726
  ).style(preview=True, columns=5, object_fit="scale-down", full_width=True, full_height=True)
727
 
728
  run_button.click(fn=run_anything_task, inputs=[
729
+ input_image, text_prompt, task_type, inpaint_prompt, box_threshold, text_threshold, iou_threshold, inpaint_mode, mask_source_radio, remove_mode, remove_mask_extend, num_relation], outputs=[gallery, gallery], show_progress=True, queue=True)
730
+ relate_all_button.click(fn=relate_anything, inputs=[input_image, num_relation], outputs=[gallery], show_progress=True, queue=True)
731
+
732
+ task_type.change(fn=change_radio_display, inputs=[task_type, mask_source_radio], outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation, run_button, relate_all_button])
733
+ mask_source_radio.change(fn=change_radio_display, inputs=[task_type, mask_source_radio], outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation, run_button, relate_all_button])
734
 
735
  DESCRIPTION = '### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
736
  DESCRIPTION += 'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'