lllyasviel / stable-diffusion-webui-forge

GNU Affero General Public License v3.0
5.31k stars 520 forks source link

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

Open inewlife opened 2 months ago

inewlife commented 2 months ago

Is there an existing issue for this?

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加速下载

ilikeulinux commented 2 months ago

非常非常感谢