File size: 1,541 Bytes
51dc898
 
 
 
41e1925
 
 
f2a34e7
41e1925
9200e28
 
c7ac038
222faf4
f2a34e7
41e1925
 
 
51dc898
 
 
 
 
 
41e1925
222faf4
51dc898
41e1925
 
 
51dc898
 
41e1925
51dc898
41e1925
51dc898
 
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
import os.path
from typing import Optional
from torch.hub import download_url_to_file
from urllib.parse import urlparse
import requests
from tqdm import tqdm

MODELS_URL = {
    "appearance_feature_extractor": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/appearance_feature_extractor.safetensors",
    "motion_extractor": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/motion_extractor.safetensors",
    "warping_module": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/warping_module.safetensors",
    "spade_generator": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/spade_generator.safetensors",
    "stitching_retargeting_module": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/stitching_retargeting_module.safetensors",
    "face_yolov8n": "https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8n.pt"
}


def download_model(
    file_path: str,
    url: str,
) -> Optional[str]:
    if os.path.exists(file_path):
        return None
    try:
        print(f'{os.path.normpath(file_path)} is not detected. Downloading model...')
        download_url_to_file(url, file_path, progress=True)

    except requests.exceptions.RequestException as e:
        print(
            f"Model download has failed. Please download manually from: {url}\n"
            f"and place it in {file_path}"
        )
        raise e
    except Exception as e:
        print('An unexpected error occurred during model download.')
        raise e