majinyu commited on
Commit
3e575ea
·
1 Parent(s): 937dfed

change clear buttons to ClearButton for immediate response

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -6,7 +6,7 @@ from pathlib import Path
6
  # building GroundingDINO requires torch but imports it before installing,
7
  # so directly installing in requirements.txt causes dependency error.
8
  # 1. build with "-e" option to keep the bin file in ./GroundingDINO/groundingdino/, rather than in site-package dir.
9
- os.system("pip install -e ./GroundingDINO/")
10
  # 2. for unknown reason, "import groundingdino" will fill due to unable to find the module, even after installing.
11
  # add ./GroundingDINO/ to PATH, so package "groundingdino" can be imported.
12
  sys.path.append(str(Path(__file__).parent / "GroundingDINO"))
@@ -295,7 +295,7 @@ if __name__ == "__main__":
295
  ram_in_img = gr.Image(type="pil")
296
  with gr.Row():
297
  ram_btn_run = gr.Button(value="Run")
298
- ram_btn_clear = gr.Button(value="Clear")
299
  with gr.Column():
300
  ram_out_img = gr.Image(type="pil")
301
  ram_out_tag = gr.Textbox(label="Tags")
@@ -319,7 +319,7 @@ if __name__ == "__main__":
319
  t2t_in_tag = gr.Textbox(label="User Specified Tags (Optional, separated by comma)")
320
  with gr.Row():
321
  t2t_btn_run = gr.Button(value="Run")
322
- t2t_btn_clear = gr.Button(value="Clear")
323
  with gr.Column():
324
  t2t_out_img = gr.Image(type="pil")
325
  t2t_out_tag = gr.Textbox(label="Tags")
@@ -353,17 +353,13 @@ if __name__ == "__main__":
353
  outputs=[t2t_out_tag, t2t_out_cap, t2t_out_img]
354
  )
355
 
356
- # clear all
357
- def clear_all():
358
- return [gr.update(value=None)] * 4 + [gr.update(value="")] * 5
359
-
360
- ram_btn_clear.click(fn=clear_all, inputs=[], outputs=[
361
- ram_in_img, ram_out_img, t2t_in_img, t2t_out_img,
362
- ram_out_tag, ram_out_biaoqian, t2t_in_tag, t2t_out_tag, t2t_out_cap
363
  ])
364
- t2t_btn_clear.click(fn=clear_all, inputs=[], outputs=[
365
- ram_in_img, t2t_in_img, t2t_in_img, t2t_out_img,
366
- ram_out_tag, ram_out_biaoqian, t2t_in_tag, t2t_out_tag, t2t_out_cap
367
  ])
368
 
369
  return demo
 
6
  # building GroundingDINO requires torch but imports it before installing,
7
  # so directly installing in requirements.txt causes dependency error.
8
  # 1. build with "-e" option to keep the bin file in ./GroundingDINO/groundingdino/, rather than in site-package dir.
9
+ os.system("pip install -e ./GroundingDINO/")
10
  # 2. for unknown reason, "import groundingdino" will fill due to unable to find the module, even after installing.
11
  # add ./GroundingDINO/ to PATH, so package "groundingdino" can be imported.
12
  sys.path.append(str(Path(__file__).parent / "GroundingDINO"))
 
295
  ram_in_img = gr.Image(type="pil")
296
  with gr.Row():
297
  ram_btn_run = gr.Button(value="Run")
298
+ ram_btn_clear = gr.ClearButton()
299
  with gr.Column():
300
  ram_out_img = gr.Image(type="pil")
301
  ram_out_tag = gr.Textbox(label="Tags")
 
319
  t2t_in_tag = gr.Textbox(label="User Specified Tags (Optional, separated by comma)")
320
  with gr.Row():
321
  t2t_btn_run = gr.Button(value="Run")
322
+ t2t_btn_clear = gr.ClearButton()
323
  with gr.Column():
324
  t2t_out_img = gr.Image(type="pil")
325
  t2t_out_tag = gr.Textbox(label="Tags")
 
353
  outputs=[t2t_out_tag, t2t_out_cap, t2t_out_img]
354
  )
355
 
356
+ ram_btn_clear.add([
357
+ ram_in_img, t2t_in_img, t2t_in_tag,
358
+ ram_out_img, ram_out_tag, ram_out_biaoqian, t2t_out_img, t2t_out_tag, t2t_out_cap
 
 
 
 
359
  ])
360
+ t2t_btn_clear.add([
361
+ ram_in_img, t2t_in_img, t2t_in_tag,
362
+ ram_out_img, ram_out_tag, ram_out_biaoqian, t2t_out_img, t2t_out_tag, t2t_out_cap
363
  ])
364
 
365
  return demo