@@ -25,6 +25,13 @@ def ensure_gradio_temp_directory():
25
25
26
26
27
27
def main_ui_panel (is_depth_tab ):
28
+
29
+ is_gradio4 = int (gr .__version__ [0 ])> 3
30
+ if is_gradio4 :
31
+ Box = gr .Group
32
+ else :
33
+ Box = gr .Box
34
+
28
35
inp = GradioComponentBundle ()
29
36
# TODO: Greater visual separation
30
37
with gr .Blocks ():
@@ -41,7 +48,7 @@ def main_ui_panel(is_depth_tab):
41
48
'Marigold v1' , 'Depth Anything' , 'Depth Anything v2 Small' ,
42
49
'Depth Anything v2 Base' , 'Depth Anything v2 Large' ],
43
50
value = 'Depth Anything v2 Base' , type = "index" )
44
- with gr . Box () as cur_option_root :
51
+ with Box () as cur_option_root :
45
52
inp -= 'depthmap_gen_row_1' , cur_option_root
46
53
with gr .Row ():
47
54
inp += go .BOOST , gr .Checkbox (label = "BOOST" ,
@@ -57,7 +64,7 @@ def main_ui_panel(is_depth_tab):
57
64
label = 'Tiling mode' , info = 'Reduces seams that appear if the depthmap is tiled into a grid'
58
65
)
59
66
60
- with gr . Box () as cur_option_root :
67
+ with Box () as cur_option_root :
61
68
inp -= 'depthmap_gen_row_2' , cur_option_root
62
69
with gr .Row ():
63
70
with gr .Group (): # 50% of width
@@ -71,7 +78,7 @@ def main_ui_panel(is_depth_tab):
71
78
inp += go .OUTPUT_DEPTH_COMBINE_AXIS , gr .Radio (
72
79
label = "Combine axis" , choices = ['Vertical' , 'Horizontal' ], type = "value" , visible = False )
73
80
74
- with gr . Box () as cur_option_root :
81
+ with Box () as cur_option_root :
75
82
inp -= 'depthmap_gen_row_3' , cur_option_root
76
83
with gr .Row ():
77
84
inp += go .CLIPDEPTH , gr .Checkbox (label = "Clip and renormalize DepthMap" )
@@ -81,7 +88,7 @@ def main_ui_panel(is_depth_tab):
81
88
inp += go .CLIPDEPTH_FAR , gr .Slider (minimum = 0 , maximum = 1 , step = 0.001 , label = 'Far clip' )
82
89
inp += go .CLIPDEPTH_NEAR , gr .Slider (minimum = 0 , maximum = 1 , step = 0.001 , label = 'Near clip' )
83
90
84
- with gr . Box ():
91
+ with Box ():
85
92
with gr .Row ():
86
93
inp += go .GEN_STEREO , gr .Checkbox (label = "Generate stereoscopic (3D) image(s)" )
87
94
with gr .Column (visible = False ) as stereo_options :
@@ -104,7 +111,7 @@ def main_ui_panel(is_depth_tab):
104
111
inp += go .STEREO_BALANCE , gr .Slider (minimum = - 1.0 , maximum = 1.0 , step = 0.05 ,
105
112
label = 'Balance between eyes' )
106
113
107
- with gr . Box ():
114
+ with Box ():
108
115
with gr .Row ():
109
116
inp += go .GEN_NORMALMAP , gr .Checkbox (label = "Generate NormalMap" )
110
117
with gr .Column (visible = False ) as normalmap_options :
@@ -124,11 +131,11 @@ def main_ui_panel(is_depth_tab):
124
131
inp += go .NORMALMAP_INVERT , gr .Checkbox (label = "Invert" )
125
132
126
133
if backbone .get_opt ('depthmap_script_gen_heatmap_from_ui' , False ):
127
- with gr . Box ():
134
+ with Box ():
128
135
with gr .Row ():
129
136
inp += go .GEN_HEATMAP , gr .Checkbox (label = "Generate HeatMap" )
130
137
131
- with gr . Box ():
138
+ with Box ():
132
139
with gr .Column ():
133
140
inp += go .GEN_SIMPLE_MESH , gr .Checkbox (label = "Generate simple 3D mesh" )
134
141
with gr .Column (visible = False ) as mesh_options :
@@ -139,7 +146,7 @@ def main_ui_panel(is_depth_tab):
139
146
inp += go .SIMPLE_MESH_SPHERICAL , gr .Checkbox (label = "Equirectangular projection" )
140
147
141
148
if is_depth_tab :
142
- with gr . Box ():
149
+ with Box ():
143
150
with gr .Column ():
144
151
inp += go .GEN_INPAINTED_MESH , gr .Checkbox (
145
152
label = "Generate 3D inpainted mesh" )
@@ -149,7 +156,7 @@ def main_ui_panel(is_depth_tab):
149
156
label = "Generate 4 demo videos with 3D inpainted mesh." )
150
157
gr .HTML ("More options for generating video can be found in the Generate video tab." )
151
158
152
- with gr . Box ():
159
+ with Box ():
153
160
# TODO: it should be clear from the UI that there is an option of the background removal
154
161
# that does not use the model selected above
155
162
with gr .Row ():
@@ -163,33 +170,49 @@ def main_ui_panel(is_depth_tab):
163
170
label = "Rembg Model" , type = "value" ,
164
171
choices = ['u2net' , 'u2netp' , 'u2net_human_seg' , 'silueta' , "isnet-general-use" , "isnet-anime" ])
165
172
166
- with gr . Box ():
173
+ with Box ():
167
174
gr .HTML (f"{ SCRIPT_FULL_NAME } <br/>" )
168
175
gr .HTML ("Information, comment and share @ <a "
169
176
"href='https://github.com/thygate/stable-diffusion-webui-depthmap-script'>"
170
177
"https://github.com/thygate/stable-diffusion-webui-depthmap-script</a>" )
171
178
172
179
def update_default_net_size (model_type ):
173
180
w , h = ModelHolder .get_default_net_size (model_type )
174
- return inp [go .NET_WIDTH ].update (value = w ), inp [go .NET_HEIGHT ].update (value = h )
175
-
181
+ if is_gradio4 :
182
+ return gr .Slider (step = w ), gr .Slider (step = h )
183
+ else :
184
+ return inp [go .NET_WIDTH ].update (value = w ), inp [go .NET_HEIGHT ].update (value = h )
185
+
176
186
inp [go .MODEL_TYPE ].change (
177
187
fn = update_default_net_size ,
178
188
inputs = inp [go .MODEL_TYPE ],
179
189
outputs = [inp [go .NET_WIDTH ], inp [go .NET_HEIGHT ]]
180
190
)
191
+ def update_boost (a , b ):
192
+ if is_gradio4 :
193
+ return (gr .Checkbox (visible = not a ), gr .Row (visible = not a and not b ))
194
+ else :
195
+ return (inp [go .NET_SIZE_MATCH ].update (visible = not a ),
196
+ options_depend_on_match_size .update (visible = not a and not b ))
181
197
182
198
inp [go .BOOST ].change ( # Go boost! Wroom!..
183
- fn = lambda a , b : (inp [go .NET_SIZE_MATCH ].update (visible = not a ),
184
- options_depend_on_match_size .update (visible = not a and not b )),
199
+ fn = update_boost ,
185
200
inputs = [inp [go .BOOST ], inp [go .NET_SIZE_MATCH ]],
186
201
outputs = [inp [go .NET_SIZE_MATCH ], options_depend_on_match_size ]
187
202
)
188
203
inp .add_rule (options_depend_on_match_size , 'visible-if-not' , go .NET_SIZE_MATCH )
204
+
205
+ def update_tiling (a ):
206
+ if is_gradio4 :
207
+ if a :
208
+ return (gr .Checkbox (value = False ), gr .Checkbox (value = True ))
209
+ return (inp [go .BOOST ], inp [go .NET_SIZE_MATCH ])
210
+ else :
211
+ (inp [go .BOOST ].update (value = False ), inp [go .NET_SIZE_MATCH ].update (value = True )
212
+ ) if a else (inp [go .BOOST ].update (), inp [go .NET_SIZE_MATCH ].update ())
213
+
189
214
inp [go .TILING_MODE ].change ( # Go boost! Wroom!..
190
- fn = lambda a : (
191
- inp [go .BOOST ].update (value = False ), inp [go .NET_SIZE_MATCH ].update (value = True )
192
- ) if a else (inp [go .BOOST ].update (), inp [go .NET_SIZE_MATCH ].update ()),
215
+ fn = update_tiling ,
193
216
inputs = [inp [go .TILING_MODE ]],
194
217
outputs = [inp [go .BOOST ], inp [go .NET_SIZE_MATCH ]]
195
218
)
@@ -248,13 +271,13 @@ def depthmap_mode_video(inp):
248
271
"pick settings so that the generation is not too slow. For the best results, "
249
272
"use a zoedepth model, since they provide the highest level of coherency between frames." )
250
273
inp += gr .File (elem_id = 'depthmap_vm_input' , label = "Video or animated file" ,
251
- file_count = "single" , interactive = True , type = "file " )
274
+ file_count = "single" , interactive = True , type = "binary " )
252
275
inp += gr .Checkbox (elem_id = "depthmap_vm_custom_checkbox" ,
253
276
label = "Use custom/pregenerated DepthMap video" , value = False )
254
277
inp += gr .Dropdown (elem_id = "depthmap_vm_smoothening_mode" , label = "Smoothening" ,
255
278
type = "value" , choices = ['none' , 'experimental' ], value = 'experimental' )
256
279
inp += gr .File (elem_id = 'depthmap_vm_custom' , file_count = "single" ,
257
- interactive = True , type = "file " , visible = False )
280
+ interactive = True , type = "binary " , visible = False )
258
281
with gr .Row ():
259
282
inp += gr .Checkbox (elem_id = 'depthmap_vm_compress_checkbox' , label = "Compress colorvideos?" , value = False )
260
283
inp += gr .Slider (elem_id = 'depthmap_vm_compress_bitrate' , label = "Bitrate (kbit)" , visible = False ,
@@ -287,11 +310,11 @@ def on_ui_tabs():
287
310
elem_id = "depthmap_input_image" )
288
311
# TODO: depthmap generation settings should disappear when using this
289
312
inp += gr .File (label = "Custom DepthMap" , file_count = "single" , interactive = True ,
290
- type = "file " , elem_id = 'custom_depthmap_img' , visible = False )
313
+ type = "binary " , elem_id = 'custom_depthmap_img' , visible = False )
291
314
inp += gr .Checkbox (elem_id = "custom_depthmap" , label = "Use custom DepthMap" , value = False )
292
315
with gr .TabItem ('Batch Process' ) as depthmap_mode_1 :
293
316
inp += gr .File (elem_id = 'image_batch' , label = "Batch Process" , file_count = "multiple" ,
294
- interactive = True , type = "file " )
317
+ interactive = True , type = "binary " )
295
318
with gr .TabItem ('Batch from Directory' ) as depthmap_mode_2 :
296
319
inp += gr .Textbox (elem_id = "depthmap_batch_input_dir" , label = "Input directory" ,
297
320
** backbone .get_hide_dirs (),
@@ -370,12 +393,20 @@ def on_ui_tabs():
370
393
depthmap_mode_2 .select (lambda : '2' , None , inp ['depthmap_mode' ])
371
394
depthmap_mode_3 .select (lambda : '3' , None , inp ['depthmap_mode' ])
372
395
396
+ is_gradio4 = int (gr .__version__ [0 ])> 3
373
397
def custom_depthmap_change_fn (mode , zero_on , three_on ):
374
398
hide = mode == '0' and zero_on or mode == '3' and three_on
375
- return inp ['custom_depthmap_img' ].update (visible = hide ), \
376
- inp ['depthmap_gen_row_0' ].update (visible = not hide ), \
377
- inp ['depthmap_gen_row_1' ].update (visible = not hide ), \
378
- inp ['depthmap_gen_row_3' ].update (visible = not hide ), not hide
399
+ if is_gradio4 :
400
+ return gr .Row (visible = hide ), \
401
+ gr .Group (visible = not hide ), \
402
+ gr .Group (visible = not hide ), \
403
+ gr .Group (visible = not hide ), not hide
404
+ else :
405
+ return inp ['custom_depthmap_img' ].update (visible = hide ), \
406
+ inp ['depthmap_gen_row_0' ].update (visible = not hide ), \
407
+ inp ['depthmap_gen_row_1' ].update (visible = not hide ), \
408
+ inp ['depthmap_gen_row_3' ].update (visible = not hide ), not hide
409
+
379
410
custom_depthmap_change_els = ['depthmap_mode' , 'custom_depthmap' , 'depthmap_vm_custom_checkbox' ]
380
411
for el in custom_depthmap_change_els :
381
412
inp [el ].change (
0 commit comments