Skip to content

Commit 0a96097

Browse files
committed
Add folder button, cmd_opts bugfix
1 parent 1a64c6a commit 0a96097

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/backbone.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212

1313
def get_opt(name, default):
1414
from modules.shared import opts
15-
1615
if hasattr(opts, name):
1716
return opts.__getattr__(name)
1817
return default
1918

19+
def get_cmd_opt(name, default):
20+
"""Get command line argument"""
21+
from modules.shared import cmd_opts
22+
if hasattr(cmd_opts, name):
23+
return cmd_opts.__getattribute__(name)
24+
return default
2025

2126
def gather_ops():
27+
"""Parameters for depthmap generation"""
2228
from modules.shared import cmd_opts
2329
ops = {}
2430
if get_opt('depthmap_script_boost_rmax', None) is not None:
@@ -29,6 +35,7 @@ def gather_ops():
2935

3036

3137
def get_outpath():
38+
"""Get path where results are saved by default"""
3239
path = get_opt('outdir_samples', None)
3340
if path is None or len(path) == 0:
3441
path = get_opt('outdir_extras_samples', None)
@@ -87,6 +94,9 @@ def listfiles(dirname):
8794

8895
def get_opt(name, default): return default # Configuring is not supported
8996

97+
98+
def get_cmd_opt(name, default): return default # Configuring is not supported
99+
90100
def gather_ops(): return {} # Configuring is not supported
91101

92102
def get_outpath(): return '.'

src/common_ui.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ def update_delault_net_size(model_type):
217217

218218
return inp
219219

220+
def open_folder_action():
221+
# Adapted from stable-diffusion-webui
222+
f = backbone.get_outpath()
223+
if backbone.get_cmd_opt('hide_ui_dir_config', False):
224+
return
225+
if not os.path.exists(f) or not os.path.isdir(f):
226+
raise "Couldn't open output folder" # .isdir is security-related, do not remove!
227+
import platform
228+
import subprocess as sp
229+
path = os.path.normpath(f)
230+
if platform.system() == "Windows":
231+
os.startfile(path)
232+
elif platform.system() == "Darwin":
233+
sp.Popen(["open", path])
234+
elif "microsoft-standard-WSL2" in platform.uname().release:
235+
sp.Popen(["wsl-open", path])
236+
else:
237+
sp.Popen(["xdg-open", path])
238+
220239
def on_ui_tabs():
221240
inp = GradioComponentBundle()
222241
with gr.Blocks(analytics_enabled=False, title="DepthMap") as depthmap_interface:
@@ -260,6 +279,10 @@ def on_ui_tabs():
260279
elem_id=f"depthmap_gallery").style(grid=4)
261280
with gr.Column():
262281
html_info = gr.HTML()
282+
folder_symbol = '\U0001f4c2' # 📂
283+
gr.Button(folder_symbol, visible=not backbone.get_cmd_opt('hide_ui_dir_config', False)).click(
284+
fn=lambda: open_folder_action(), inputs=[], outputs=[],
285+
)
263286

264287
with gr.TabItem('3D Mesh'):
265288
with gr.Group():
@@ -301,6 +324,7 @@ def on_ui_tabs():
301324
submit_vid = gr.Button('Generate Video', elem_id="depthmap_generatevideo",
302325
variant='primary')
303326

327+
304328
inp += inp.enkey_tail()
305329

306330
depthmap_mode_0.select(lambda: '0', None, inp['depthmap_mode'])
@@ -401,7 +425,7 @@ def run_generate(*inputs):
401425
inputimages.append(image)
402426
inputnames.append(os.path.splitext(img.orig_name)[0])
403427
elif depthmap_mode == '2': # Batch from Directory
404-
assert not backbone.get_opt('hide_ui_dir_config', False), '--hide-ui-dir-config option must be disabled'
428+
assert not backbone.get_cmd_opt('hide_ui_dir_config', False), '--hide-ui-dir-config option must be disabled'
405429
if depthmap_batch_input_dir == '':
406430
return [], None, None, "Please select an input directory."
407431
if depthmap_batch_input_dir == depthmap_batch_output_dir:

src/depthmap_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def reload(self):
253253
"""Undoes offload"""
254254
if self.offloaded:
255255
self.move_models_to(self.device)
256-
self.offloaded = True
256+
self.offloaded = False
257257

258258
def move_models_to(self, device):
259259
if self.depth_model is not None:

0 commit comments

Comments
 (0)