@@ -74,19 +74,19 @@ def main_ui_panel():
74
74
'dpt_large_384 (midas 3.0)' , 'dpt_hybrid_384 (midas 3.0)' ,
75
75
'midas_v21' , 'midas_v21_small' ], value = 'res101' ,
76
76
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 )
82
77
with gr .Group ():
83
78
with gr .Row ():
84
79
boost = gr .Checkbox (label = "BOOST (multi-resolution merging)" , value = True )
85
80
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 )
86
86
with gr .Group ():
87
87
with gr .Row ():
88
88
clipdepth = gr .Checkbox (label = "Clip and renormalize" , value = False )
89
- with gr .Row () :
89
+ with gr .Row (visible = False ) as clip_options_row_1 :
90
90
clipthreshold_far = gr .Slider (minimum = 0 , maximum = 1 , step = 0.001 , label = 'Far clip' , value = 0 )
91
91
clipthreshold_near = gr .Slider (minimum = 0 , maximum = 1 , step = 0.001 , label = 'Near clip' , value = 1 )
92
92
with gr .Group ():
@@ -101,14 +101,15 @@ def main_ui_panel():
101
101
with gr .Group ():
102
102
with gr .Row ():
103
103
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 :
109
110
stereo_divergence = gr .Slider (minimum = 0.05 , maximum = 10.005 , step = 0.01 , label = 'Divergence (3D effect)' ,
110
111
value = 2.5 )
111
- with gr .Row () :
112
+ with gr .Row (visible = False ) as stereo_options_row_2 :
112
113
stereo_fill = gr .Dropdown (label = "Gap fill technique" ,
113
114
choices = ['none' , 'naive' , 'naive_interpolating' , 'polylines_soft' ,
114
115
'polylines_sharp' ], value = 'polylines_sharp' , type = "value" ,
@@ -123,9 +124,10 @@ def main_ui_panel():
123
124
with gr .Group ():
124
125
with gr .Row ():
125
126
background_removal = gr .Checkbox (label = "Remove background" , value = False )
127
+ with gr .Row (visible = False ) as bgrem_options_row_1 :
126
128
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 :
129
131
background_removal_model = gr .Dropdown (label = "Rembg Model" ,
130
132
choices = ['u2net' , 'u2netp' , 'u2net_human_seg' , 'silueta' ],
131
133
value = 'u2net' , type = "value" , elem_id = "backgroundmodel_type" )
@@ -137,6 +139,7 @@ def main_ui_panel():
137
139
138
140
gen_normal = gr .Checkbox (label = "Generate Normalmap (hidden! api only)" , value = False , visible = False )
139
141
142
+
140
143
clipthreshold_far .change (
141
144
fn = lambda a , b : a if b < a else b ,
142
145
inputs = [clipthreshold_far , clipthreshold_near ],
@@ -149,6 +152,45 @@ def main_ui_panel():
149
152
outputs = [clipthreshold_far ]
150
153
)
151
154
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
+
152
194
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 ]
153
195
154
196
@@ -494,7 +536,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
494
536
outimages .append (heatmap )
495
537
496
538
if gen_stereo :
497
- print ("Generating stereoscopic image(s) .." )
539
+ print ("Generating stereoscopic image.." )
498
540
stereoimage = create_stereoimage (inputimages [count ], img_output , stereo_divergence , stereo_mode , stereo_balance , stereo_fill )
499
541
outimages .append (stereoimage )
500
542
@@ -1001,18 +1043,6 @@ def on_ui_tabs():
1001
1043
with gr .Row ():
1002
1044
submit_vid = gr .Button ('Generate Video' , elem_id = "depthmap_generatevideo" , variant = 'primary' )
1003
1045
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
-
1016
1046
submit .click (
1017
1047
fn = wrap_gradio_gpu_call (run_generate ),
1018
1048
_js = "get_depthmap_tab_index" ,
0 commit comments