Upload modelFetcher.py
Browse files- modelFetcher.py +134 -0
modelFetcher.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
from tqdm import tqdm
|
4 |
+
import subprocess
|
5 |
+
import shutil
|
6 |
+
import platform
|
7 |
+
import logging
|
8 |
+
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
URL_BASE = "https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main"
|
12 |
+
models_download = [
|
13 |
+
(
|
14 |
+
"pretrained/",
|
15 |
+
[
|
16 |
+
"D32k.pth",
|
17 |
+
"D40k.pth",
|
18 |
+
"D48k.pth",
|
19 |
+
"G32k.pth",
|
20 |
+
"G40k.pth",
|
21 |
+
"G48k.pth",
|
22 |
+
"f0D32k.pth",
|
23 |
+
"f0D40k.pth",
|
24 |
+
"f0D48k.pth",
|
25 |
+
"f0G32k.pth",
|
26 |
+
"f0G40k.pth",
|
27 |
+
"f0G48k.pth",
|
28 |
+
],
|
29 |
+
),
|
30 |
+
(
|
31 |
+
"pretrained_v2/",
|
32 |
+
[
|
33 |
+
"D32k.pth",
|
34 |
+
"D40k.pth",
|
35 |
+
"D48k.pth",
|
36 |
+
"G32k.pth",
|
37 |
+
"G40k.pth",
|
38 |
+
"G48k.pth",
|
39 |
+
"f0D32k.pth",
|
40 |
+
"f0D40k.pth",
|
41 |
+
"f0D48k.pth",
|
42 |
+
"f0G32k.pth",
|
43 |
+
"f0G40k.pth",
|
44 |
+
"f0G48k.pth",
|
45 |
+
],
|
46 |
+
),
|
47 |
+
("", ["ffmpeg.exe", "ffprobe.exe"]),
|
48 |
+
]
|
49 |
+
|
50 |
+
|
51 |
+
individual_files = [
|
52 |
+
("hubert_base.pt", "assets/hubert/"),
|
53 |
+
("rmvpe.pt", "assets/rmvpe/"),
|
54 |
+
("rmvpe.onnx", "assets/rmvpe/"),
|
55 |
+
]
|
56 |
+
|
57 |
+
folder_mapping = {
|
58 |
+
"pretrained/": "assets/pretrained/",
|
59 |
+
"pretrained_v2/": "assets/pretrained_v2/",
|
60 |
+
"": "",
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
def download_file_with_progress(url, destination_path):
|
65 |
+
response = requests.get(url, stream=True)
|
66 |
+
total_size = int(response.headers.get("content-length", 0))
|
67 |
+
block_size = 1024
|
68 |
+
|
69 |
+
with open(destination_path, "wb") as file, tqdm(
|
70 |
+
desc=os.path.basename(destination_path),
|
71 |
+
total=total_size,
|
72 |
+
unit="B",
|
73 |
+
unit_scale=True,
|
74 |
+
unit_divisor=1024,
|
75 |
+
) as bar:
|
76 |
+
for data in response.iter_content(block_size):
|
77 |
+
file.write(data)
|
78 |
+
bar.update(len(data))
|
79 |
+
|
80 |
+
|
81 |
+
if not os.path.exists("torchcrepe"):
|
82 |
+
os_name = platform.system()
|
83 |
+
|
84 |
+
print("Клонирование репозитория GitHub во временную директорию...")
|
85 |
+
|
86 |
+
mingit_path = os.path.join(os.getcwd(), "lib", "tools", "mingit", "cmd", "git.exe")
|
87 |
+
|
88 |
+
if os.path.exists(mingit_path):
|
89 |
+
subprocess.run(
|
90 |
+
[
|
91 |
+
mingit_path,
|
92 |
+
"clone",
|
93 |
+
"https://github.com/maxrmorrison/torchcrepe.git",
|
94 |
+
"temp_torchcrepe",
|
95 |
+
]
|
96 |
+
)
|
97 |
+
else:
|
98 |
+
subprocess.run(
|
99 |
+
[
|
100 |
+
"git",
|
101 |
+
"clone",
|
102 |
+
"https://github.com/maxrmorrison/torchcrepe.git",
|
103 |
+
"temp_torchcrepe",
|
104 |
+
]
|
105 |
+
)
|
106 |
+
|
107 |
+
print("Копирование папки torchcrepe...")
|
108 |
+
shutil.copytree("temp_torchcrepe/torchcrepe", "./torchcrepe")
|
109 |
+
|
110 |
+
print("Удаление временной директории...")
|
111 |
+
print(os_name)
|
112 |
+
if os_name == "Windows":
|
113 |
+
subprocess.run("rmdir /s /q temp_torchcrepe", shell=True)
|
114 |
+
if os_name == "Linux":
|
115 |
+
shutil.rmtree("temp_torchcrepe")
|
116 |
+
|
117 |
+
for remote_folder, file_list in models_download:
|
118 |
+
local_folder = folder_mapping.get(remote_folder, "")
|
119 |
+
for file in file_list:
|
120 |
+
destination_path = os.path.join(local_folder, file)
|
121 |
+
url = f"{URL_BASE}/{remote_folder}{file}"
|
122 |
+
if not os.path.exists(destination_path):
|
123 |
+
print(f"Скачивание {url} в {destination_path}...")
|
124 |
+
download_file_with_progress(url, destination_path)
|
125 |
+
|
126 |
+
for file_name, local_folder in individual_files:
|
127 |
+
destination_path = os.path.join(local_folder, file_name)
|
128 |
+
url = f"{URL_BASE}/{file_name}"
|
129 |
+
if not os.path.exists(destination_path):
|
130 |
+
print(f"Скачивание {url} в {destination_path}...")
|
131 |
+
download_file_with_progress(url, destination_path)
|
132 |
+
|
133 |
+
os.system("cls" if os.name == "nt" else "clear")
|
134 |
+
logger.info("Загрузка Kanoyo успешно продолжается...")
|