Update app.py
Browse files
app.py
CHANGED
@@ -229,18 +229,64 @@ with gr.Blocks(theme='pikto/theme@>=0.0.1,<0.0.3') as pan:
|
|
229 |
|
230 |
b1.click(get_next10_images, [df, row_count], [df, row_count, img_search], api_name = "load_playgroundai_images" )
|
231 |
|
232 |
-
##########################
|
233 |
with gr.Tab("Rem_BG"):
|
234 |
|
235 |
color_state = gr.State(value=False)
|
236 |
matting_state = gr.State(value=(0, 0, 0))
|
237 |
gr.HTML("<center><h1>Remove Background Tool</h1></center>")
|
238 |
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
-
text_input = gr.Textbox() ## Diffuser
|
242 |
-
image_output = gr.Image()
|
243 |
-
image_button = gr.Button("Flip")
|
244 |
|
245 |
|
246 |
|
|
|
229 |
|
230 |
b1.click(get_next10_images, [df, row_count], [df, row_count, img_search], api_name = "load_playgroundai_images" )
|
231 |
|
232 |
+
########################## REM-BG
|
233 |
with gr.Tab("Rem_BG"):
|
234 |
|
235 |
color_state = gr.State(value=False)
|
236 |
matting_state = gr.State(value=(0, 0, 0))
|
237 |
gr.HTML("<center><h1>Remove Background Tool</h1></center>")
|
238 |
|
239 |
+
with gr.Row(equal_height=False):
|
240 |
+
with gr.Column():
|
241 |
+
input_img = gr.Image(type="pil", label="Input image")
|
242 |
+
drp_models = gr.Dropdown(choices=model_choices, label="Model Segment", value="TracerUniversalB7")
|
243 |
+
with gr.Row():
|
244 |
+
chk_include_matting = gr.Checkbox(label="Matting", value=False)
|
245 |
+
chk_smoot_mask = gr.Checkbox(label="Smoot Mask", value=False)
|
246 |
+
chk_show_mask = gr.Checkbox(label="Show Mask", value=False)
|
247 |
+
with gr.Box(visible=False) as slider_matting:
|
248 |
+
slr_fg_threshold = gr.Slider(0, 300, value=270, step=1, label="Alpha matting foreground threshold")
|
249 |
+
slr_bg_threshold = gr.Slider(0, 50, value=20, step=1, label="Alpha matting background threshold")
|
250 |
+
slr_erode_size = gr.Slider(0, 20, value=11, step=1, label="Alpha matting erode size")
|
251 |
+
with gr.Box():
|
252 |
+
with gr.Row():
|
253 |
+
chk_change_color = gr.Checkbox(label="Change background color", value=False)
|
254 |
+
pkr_color = gr.ColorPicker(label="Pick a new color", visible=False)
|
255 |
+
chk_dominant = gr.Checkbox(label="Use dominant color", value=False, visible=False)
|
256 |
+
run_btn = gr.Button(value="Remove background", variant="primary")
|
257 |
+
with gr.Column():
|
258 |
+
output_img = gr.Image(type="pil", label="Image Result")
|
259 |
+
mask_img = gr.Image(type="pil", label="Image Mask", visible=False)
|
260 |
+
gr.ClearButton(components=[input_img, output_img, mask_img])
|
261 |
+
|
262 |
+
chk_include_matting.change(change_include_matting, inputs=[chk_include_matting],
|
263 |
+
outputs=[slider_matting, matting_state,
|
264 |
+
slr_fg_threshold, slr_bg_threshold, slr_erode_size])
|
265 |
+
|
266 |
+
slr_fg_threshold.change(change_foreground_threshold, inputs=[slr_fg_threshold, matting_state],
|
267 |
+
outputs=[matting_state])
|
268 |
+
|
269 |
+
slr_bg_threshold.change(change_background_threshold, inputs=[slr_bg_threshold, matting_state],
|
270 |
+
outputs=[matting_state])
|
271 |
+
|
272 |
+
slr_erode_size.change(change_erode_size, inputs=[slr_erode_size, matting_state],
|
273 |
+
outputs=[matting_state])
|
274 |
+
|
275 |
+
chk_show_mask.change(change_show_mask, inputs=[chk_show_mask], outputs=[mask_img])
|
276 |
+
|
277 |
+
chk_change_color.change(change_background_mode, inputs=[chk_change_color],
|
278 |
+
outputs=[pkr_color, chk_dominant])
|
279 |
+
|
280 |
+
pkr_color.change(change_picker_color, inputs=[pkr_color, chk_dominant], outputs=[color_state])
|
281 |
+
|
282 |
+
chk_dominant.change(set_dominant_color, inputs=[chk_dominant], outputs=[color_state, pkr_color])
|
283 |
+
|
284 |
+
run_btn.click(predict, inputs=[input_img, drp_models, chk_smoot_mask, matting_state, color_state],
|
285 |
+
outputs=[output_img, mask_img])
|
286 |
|
287 |
+
# text_input = gr.Textbox() ## Diffuser
|
288 |
+
# image_output = gr.Image()
|
289 |
+
# image_button = gr.Button("Flip")
|
290 |
|
291 |
|
292 |
|