@@ -80,7 +80,7 @@ def main_ui_panel(is_depth_tab):
80
80
"left-only" , "only-right" , "cyan-red-reverseanaglyph"
81
81
][0 :8 if backbone .get_opt ('depthmap_script_extra_stereomodes' , False ) else 5 ], label = "Output" )
82
82
with gr .Row ():
83
- inp += go .STEREO_DIVERGENCE , gr .Slider (minimum = 0.05 , maximum = 10 .005 , step = 0.01 ,
83
+ inp += go .STEREO_DIVERGENCE , gr .Slider (minimum = 0.05 , maximum = 15 .005 , step = 0.01 ,
84
84
label = 'Divergence (3D effect)' )
85
85
inp += go .STEREO_SEPARATION , gr .Slider (minimum = - 5.0 , maximum = 5.0 , step = 0.01 ,
86
86
label = 'Separation (moves images apart)' )
@@ -99,13 +99,16 @@ def main_ui_panel(is_depth_tab):
99
99
with gr .Column (visible = False ) as normalmap_options :
100
100
with gr .Row ():
101
101
inp += go .NORMALMAP_PRE_BLUR , gr .Checkbox (label = "Smooth before calculating normals" )
102
- inp += go .NORMALMAP_PRE_BLUR_KERNEL , gr .Slider (minimum = 1 , maximum = 31 , step = 2 , label = 'Pre-smooth kernel size' )
102
+ inp += go .NORMALMAP_PRE_BLUR_KERNEL , gr .Slider (minimum = 1 , maximum = 31 , step = 2 , label = 'Pre-smooth kernel size' , visible = False )
103
+ inp .add_rule (go .NORMALMAP_PRE_BLUR_KERNEL , 'visible-if' , go .NORMALMAP_PRE_BLUR )
103
104
with gr .Row ():
104
105
inp += go .NORMALMAP_SOBEL , gr .Checkbox (label = "Sobel gradient" )
105
106
inp += go .NORMALMAP_SOBEL_KERNEL , gr .Slider (minimum = 1 , maximum = 31 , step = 2 , label = 'Sobel kernel size' )
107
+ inp .add_rule (go .NORMALMAP_SOBEL_KERNEL , 'visible-if' , go .NORMALMAP_SOBEL )
106
108
with gr .Row ():
107
109
inp += go .NORMALMAP_POST_BLUR , gr .Checkbox (label = "Smooth after calculating normals" )
108
- inp += go .NORMALMAP_POST_BLUR_KERNEL , gr .Slider (minimum = 1 , maximum = 31 , step = 2 , label = 'Post-smooth kernel size' )
110
+ inp += go .NORMALMAP_POST_BLUR_KERNEL , gr .Slider (minimum = 1 , maximum = 31 , step = 2 , label = 'Post-smooth kernel size' , visible = False )
111
+ inp .add_rule (go .NORMALMAP_POST_BLUR_KERNEL , 'visible-if' , go .NORMALMAP_POST_BLUR )
109
112
with gr .Row ():
110
113
inp += go .NORMALMAP_INVERT , gr .Checkbox (label = "Invert" )
111
114
@@ -219,8 +222,12 @@ def open_folder_action():
219
222
220
223
221
224
def depthmap_mode_video (inp ):
222
- inp += gr .File (elem_id = 'depthmap_input_video' , label = "Video or animated file" ,
225
+ gr .HTML (value = "Single video mode allows generating videos from videos. Every frame of the video is processed, "
226
+ "please adjust generation settings, so that generation is not too slow. For the best results, "
227
+ "Use a zoedepth model, since they provide the highest level of temporal coherency." )
228
+ inp += gr .File (elem_id = 'depthmap_vm_input' , label = "Video or animated file" ,
223
229
file_count = "single" , interactive = True , type = "file" )
230
+ inp += gr .Dropdown (elem_id = "depthmap_vm_smoothening_mode" , label = "Smoothening" , type = "value" , choices = ['none' ])
224
231
inp += gr .Checkbox (elem_id = "depthmap_vm_custom_checkbox" ,
225
232
label = "Use custom/pregenerated DepthMap video" , value = False )
226
233
inp += gr .File (elem_id = 'depthmap_vm_custom' , file_count = "single" ,
@@ -230,23 +237,21 @@ def depthmap_mode_video(inp):
230
237
inp += gr .Slider (elem_id = 'depthmap_vm_compress_bitrate' , label = "Bitrate (kbit)" , visible = False ,
231
238
minimum = 1000 , value = 15000 , maximum = 50000 , step = 250 )
232
239
233
- inp ['depthmap_vm_custom_checkbox' ].change (
234
- fn = lambda v : inp ['depthmap_vm_custom' ].update (visible = v ),
235
- inputs = [inp ['depthmap_vm_custom_checkbox' ]],
236
- outputs = [inp ['depthmap_vm_custom' ]]
237
- )
238
-
239
- inp ['depthmap_vm_compress_checkbox' ].change (
240
- fn = lambda v : inp ['depthmap_vm_compress_bitrate' ].update (visible = v ),
241
- inputs = [inp ['depthmap_vm_compress_checkbox' ]],
242
- outputs = [inp ['depthmap_vm_compress_bitrate' ]]
243
- )
240
+ inp .add_rule ('depthmap_vm_custom' , 'visible-if' , 'depthmap_vm_custom_checkbox' )
241
+ inp .add_rule ('depthmap_vm_compress_bitrate' , 'visible-if' , 'depthmap_vm_compress_checkbox' )
244
242
245
243
return inp
246
244
245
+
246
+ custom_css = """
247
+ #depthmap_vm_input {height: 75px}
248
+ #depthmap_vm_custom {height: 75px}
249
+ """
250
+
251
+
247
252
def on_ui_tabs ():
248
253
inp = GradioComponentBundle ()
249
- with gr .Blocks (analytics_enabled = False , title = "DepthMap" ) as depthmap_interface :
254
+ with gr .Blocks (analytics_enabled = False , title = "DepthMap" , css = custom_css ) as depthmap_interface :
250
255
with gr .Row ().style (equal_height = False ):
251
256
with gr .Column (variant = 'panel' ):
252
257
inp += 'depthmap_mode' , gr .HTML (visible = False , value = '0' )
@@ -341,17 +346,20 @@ def on_ui_tabs():
341
346
depthmap_mode_2 .select (lambda : '2' , None , inp ['depthmap_mode' ])
342
347
depthmap_mode_3 .select (lambda : '3' , None , inp ['depthmap_mode' ])
343
348
344
- def custom_depthmap_change_fn (turned_on ):
345
- return inp ['custom_depthmap_img' ].update (visible = turned_on ), \
346
- inp ['depthmap_gen_row_0' ].update (visible = not turned_on ), \
347
- inp ['depthmap_gen_row_1' ].update (visible = not turned_on ), \
348
- inp ['depthmap_gen_row_3' ].update (visible = not turned_on ), not turned_on
349
- inp ['custom_depthmap' ].change (
349
+ def custom_depthmap_change_fn (mode , zero_on , three_on ):
350
+ hide = mode == '0' and zero_on or mode == '3' and three_on
351
+ return inp ['custom_depthmap_img' ].update (visible = hide ), \
352
+ inp ['depthmap_gen_row_0' ].update (visible = not hide ), \
353
+ inp ['depthmap_gen_row_1' ].update (visible = not hide ), \
354
+ inp ['depthmap_gen_row_3' ].update (visible = not hide ), not hide
355
+ custom_depthmap_change_els = ['depthmap_mode' , 'custom_depthmap' , 'depthmap_vm_custom_checkbox' ]
356
+ for el in custom_depthmap_change_els :
357
+ inp [el ].change (
350
358
fn = custom_depthmap_change_fn ,
351
- inputs = [inp ['custom_depthmap' ] ],
352
- outputs = [inp [st ] for st in
353
- [ 'custom_depthmap_img' , 'depthmap_gen_row_0' , 'depthmap_gen_row_1' , 'depthmap_gen_row_3' ,
354
- go .DO_OUTPUT_DEPTH ]])
359
+ inputs = [inp [el ] for el in custom_depthmap_change_els ],
360
+ outputs = [inp [st ] for st in [
361
+ 'custom_depthmap_img' , 'depthmap_gen_row_0' , 'depthmap_gen_row_1' , 'depthmap_gen_row_3' ,
362
+ go .DO_OUTPUT_DEPTH ]])
355
363
356
364
unloadmodels .click (
357
365
fn = unload_models ,
@@ -433,7 +441,8 @@ def run_generate(*inputs):
433
441
colorvids_bitrate = inputs ['depthmap_vm_compress_bitrate' ] \
434
442
if inputs ['depthmap_vm_compress_checkbox' ] else None
435
443
ret = video_mode .gen_video (
436
- inputs ['depthmap_input_video' ], backbone .get_outpath (), inputs , custom_depthmap , colorvids_bitrate )
444
+ inputs ['depthmap_vm_input' ], backbone .get_outpath (), inputs , custom_depthmap , colorvids_bitrate ,
445
+ inputs ['depthmap_vm_smoothening_mode' ])
437
446
return [], None , None , ret
438
447
except Exception as e :
439
448
ret = format_exception (e )
0 commit comments