Aitron Emper commited on
Commit
b222c00
1 Parent(s): d2c314d

Update rvc/lib/tools/model_download.py

Browse files
Files changed (1) hide show
  1. 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
- verify = download_from_url(url)
284
- if verify == "downloaded":
285
- extract_folder_path = ""
286
- for filename in os.listdir(zips_path):
287
- if filename.endswith(".zip"):
288
- zipfile_path = os.path.join(zips_path, filename)
289
- print("Proceeding with the extraction...")
290
-
291
- model_zip = os.path.basename(zipfile_path)
292
- model_name = format_title(model_zip.split(".zip")[0])
293
- extract_folder_path = os.path.join(
294
- "logs",
295
- os.path.normpath(model_name),
296
- )
297
-
298
- success = extract_and_show_progress(zipfile_path, extract_folder_path)
299
-
300
- subfolders = [
301
- f
302
- for f in os.listdir(extract_folder_path)
303
- if os.path.isdir(os.path.join(extract_folder_path, f))
304
- ]
305
- if len(subfolders) == 1:
306
- subfolder_path = os.path.join(extract_folder_path, subfolders[0])
307
- for item in os.listdir(subfolder_path):
308
- s = os.path.join(subfolder_path, item)
309
- d = os.path.join(extract_folder_path, item)
310
- shutil.move(s, d)
311
- os.rmdir(subfolder_path)
312
-
313
- for item in os.listdir(extract_folder_path):
314
- if ".pth" in item:
315
- file_name = item.split(".pth")[0]
316
- if file_name != model_name:
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
- file_name = item.split("_nprobe_1_")[1].split("_v2")[0]
339
- if file_name != model_name:
340
- new_file_name = (
341
- item.split("_nprobe_1_")[0]
342
- + "_nprobe_1_"
343
- + model_name
344
- + "_v2"
345
- )
346
- os.rename(
347
- os.path.join(extract_folder_path, item),
348
- os.path.join(
349
- extract_folder_path, new_file_name + ".index"
350
- ),
351
- )
352
-
353
- if success:
354
- print(f"Model {model_name} downloaded!")
355
- else:
356
- print(f"Error downloading {model_name}")
357
- sys.exit()
358
- if extract_folder_path == "":
359
- print("Zip file was not found.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  sys.exit()
361
- result = search_pth_index(extract_folder_path)
362
- else:
363
- message = "Error"
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
+