mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
* fix: load image number from preset (#2611) * fix: add default_image_number to preset handling * fix: use minimum image number of preset and config to prevent UI overflow * fix: use correct base dimensions for outpaint mask padding (#2612) * fix: add Civitai compatibility for LoRAs in a1111 metadata scheme by switching schema (#2615) * feat: update sha256 generation functions https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/29be1da7cf2b5dccfc70fbdd33eb35c56a31ffb7/modules/hashes.py * feat: add compatibility for LoRAs in a1111 metadata scheme * feat: add backwards compatibility * refactor: extract remove_special_loras * fix: correctly apply LoRA weight for legacy schema * docs: bump version number to 2.3.1, add changelog (#2616) * feat:support download huggingface files from a mirror site --------- Co-authored-by: Manuel Schmid <9307310+mashb1t@users.noreply.github.com>
29 lines
969 B
Python
29 lines
969 B
Python
import os
|
|
from urllib.parse import urlparse
|
|
from typing import Optional
|
|
|
|
|
|
def load_file_from_url(
|
|
url: str,
|
|
*,
|
|
model_dir: str,
|
|
progress: bool = True,
|
|
file_name: Optional[str] = None,
|
|
) -> str:
|
|
"""Download a file from `url` into `model_dir`, using the file present if possible.
|
|
|
|
Returns the path to the downloaded file.
|
|
"""
|
|
domain = os.environ.get("HF_MIRROR", "https://huggingface.co").rstrip('/')
|
|
url = str.replace(url, "https://huggingface.co", domain, 1)
|
|
os.makedirs(model_dir, exist_ok=True)
|
|
if not file_name:
|
|
parts = urlparse(url)
|
|
file_name = os.path.basename(parts.path)
|
|
cached_file = os.path.abspath(os.path.join(model_dir, file_name))
|
|
if not os.path.exists(cached_file):
|
|
print(f'Downloading: "{url}" to {cached_file}\n')
|
|
from torch.hub import download_url_to_file
|
|
download_url_to_file(url, cached_file, progress=progress)
|
|
return cached_file
|