Aitron Emper
commited on
Commit
•
b222c00
1
Parent(s):
d2c314d
Update rvc/lib/tools/model_download.py
Browse files- rvc/lib/tools/model_download.py +80 -76
rvc/lib/tools/model_download.py
CHANGED
@@ -280,85 +280,89 @@ def unzip_file(zip_path, zip_file_name):
|
|
280 |
|
281 |
|
282 |
def model_download_pipeline(url):
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
os.rename(
|
318 |
-
os.path.join(extract_folder_path, item),
|
319 |
-
os.path.join(extract_folder_path, model_name + ".pth"),
|
320 |
-
)
|
321 |
-
else:
|
322 |
-
if "v2" not in item:
|
323 |
-
file_name = item.split("_nprobe_1_")[1].split("_v1")[0]
|
324 |
if file_name != model_name:
|
325 |
-
new_file_name = (
|
326 |
-
item.split("_nprobe_1_")[0]
|
327 |
-
+ "_nprobe_1_"
|
328 |
-
+ model_name
|
329 |
-
+ "_v1"
|
330 |
-
)
|
331 |
os.rename(
|
332 |
os.path.join(extract_folder_path, item),
|
333 |
-
os.path.join(
|
334 |
-
extract_folder_path, new_file_name + ".index"
|
335 |
-
),
|
336 |
)
|
337 |
else:
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
os.
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
sys.exit()
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
sys.exit()
|
|
|
280 |
|
281 |
|
282 |
def model_download_pipeline(url):
|
283 |
+
try:
|
284 |
+
verify = download_from_url(url)
|
285 |
+
if verify == "downloaded":
|
286 |
+
extract_folder_path = ""
|
287 |
+
for filename in os.listdir(zips_path):
|
288 |
+
if filename.endswith(".zip"):
|
289 |
+
zipfile_path = os.path.join(zips_path, filename)
|
290 |
+
print("Proceeding with the extraction...")
|
291 |
+
|
292 |
+
model_zip = os.path.basename(zipfile_path)
|
293 |
+
model_name = format_title(model_zip.split(".zip")[0])
|
294 |
+
extract_folder_path = os.path.join(
|
295 |
+
"logs",
|
296 |
+
os.path.normpath(model_name),
|
297 |
+
)
|
298 |
+
|
299 |
+
success = extract_and_show_progress(zipfile_path, extract_folder_path)
|
300 |
+
|
301 |
+
subfolders = [
|
302 |
+
f
|
303 |
+
for f in os.listdir(extract_folder_path)
|
304 |
+
if os.path.isdir(os.path.join(extract_folder_path, f))
|
305 |
+
]
|
306 |
+
if len(subfolders) == 1:
|
307 |
+
subfolder_path = os.path.join(extract_folder_path, subfolders[0])
|
308 |
+
for item in os.listdir(subfolder_path):
|
309 |
+
s = os.path.join(subfolder_path, item)
|
310 |
+
d = os.path.join(extract_folder_path, item)
|
311 |
+
shutil.move(s, d)
|
312 |
+
os.rmdir(subfolder_path)
|
313 |
+
|
314 |
+
for item in os.listdir(extract_folder_path):
|
315 |
+
if ".pth" in item:
|
316 |
+
file_name = item.split(".pth")[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
if file_name != model_name:
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
os.rename(
|
319 |
os.path.join(extract_folder_path, item),
|
320 |
+
os.path.join(extract_folder_path, model_name + ".pth"),
|
|
|
|
|
321 |
)
|
322 |
else:
|
323 |
+
if "v2" not in item:
|
324 |
+
file_name = item.split("_nprobe_1_")[1].split("_v1")[0]
|
325 |
+
if file_name != model_name:
|
326 |
+
new_file_name = (
|
327 |
+
item.split("_nprobe_1_")[0]
|
328 |
+
+ "_nprobe_1_"
|
329 |
+
+ model_name
|
330 |
+
+ "_v1"
|
331 |
+
)
|
332 |
+
os.rename(
|
333 |
+
os.path.join(extract_folder_path, item),
|
334 |
+
os.path.join(
|
335 |
+
extract_folder_path, new_file_name + ".index"
|
336 |
+
),
|
337 |
+
)
|
338 |
+
else:
|
339 |
+
file_name = item.split("_nprobe_1_")[1].split("_v2")[0]
|
340 |
+
if file_name != model_name:
|
341 |
+
new_file_name = (
|
342 |
+
item.split("_nprobe_1_")[0]
|
343 |
+
+ "_nprobe_1_"
|
344 |
+
+ model_name
|
345 |
+
+ "_v2"
|
346 |
+
)
|
347 |
+
os.rename(
|
348 |
+
os.path.join(extract_folder_path, item),
|
349 |
+
os.path.join(
|
350 |
+
extract_folder_path, new_file_name + ".index"
|
351 |
+
),
|
352 |
+
)
|
353 |
+
|
354 |
+
if success:
|
355 |
+
print(f"Model {model_name} downloaded!")
|
356 |
+
else:
|
357 |
+
print(f"Error downloading {model_name}")
|
358 |
+
sys.exit()
|
359 |
+
if extract_folder_path == "":
|
360 |
+
print("Zip file was not found.")
|
361 |
+
sys.exit()
|
362 |
+
result = search_pth_index(extract_folder_path)
|
363 |
+
else:
|
364 |
+
message = "Error"
|
365 |
sys.exit()
|
366 |
+
except Exception as error:
|
367 |
+
print(f"Error: {error}")
|
368 |
+
|
|