Skip to content

Commit 381536d

Browse files
committed
Minor fixes
1 parent 3fa9185 commit 381536d

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ images generated by [@semjon00](https://github.com/semjon00) from CC0 photos, mo
2323
## Changelog
2424
* v0.4.0 large code refactor
2525
* UI improvements
26+
* improved Batch from Directory, Clip and renormalize DepthMap
2627
* slightly changed the behaviour of various options
2728
* extension may partially work even if some of the dependencies are unmet
2829
* v0.3.12

scripts/depthmap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def main_ui_panel(is_depth_tab):
136136
value='u2net', type="value")
137137

138138
with gr.Box():
139+
gr.HTML(f"{SCRIPT_FULL_NAME}<br/>")
139140
gr.HTML("Information, comment and share @ <a "
140141
"href='https://github.com/thygate/stable-diffusion-webui-depthmap-script'>"
141142
"https://github.com/thygate/stable-diffusion-webui-depthmap-script</a>")
@@ -480,6 +481,8 @@ def run_generate(*inputs):
480481
outpath = opts.outdir_samples or opts.outdir_extras_samples
481482

482483
if depthmap_mode == '0': # Single image
484+
if depthmap_input_image is None:
485+
return [], None, None, "Please select an input image!", ""
483486
inputimages.append(depthmap_input_image)
484487
inputnames.append(None)
485488
if custom_depthmap:
@@ -490,6 +493,8 @@ def run_generate(*inputs):
490493
else:
491494
inputdepthmaps.append(None)
492495
if depthmap_mode == '1': # Batch Process
496+
if image_batch is None:
497+
return [], None, None, "Please select input images!", ""
493498
for img in image_batch:
494499
image = Image.open(os.path.abspath(img.name))
495500
inputimages.append(image)

src/core.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
9898
stereo_separation = inp["stereo_separation"]
9999

100100
# TODO: ideally, run_depthmap should not save meshes - that makes the function not pure
101-
print(f"{SCRIPT_NAME} {SCRIPT_VERSION} ({get_commit_hash()})")
101+
print(SCRIPT_FULL_NAME)
102102

103103
unload_sd_model()
104104

@@ -649,24 +649,6 @@ def batched_background_removal(inimages, model_name):
649649
return outimages
650650

651651

652-
def ensure_file_downloaded(filename, url, sha256_hash_prefix=None):
653-
# Do not check the hash every time - it is somewhat time-consuming
654-
if os.path.exists(filename):
655-
return
656-
657-
if type(url) is not list:
658-
url = [url]
659-
for cur_url in url:
660-
try:
661-
print("Downloading", cur_url, "to", filename)
662-
torch.hub.download_url_to_file(cur_url, filename, sha256_hash_prefix)
663-
if os.path.exists(filename):
664-
return # The correct model was downloaded, no need to try more
665-
except:
666-
pass
667-
raise RuntimeError('Download failed. Try again later or manually download the file to that location.')
668-
669-
670652
def pano_depth_to_world_points(depth):
671653
"""
672654
360 depth to world points

src/main.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@
33
import pathlib
44
import torch
55

6+
def get_commit_hash():
7+
try:
8+
return subprocess.check_output(
9+
[os.environ.get("GIT", "git"), "rev-parse", "HEAD"],
10+
cwd=pathlib.Path.cwd().joinpath('extensions/stable-diffusion-webui-depthmap-script/'),
11+
shell=False,
12+
stderr=subprocess.DEVNULL,
13+
encoding='utf8').strip()[0:8]
14+
except Exception:
15+
return "<none>"
16+
17+
618
SCRIPT_NAME = "DepthMap"
719
SCRIPT_VERSION = "v0.4.0"
8-
9-
commit_hash = None # TODO: understand why it would spam to stderr if changed to ... = get_commit_hash()
10-
def get_commit_hash():
11-
global commit_hash
12-
if commit_hash is None:
13-
try:
14-
commit_hash = subprocess.check_output(
15-
[os.environ.get('GIT', "git"), "rev-parse", "HEAD"],
16-
cwd=pathlib.Path.cwd().joinpath('extensions/stable-diffusion-webui-depthmap-script/'),
17-
shell=False,
18-
stderr=subprocess.DEVNULL,
19-
encoding='utf8').strip()[0:8]
20-
except Exception:
21-
commit_hash = "<none>"
22-
return commit_hash
20+
SCRIPT_FULL_NAME = f"{SCRIPT_NAME} {SCRIPT_VERSION} ({get_commit_hash()})"
2321

2422

2523
def ensure_file_downloaded(filename, url, sha256_hash_prefix=None):

0 commit comments

Comments
 (0)