liuyizhang commited on
Commit
11e651f
1 Parent(s): fd3aa1a

update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -668,13 +668,15 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
668
  logger.info(f'run_anything_task_[{file_temp}]_9_9_')
669
  return output_images, gr.Gallery.update(label='result images')
670
 
671
- def change_radio_display(task_type, mask_source_radio, num_relation, run_button, relate_all_button):
672
  text_prompt_visible = True
673
  inpaint_prompt_visible = False
674
  mask_source_radio_visible = False
675
  num_relation_visible = False
676
  run_button_visible = True
677
  relate_all_button_visible = False
 
 
678
  if task_type == "inpainting":
679
  inpaint_prompt_visible = True
680
  if task_type == "inpainting" or task_type == "remove":
@@ -686,7 +688,9 @@ def change_radio_display(task_type, mask_source_radio, num_relation, run_button,
686
  num_relation_visible = True
687
  run_button_visible = False
688
  relate_all_button_visible = True
689
- 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)
 
 
690
 
691
  if __name__ == "__main__":
692
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
@@ -729,15 +733,17 @@ if __name__ == "__main__":
729
  remove_mask_extend = gr.Textbox(label="remove_mask_extend", value='10')
730
 
731
  with gr.Column():
732
- gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery"
733
- ).style(preview=True, grid=2, object_fit="scale-down")
 
 
734
 
735
  run_button.click(fn=run_anything_task, inputs=[
736
- 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)
737
- relate_all_button.click(fn=relate_anything, inputs=[input_image, num_relation], outputs=[gallery], show_progress=True, queue=True)
738
 
739
- 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])
740
- 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])
741
 
742
  DESCRIPTION = '### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
743
  DESCRIPTION += 'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
 
668
  logger.info(f'run_anything_task_[{file_temp}]_9_9_')
669
  return output_images, gr.Gallery.update(label='result images')
670
 
671
+ def change_radio_display(task_type, mask_source_radio):
672
  text_prompt_visible = True
673
  inpaint_prompt_visible = False
674
  mask_source_radio_visible = False
675
  num_relation_visible = False
676
  run_button_visible = True
677
  relate_all_button_visible = False
678
+ gsa_gallery_visible = True
679
+ ram_gallery_visible = False
680
  if task_type == "inpainting":
681
  inpaint_prompt_visible = True
682
  if task_type == "inpainting" or task_type == "remove":
 
688
  num_relation_visible = True
689
  run_button_visible = False
690
  relate_all_button_visible = True
691
+ gsa_gallery_visible = False
692
+ ram_gallery_visible = True
693
+ 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), gr.Gallery.update(visible=gsa_gallery_visible), gr.Gallery.update(visible=ram_gallery_visible)
694
 
695
  if __name__ == "__main__":
696
  parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
 
733
  remove_mask_extend = gr.Textbox(label="remove_mask_extend", value='10')
734
 
735
  with gr.Column():
736
+ gsa_gallery = gr.Gallery(label="result images", show_label=True, elem_id="gsa_allery"
737
+ ).style(grid=[2], full_width=True, full_height=True, visible=True)
738
+ ram_gallery = gr.Gallery(label="Your Result", show_label=True, elem_id="ram_gallery"
739
+ ).style(preview=True, columns=5, object_fit="scale-down", visible=False)
740
 
741
  run_button.click(fn=run_anything_task, inputs=[
742
+ 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=[gsa_gallery, gsa_gallery], show_progress=True, queue=True)
743
+ relate_all_button.click(fn=relate_anything, inputs=[input_image, num_relation], outputs=[ram_gallery], show_progress=True, queue=True)
744
 
745
+ 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, gsa_gallery, ram_gallery])
746
+ 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, gsa_gallery, ram_gallery])
747
 
748
  DESCRIPTION = '### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
749
  DESCRIPTION += 'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'