juanelot commited on
Commit
57135e2
·
verified ·
1 Parent(s): 326c934

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -30
app.py CHANGED
@@ -75,48 +75,48 @@ with gr.Blocks(title="Remove background") as app:
75
  gr.HTML("<center><h1>Background Remover</h1></center>")
76
  with gr.Row(equal_height=False):
77
  with gr.Column():
78
- # input_img = gr.Image(type="pil", label="Input image")
79
- # drp_models = gr.Dropdown(choices=model_choices, label="Model Segment", value="U2NET")
80
- # with gr.Row():
81
- # chk_include_matting = gr.Checkbox(label="Matting", value=False)
82
- # chk_smoot_mask = gr.Checkbox(label="Smoot Mask", value=False)
83
- # chk_show_mask = gr.Checkbox(label="Show Mask", value=False)
84
- # with gr.Box(visible=False) as slider_matting:
85
- # slr_fg_threshold = gr.Slider(0, 300, value=270, step=1, label="Alpha matting foreground threshold")
86
- # slr_bg_threshold = gr.Slider(0, 50, value=20, step=1, label="Alpha matting background threshold")
87
- # slr_erode_size = gr.Slider(0, 20, value=11, step=1, label="Alpha matting erode size")
88
- #with gr.Box():
89
- # with gr.Row():
90
- # chk_change_color = gr.Checkbox(label="Change background color", value=False)
91
- # pkr_color = gr.ColorPicker(label="Pick a new color", visible=False)
92
- #chk_dominant = gr.Checkbox(label="Use dominant color", value=False, visible=False)
93
  run_btn = gr.Button(value="Remove background", variant="primary")
94
  with gr.Column():
95
  output_img = gr.Image(type="pil", label="Image Result")
96
  mask_img = gr.Image(type="pil", label="Image Mask", visible=False)
97
- # gr.ClearButton(components=[input_img, output_img, mask_img])
98
 
99
- #chk_include_matting.change(change_include_matting, inputs=[chk_include_matting],
100
- # outputs=[slider_matting, matting_state,
101
- # slr_fg_threshold, slr_bg_threshold, slr_erode_size])
102
 
103
- #slr_fg_threshold.change(change_foreground_threshold, inputs=[slr_fg_threshold, matting_state],
104
- # outputs=[matting_state])
105
 
106
- #slr_bg_threshold.change(change_background_threshold, inputs=[slr_bg_threshold, matting_state],
107
- # outputs=[matting_state])
108
 
109
- # slr_erode_size.change(change_erode_size, inputs=[slr_erode_size, matting_state],
110
- # outputs=[matting_state])
111
 
112
- #chk_show_mask.change(change_show_mask, inputs=[chk_show_mask], outputs=[mask_img])
113
 
114
- # chk_change_color.change(change_background_mode, inputs=[chk_change_color],
115
- # outputs=[pkr_color, chk_dominant])
116
 
117
- # pkr_color.change(change_picker_color, inputs=[pkr_color, chk_dominant], outputs=[color_state])
118
 
119
- # chk_dominant.change(set_dominant_color, inputs=[chk_dominant], outputs=[color_state, pkr_color])
120
 
121
  run_btn.click(predict, inputs=[input_img, drp_models, chk_smoot_mask, matting_state, color_state],
122
  outputs=[output_img, mask_img])
 
75
  gr.HTML("<center><h1>Background Remover</h1></center>")
76
  with gr.Row(equal_height=False):
77
  with gr.Column():
78
+ input_img = gr.Image(type="pil", label="Input image")
79
+ drp_models = gr.Dropdown(choices=model_choices, label="Model Segment", value="U2NET")
80
+ with gr.Row():
81
+ chk_include_matting = gr.Checkbox(label="Matting", value=False)
82
+ chk_smoot_mask = gr.Checkbox(label="Smoot Mask", value=False)
83
+ chk_show_mask = gr.Checkbox(label="Show Mask", value=False)
84
+ with gr.Box(visible=False) as slider_matting:
85
+ slr_fg_threshold = gr.Slider(0, 300, value=270, step=1, label="Alpha matting foreground threshold")
86
+ slr_bg_threshold = gr.Slider(0, 50, value=20, step=1, label="Alpha matting background threshold")
87
+ slr_erode_size = gr.Slider(0, 20, value=11, step=1, label="Alpha matting erode size")
88
+ with gr.Box():
89
+ with gr.Row():
90
+ chk_change_color = gr.Checkbox(label="Change background color", value=False)
91
+ pkr_color = gr.ColorPicker(label="Pick a new color", visible=False)
92
+ chk_dominant = gr.Checkbox(label="Use dominant color", value=False, visible=False)
93
  run_btn = gr.Button(value="Remove background", variant="primary")
94
  with gr.Column():
95
  output_img = gr.Image(type="pil", label="Image Result")
96
  mask_img = gr.Image(type="pil", label="Image Mask", visible=False)
97
+ gr.ClearButton(components=[input_img, output_img, mask_img])
98
 
99
+ chk_include_matting.change(change_include_matting, inputs=[chk_include_matting],
100
+ outputs=[slider_matting, matting_state,
101
+ slr_fg_threshold, slr_bg_threshold, slr_erode_size])
102
 
103
+ slr_fg_threshold.change(change_foreground_threshold, inputs=[slr_fg_threshold, matting_state],
104
+ outputs=[matting_state])
105
 
106
+ slr_bg_threshold.change(change_background_threshold, inputs=[slr_bg_threshold, matting_state],
107
+ outputs=[matting_state])
108
 
109
+ slr_erode_size.change(change_erode_size, inputs=[slr_erode_size, matting_state],
110
+ outputs=[matting_state])
111
 
112
+ chk_show_mask.change(change_show_mask, inputs=[chk_show_mask], outputs=[mask_img])
113
 
114
+ chk_change_color.change(change_background_mode, inputs=[chk_change_color],
115
+ outputs=[pkr_color, chk_dominant])
116
 
117
+ pkr_color.change(change_picker_color, inputs=[pkr_color, chk_dominant], outputs=[color_state])
118
 
119
+ chk_dominant.change(set_dominant_color, inputs=[chk_dominant], outputs=[color_state, pkr_color])
120
 
121
  run_btn.click(predict, inputs=[input_img, drp_models, chk_smoot_mask, matting_state, color_state],
122
  outputs=[output_img, mask_img])