MCPcopy
hub / github.com/huchenlei/ComfyUI-layerdiffuse / load_file_from_url

Function load_file_from_url

lib_layerdiffusion/utils.py:95–115  ·  view source on GitHub ↗

Download a file from `url` into `model_dir`, using the file present if possible. Returns the path to the downloaded file.

(
    url: str,
    *,
    model_dir: str,
    progress: bool = True,
    file_name: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

93
94
95def load_file_from_url(
96 url: str,
97 *,
98 model_dir: str,
99 progress: bool = True,
100 file_name: Optional[str] = None,
101) -> str:
102 """Download a file from `url` into `model_dir`, using the file present if possible.
103
104 Returns the path to the downloaded file.
105 """
106 os.makedirs(model_dir, exist_ok=True)
107 if not file_name:
108 parts = urlparse(url)
109 file_name = os.path.basename(parts.path)
110 cached_file = os.path.abspath(os.path.join(model_dir, file_name))
111 if not os.path.exists(cached_file):
112 print(f'Downloading: "{url}" to {cached_file}\n')
113 from torch.hub import download_url_to_file
114 download_url_to_file(url, cached_file, progress=progress)
115 return cached_file
116
117
118def to_lora_patch_dict(state_dict: dict) -> dict:

Callers 3

decodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected