File size: 1,769 Bytes
41e1925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from tqdm import tqdm

MODELS = {
    "appearance_feature_extractor": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/appearance_feature_extractor.safetensors",
    "motion_extractor": "https://huggingface.co/Kijai/LivePortrait_safetensors/blob/main/motion_extractor.safetensors",
    "warping_module": "https://huggingface.co/Kijai/LivePortrait_safetensors/tree/main/warping_module.safetensors",
    "spade_generator ": "https://huggingface.co/Kijai/LivePortrait_safetensors/tree/main/spade_generator.safetensors ",
    "stitching_retargeting_module ": "https://huggingface.co/Kijai/LivePortrait_safetensors/tree/main/stitching_retargeting_module.safetensors",
}


def download_model(file_path, model_url):
    print('Downloading model...')
    response = requests.get(model_url, stream=True)
    try:
        if response.status_code == 200:
            total_size = int(response.headers.get('content-length', 0))
            block_size = 1024  # 1 Kibibyte

            # tqdm will display a progress bar
            with open(file_path, 'wb') as file, tqdm(
                    desc='Downloading',
                    total=total_size,
                    unit='iB',
                    unit_scale=True,
                    unit_divisor=1024,
            ) as bar:
                for data in response.iter_content(block_size):
                    bar.update(len(data))
                    file.write(data)

    except requests.exceptions.RequestException as e:
        print(
            f"Model Download has failed. Download manually from: {model_url}"
            f"And place in {file_path}"
        )
        raise
    except Exception as e:
        print(f'An unexpected error occurred during model download')
        raise