MCPcopy
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / ensure_file_downloaded

Function ensure_file_downloaded

src/misc.py:27–44  ·  view source on GitHub ↗
(filename, url, sha256_hash_prefix=None)

Source from the content-addressed store, hash-verified

25# with open(filename, 'rb', buffering=0) as f:
26# return hashlib.file_digest(f, 'sha256').hexdigest()
27def ensure_file_downloaded(filename, url, sha256_hash_prefix=None):
28 import torch
29 # Do not check the hash every time - it is somewhat time-consumin
30 if os.path.exists(filename):
31 return
32
33 if type(url) is not list:
34 url = [url]
35 for cur_url in url:
36 try:
37 print("Downloading", cur_url, "to", filename)
38 torch.hub.download_url_to_file(cur_url, filename, sha256_hash_prefix)
39 if os.path.exists(filename):
40 return # The correct model was downloaded, no need to try more
41 except:
42 pass
43 raise RuntimeError(f'Download failed. '
44 f'Try again later or manually download the file {filename} to location {url}.')

Callers 2

run_3dphotoFunction · 0.85
load_modelsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected