Skip to content

Commit bcf48a5

Browse files
committed
Questionable design decisions
Element hiding-unhiding how works in the standalone mode.
1 parent 2fbfbba commit bcf48a5

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

src/common_ui.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ def main_ui_panel(is_depth_tab):
2525
'zoedepth_n (indoor)', 'zoedepth_k (outdoor)', 'zoedepth_nk'],
2626
value='res101',
2727
type="index")
28-
with gr.Group():
28+
with gr.Box():
2929
with gr.Row():
3030
inp += 'boost', gr.Checkbox(label="BOOST (multi-resolution merging)", value=True)
3131
inp += 'match_size', gr.Checkbox(label="Match net size to input size", value=False)
3232
with gr.Row(visible=False) as options_depend_on_match_size:
3333
inp += 'net_width', gr.Slider(minimum=64, maximum=2048, step=64, label='Net width', value=448)
3434
inp += 'net_height', gr.Slider(minimum=64, maximum=2048, step=64, label='Net height', value=448)
3535

36-
with gr.Group():
36+
with gr.Box():
3737
with gr.Row():
38-
inp += "save_outputs", gr.Checkbox(label="Save Outputs", value=True) # 50% of width
38+
with gr.Group():
39+
inp += "save_outputs", gr.Checkbox(label="Save Outputs", value=True) # 50% of width
3940
with gr.Group(): # 50% of width
4041
inp += "output_depth", gr.Checkbox(label="Output DepthMap", value=True)
4142
inp += "invert_depth", gr.Checkbox(label="Invert (black=near, white=far)", value=False)
@@ -44,22 +45,22 @@ def main_ui_panel(is_depth_tab):
4445
label="Combine input and depthmap into one image", value=False)
4546
inp += "combine_output_axis", gr.Radio(label="Combine axis", choices=['Vertical', 'Horizontal'],
4647
value='Horizontal', type="index", visible=False)
47-
with gr.Group():
48+
with gr.Box():
4849
with gr.Row():
4950
inp += 'clipdepth', gr.Checkbox(label="Clip and renormalize DepthMap", value=False)
5051
with gr.Row(visible=False) as clip_options_row_1:
5152
inp += "clipthreshold_far", gr.Slider(minimum=0, maximum=1, step=0.001, label='Far clip', value=0)
5253
inp += "clipthreshold_near", gr.Slider(minimum=0, maximum=1, step=0.001, label='Near clip', value=1)
5354

54-
with gr.Group():
55+
with gr.Box():
5556
with gr.Row():
5657
inp += "show_heat", gr.Checkbox(label="Generate HeatMap", value=False)
5758
# gr.Checkbox(label="Generate NormalMap", value=False) # TODO: this is a fake door
5859

59-
with gr.Group():
60+
with gr.Box():
6061
with gr.Row():
6162
inp += "gen_stereo", gr.Checkbox(label="Generate stereoscopic image(s)", value=False)
62-
with gr.Group(visible=False) as stereo_options:
63+
with gr.Column(visible=False) as stereo_options:
6364
with gr.Row():
6465
inp += "stereo_modes", gr.CheckboxGroup(
6566
["left-right", "right-left", "top-bottom", "bottom-top", "red-cyan-anaglyph"],
@@ -80,41 +81,42 @@ def main_ui_panel(is_depth_tab):
8081
label='Balance between eyes',
8182
value=0.0)
8283

83-
with gr.Group():
84-
with gr.Row():
84+
with gr.Box():
85+
with gr.Column():
8586
inp += "gen_mesh", gr.Checkbox(
8687
label="Generate simple 3D mesh", value=False, visible=True)
87-
with gr.Group(visible=False) as mesh_options:
88+
with gr.Column(visible=False) as mesh_options:
8889
with gr.Row():
8990
gr.HTML(value="Generates fast, accurate only with ZoeDepth models and no boost, no custom maps")
9091
with gr.Row():
9192
inp += "mesh_occlude", gr.Checkbox(label="Remove occluded edges", value=True, visible=True)
9293
inp += "mesh_spherical", gr.Checkbox(label="Equirectangular projection", value=False, visible=True)
9394

