stable-diffusion-webui-forge icon indicating copy to clipboard operation
stable-diffusion-webui-forge copied to clipboard

[Feature Request]: 加快在国内下载模型的速度,同时兼容Windows加速下载

Open inewlife opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

替换所有download_url_to_file

def download_url_to_file(url, local_filename, progress=True):
    """
    Download a file from a given URL and saves it to a specified local path.
    :param progress: print download progress
    :param url: The URL of the file to download
    :param local_filename: The local path to save the file
    """
    print("Downloading file from URL: %s" % url)
    url = url.replace('huggingface.co', 'hf-mirror.com')
    with requests.get(url, stream=True) as response:
        total_size = int(response.headers.get('content-length', 0))
        response.raise_for_status()
    if total_size == 0:
        print("Unable to retrieve the file size.")
    downloaded_size = 0
    # Send a GET request and retrieve the content
    with requests.get(url, stream=True) as r:
        r.raise_for_status()  # Check the response status code, if the status code indicates an error, it throws an exception
        with open(local_filename, 'wb') as f:
            for chunk in r.iter_content(chunk_size=8192):
                f.write(chunk)
                if progress:
                    downloaded_size += len(chunk)
                    # Print progress information
                    progress_percentage = (downloaded_size / total_size) * 100
                    # Use carriage return to overwrite the content in the same line and print download progress
                    print(f"Download progress: {downloaded_size} / {total_size} "
                          f"({progress_percentage:.2f}%)", end='\r')

Proposed workflow

加快在国内下载模型的速度,同时兼容Windows加速下载

Additional information

加快在国内下载模型的速度,同时兼容Windows加速下载

inewlife avatar Apr 30 '24 09:04 inewlife

非常非常感谢

ilikeulinux avatar May 04 '24 00:05 ilikeulinux

controlnet会从hf官网下载, 请教替换哪个文件好呢?

nicevlhjfihtqngkldl avatar Aug 04 '24 11:08 nicevlhjfihtqngkldl