Skip to content

Commit 04f96a2

Browse files
committed
Simplify UI - only show options that are not disabled
1 parent 91b272b commit 04f96a2

File tree

1 file changed

+57
-27
lines changed

1 file changed

+57
-27
lines changed

scripts/depthmap.py

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ def main_ui_panel():
7474
'dpt_large_384 (midas 3.0)', 'dpt_hybrid_384 (midas 3.0)',
7575
'midas_v21', 'midas_v21_small'], value='res101',
7676
type="index", elem_id="tabmodel_type")
77-
with gr.Group():
78-
with gr.Row():
79-
net_width = gr.Slider(minimum=64, maximum=2048, step=64, label='Net width', value=512)
80-
net_height = gr.Slider(minimum=64, maximum=2048, step=64, label='Net height', value=512)
81-
match_size = gr.Checkbox(label="Match input size (size is ignored when using boost)", value=False)
8277
with gr.Group():
8378
with gr.Row():
8479
boost = gr.Checkbox(label="BOOST (multi-resolution merging)", value=True)
8580
invert_depth = gr.Checkbox(label="Invert DepthMap (black=near, white=far)", value=False)
81+
with gr.Group(visible=False) as options_depend_on_boost:
82+
match_size = gr.Checkbox(label="Match input size", value=False)
83+
with gr.Row() as options_depend_on_match_size:
84+
net_width = gr.Slider(minimum=64, maximum=2048, step=64, label='Net width', value=512)
85+
net_height = gr.Slider(minimum=64, maximum=2048, step=64, label='Net height', value=512)
8686
with gr.Group():
8787
with gr.Row():
8888
clipdepth = gr.Checkbox(label="Clip and renormalize", value=False)
89-
with gr.Row():
89+
with gr.Row(visible=False) as clip_options_row_1:
9090
clipthreshold_far = gr.Slider(minimum=0, maximum=1, step=0.001, label='Far clip', value=0)
9191
clipthreshold_near = gr.Slider(minimum=0, maximum=1, step=0.001, label='Near clip', value=1)
9292
with gr.Group():
@@ -101,14 +101,15 @@ def main_ui_panel():
101101
with gr.Group():
102102
with gr.Row():
103103
gen_stereo = gr.Checkbox(label="Generate stereoscopic image", value=False)
104-
stereo_mode = gr.Dropdown(label="Stereoscopic image type",
105-
choices=['left-right', 'right-left', 'top-bottom', 'bottom-top',
106-
'red-cyan-anaglyph'], value='left-right', type="value",
107-
elem_id="stereo_mode")
108-
with gr.Row():
104+
with gr.Group(visible=False) as stereo_options_row_0:
105+
stereo_mode = gr.Dropdown(label="Stereoscopic image type",
106+
choices=['left-right', 'right-left', 'top-bottom', 'bottom-top',
107+
'red-cyan-anaglyph'], value='left-right', type="value",
108+
elem_id="stereo_mode")
109+
with gr.Row(visible=False) as stereo_options_row_1:
109110
stereo_divergence = gr.Slider(minimum=0.05, maximum=10.005, step=0.01, label='Divergence (3D effect)',
110111
value=2.5)
111-
with gr.Row():
112+
with gr.Row(visible=False) as stereo_options_row_2:
112113
stereo_fill = gr.Dropdown(label="Gap fill technique",
113114
choices=['none', 'naive', 'naive_interpolating', 'polylines_soft',
114115
'polylines_sharp'], value='polylines_sharp', type="value",
@@ -123,9 +124,10 @@ def main_ui_panel():
123124
with gr.Group():
124125
with gr.Row():
125126
background_removal = gr.Checkbox(label="Remove background", value=False)
127+
with gr.Row(visible=False) as bgrem_options_row_1:
126128
save_background_removal_masks = gr.Checkbox(label="Save the foreground masks", value=False)
127-
pre_depth_background_removal = gr.Checkbox(label="pre-depth background removal", value=False)
128-
with gr.Row():
129+
pre_depth_background_removal = gr.Checkbox(label="Pre-depth background removal", value=False)
130+
with gr.Row(visible=False) as bgrem_options_row_2:
129131
background_removal_model = gr.Dropdown(label="Rembg Model",
130132
choices=['u2net', 'u2netp', 'u2net_human_seg', 'silueta'],
131133
value='u2net', type="value", elem_id="backgroundmodel_type")
@@ -137,6 +139,7 @@ def main_ui_panel():
137139

138140
gen_normal = gr.Checkbox(label="Generate Normalmap (hidden! api only)", value=False, visible=False)
139141

142+
140143
clipthreshold_far.change(
141144
fn=lambda a, b: a if b < a else b,
142145
inputs=[clipthreshold_far, clipthreshold_near],
@@ -149,6 +152,45 @@ def main_ui_panel():
149152
outputs=[clipthreshold_far]
150153
)
151154

155+
boost.change(
156+
fn=lambda a: options_depend_on_boost.update(visible = not a),
157+
inputs=[boost],
158+
outputs=[options_depend_on_boost]
159+
)
160+
161+
match_size.change(
162+
fn=lambda a: options_depend_on_match_size.update(visible = not a),
163+
inputs=[match_size],
164+
outputs=[options_depend_on_match_size]
165+
)
166+
167+
def clipdepth_options_visibility(v):
168+
return clip_options_row_1.update(visible=v)
169+
clipdepth.change(
170+
fn=clipdepth_options_visibility,
171+
inputs=[clipdepth],
172+
outputs=[clip_options_row_1]
173+
)
174+
175+
def stereo_options_visibility(v):
176+
return stereo_options_row_0.update(visible=v),\
177+
stereo_options_row_1.update(visible=v),\
178+
stereo_options_row_2.update(visible=v)
179+
gen_stereo.change(
180+
fn=stereo_options_visibility,
181+
inputs=[gen_stereo],
182+
outputs=[stereo_options_row_0, stereo_options_row_1, stereo_options_row_2]
183+
)
184+
185+
def background_removal_options_visibility(v):
186+
return bgrem_options_row_1.update(visible=v), \
187+
bgrem_options_row_2.update(visible=v)
188+
background_removal.change(
189+
fn=background_removal_options_visibility,
190+
inputs=[background_removal],
191+
outputs=[bgrem_options_row_1, bgrem_options_row_2]
192+
)
193+
152194
return [compute_device, model_type, net_width, net_height, match_size, boost, invert_depth, clipdepth, clipthreshold_far, clipthreshold_near, combine_output, combine_output_axis, save_depth, show_depth, show_heat, gen_stereo, stereo_mode, stereo_divergence, stereo_fill, stereo_balance, inpaint, inpaint_vids, background_removal, save_background_removal_masks, gen_normal, pre_depth_background_removal, background_removal_model]
153195

154196

@@ -494,7 +536,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
494536
outimages.append(heatmap)
495537

496538
if gen_stereo:
497-
print("Generating stereoscopic image(s)..")
539+
print("Generating stereoscopic image..")
498540
stereoimage = create_stereoimage(inputimages[count], img_output, stereo_divergence, stereo_mode, stereo_balance, stereo_fill)
499541
outimages.append(stereoimage)
500542

@@ -1001,18 +1043,6 @@ def on_ui_tabs():
10011043
with gr.Row():
10021044
submit_vid = gr.Button('Generate Video', elem_id="depthmap_generatevideo", variant='primary')
10031045

1004-
clipthreshold_far.change(
1005-
fn = lambda a, b: a if b < a else b,
1006-
inputs = [clipthreshold_far, clipthreshold_near],
1007-
outputs=[clipthreshold_near]
1008-
)
1009-
1010-
clipthreshold_near.change(
1011-
fn = lambda a, b: a if b > a else b,
1012-
inputs = [clipthreshold_near, clipthreshold_far],
1013-
outputs=[clipthreshold_far]
1014-
)
1015-
10161046
submit.click(
10171047
fn=wrap_gradio_gpu_call(run_generate),
10181048
_js="get_depthmap_tab_index",

0 commit comments

Comments
 (0)