9495
if is_depth_tab:
95-
with gr.Group():
96-
with gr.Row():
96+
with gr.Box():
97+
with gr.Column():
9798
inp += "inpaint", gr.Checkbox(
9899
label="Generate 3D inpainted mesh", value=False)
99-
with gr.Group(visible=False) as inpaint_options_row_0:
100+
with gr.Column(visible=False) as inpaint_options_row_0:
100101
gr.HTML("Generation is sloooow, required for generating videos")
101102
inp += "inpaint_vids", gr.Checkbox(
102103
label="Generate 4 demo videos with 3D inpainted mesh.", value=False)
103104
gr.HTML("More options for generating video can be found in the Generate video tab")
104105

105-
with gr.Group():
106+
with gr.Box():
106107
# TODO: it should be clear from the UI that there is an option of the background removal
107108
# that does not use the model selected above
108109
with gr.Row():
109110
inp += "background_removal", gr.Checkbox(label="Remove background", value=False)
110-
with gr.Row(visible=False) as bgrem_options_row_1:
111-
inp += "save_background_removal_masks", gr.Checkbox(label="Save the foreground masks", value=False)
112-
inp += "pre_depth_background_removal", gr.Checkbox(label="Pre-depth background removal", value=False)
113-
with gr.Row(visible=False) as bgrem_options_row_2:
114-
inp += "background_removal_model", gr.Dropdown(label="Rembg Model",
115-
choices=['u2net', 'u2netp', 'u2net_human_seg',
116-
'silueta'],
117-
value='u2net', type="value")
111+
with gr.Column(visible=False) as bgrem_options:
112+
with gr.Row():
113+
inp += "save_background_removal_masks", gr.Checkbox(label="Save the foreground masks", value=False)
114+
inp += "pre_depth_background_removal", gr.Checkbox(label="Pre-depth background removal", value=False)
115+
with gr.Row():
116+
inp += "background_removal_model", gr.Dropdown(label="Rembg Model",
117+
choices=['u2net', 'u2netp', 'u2net_human_seg',
118+
'silueta'],
119+
value='u2net', type="value")
118120

119121
with gr.Box():
120122
gr.HTML(f"{SCRIPT_FULL_NAME}<br/>")
@@ -194,9 +196,9 @@ def update_delault_net_size(model_type):
194196
)
195197

196198
inp['background_removal'].change(
197-
fn=lambda v: (bgrem_options_row_1.update(visible=v), bgrem_options_row_2.update(visible=v)),
199+
fn=lambda v: bgrem_options.update(visible=v),
198200
inputs=[inp['background_removal']],
199-
outputs=[bgrem_options_row_1, bgrem_options_row_2]
201+
outputs=[bgrem_options]
200202
)
201203

202204
return inp
@@ -209,13 +211,13 @@ def on_ui_tabs():
209211
inp += 'depthmap_mode', gr.HTML(visible=False, value='0')
210212
with gr.Tabs():
211213
with gr.TabItem('Single Image') as depthmap_mode_0:
212-
with gr.Row():
213-
inp += gr.Image(label="Source", source="upload", interactive=True, type="pil",
214-
elem_id="depthmap_input_image")
215-
with gr.Group(visible=False) as custom_depthmap_row_0:
214+
with gr.Group():
215+
with gr.Row():
216+
inp += gr.Image(label="Source", source="upload", interactive=True, type="pil",
217+
elem_id="depthmap_input_image")
216218
# TODO: depthmap generation settings should disappear when using this
217219
inp += gr.File(label="Custom DepthMap", file_count="single", interactive=True,
218-
type="file", elem_id='custom_depthmap_img')
220+
type="file", elem_id='custom_depthmap_img', visible=False)
219221
inp += gr.Checkbox(elem_id="custom_depthmap", label="Use custom DepthMap", value=False)
220222
with gr.TabItem('Batch Process') as depthmap_mode_1:
221223
inp += gr.File(elem_id='image_batch', label="Batch Process", file_count="multiple",
@@ -291,13 +293,10 @@ def on_ui_tabs():
291293
depthmap_mode_1.select(lambda: '1', None, inp['depthmap_mode'])
292294
depthmap_mode_2.select(lambda: '2', None, inp['depthmap_mode'])
293295

294-
def custom_depthmap_visibility(v):
295-
return custom_depthmap_row_0.update(visible=v)
296-
297296
inp['custom_depthmap'].change(
298-
fn=custom_depthmap_visibility,
297+
fn=lambda v: inp['custom_depthmap_img'].update(visible=v),
299298
inputs=[inp['custom_depthmap']],
300-
outputs=[custom_depthmap_row_0]
299+
outputs=[inp['custom_depthmap_img']]
301300
)
302301

303302
unloadmodels.click(

0 commit comments

Comments
 (0)