jhj0517 commited on
Commit
41e1925
1 Parent(s): 71b7d31

Add model downloader

Browse files
modules/live_portrait/model_downloader.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from tqdm import tqdm
3
+
4
+ MODELS = {
5
+ "appearance_feature_extractor": "https://huggingface.co/Kijai/LivePortrait_safetensors/resolve/main/appearance_feature_extractor.safetensors",
6
+ "motion_extractor": "https://huggingface.co/Kijai/LivePortrait_safetensors/blob/main/motion_extractor.safetensors",
7
+ "warping_module": "https://huggingface.co/Kijai/LivePortrait_safetensors/tree/main/warping_module.safetensors",
8
+ "spade_generator ": "https://huggingface.co/Kijai/LivePortrait_safetensors/tree/main/spade_generator.safetensors ",
9
+ "stitching_retargeting_module ": "https://huggingface.co/Kijai/LivePortrait_safetensors/tree/main/stitching_retargeting_module.safetensors",
10
+ }
11
+
12
+
13
+ def download_model(file_path, model_url):
14
+ print('Downloading model...')
15
+ response = requests.get(model_url, stream=True)
16
+ try:
17
+ if response.status_code == 200:
18
+ total_size = int(response.headers.get('content-length', 0))
19
+ block_size = 1024 # 1 Kibibyte
20
+
21
+ # tqdm will display a progress bar
22
+ with open(file_path, 'wb') as file, tqdm(
23
+ desc='Downloading',
24
+ total=total_size,
25
+ unit='iB',
26
+ unit_scale=True,
27
+ unit_divisor=1024,
28
+ ) as bar:
29
+ for data in response.iter_content(block_size):
30
+ bar.update(len(data))
31
+ file.write(data)
32
+
33
+ except requests.exceptions.RequestException as e:
34
+ print(
35
+ f"Model Download has failed. Download manually from: {model_url}"
36
+ f"And place in {file_path}"
37
+ )
38
+ raise
39
+ except Exception as e:
40
+ print(f'An unexpected error occurred during model download')
41
+ raise
42
+