dont clear selected points until `Clear points` button is pressed or input image is changed

#10
by fcakyon - opened
Files changed (1) hide show
  1. app_gradio.py +12 -5
app_gradio.py CHANGED
@@ -159,9 +159,7 @@ def segment_with_points(
159
  use_retina=use_retina,
160
  withContours=withContours,)
161
 
162
- global_points = []
163
- global_point_label = []
164
- return fig, None
165
 
166
 
167
  def get_points_with_draw(image, label, evt: gr.SelectData):
@@ -297,7 +295,7 @@ with gr.Blocks(css=css, title='Fast Segment Anything') as demo:
297
 
298
  segment_btn_p.click(segment_with_points,
299
  inputs=[cond_img_p],
300
- outputs=[segm_img_p, cond_img_p])
301
 
302
  with gr.Tab("Text mode"):
303
  # Images
@@ -361,11 +359,20 @@ with gr.Blocks(css=css, title='Fast Segment Anything') as demo:
361
  outputs=segm_img_t)
362
 
363
  def clear():
 
 
 
 
364
  return None, None
365
-
366
  def clear_text():
367
  return None, None, None
368
 
 
 
 
 
 
369
  clear_btn_e.click(clear, outputs=[cond_img_e, segm_img_e])
370
  clear_btn_p.click(clear, outputs=[cond_img_p, segm_img_p])
371
  clear_btn_t.click(clear_text, outputs=[cond_img_p, segm_img_p, text_box])
 
159
  use_retina=use_retina,
160
  withContours=withContours,)
161
 
162
+ return fig
 
 
163
 
164
 
165
  def get_points_with_draw(image, label, evt: gr.SelectData):
 
295
 
296
  segment_btn_p.click(segment_with_points,
297
  inputs=[cond_img_p],
298
+ outputs=[segm_img_p])
299
 
300
  with gr.Tab("Text mode"):
301
  # Images
 
359
  outputs=segm_img_t)
360
 
361
  def clear():
362
+ global global_points
363
+ global global_point_label
364
+ global_points = []
365
+ global_point_label = []
366
  return None, None
367
+
368
  def clear_text():
369
  return None, None, None
370
 
371
+ everything_tab.select(clear, outputs=[cond_img_e, segm_img_e]) # reset when everything tab is selected
372
+ points_tab.select(clear, outputs=[cond_img_e, segm_img_e]) # reset when points tab is selected
373
+ text_tab.select(clear, outputs=[cond_img_e, segm_img_e]) # reset when text tab is selected
374
+ cond_img_p.clear(clear, outputs=[cond_img_e, segm_img_e]) # reset when input image is cleared
375
+ cond_img_p.input(clear, outputs=[cond_img_e, segm_img_e]) # reset when input image is changed
376
  clear_btn_e.click(clear, outputs=[cond_img_e, segm_img_e])
377
  clear_btn_p.click(clear, outputs=[cond_img_p, segm_img_p])
378
  clear_btn_t.click(clear_text, outputs=[cond_img_p, segm_img_p, text_box])