helloWorld199 commited on
Commit
cab87bd
1 Parent(s): 3bed861

resilient to invalid index files

Browse files
Files changed (2) hide show
  1. src/main.py +8 -3
  2. src/vc_infer_pipeline.py +5 -2
src/main.py CHANGED
@@ -100,12 +100,17 @@ def get_rvc_model(voice_model, is_webui):
100
  for root, dirs, files in os.walk(model_dir):
101
  # Iterate over the files in the current directory
102
  for file in files:
 
103
  if file.endswith('.pth'):
104
  # Append the full path of the file to the list
105
  rvc_model_filename = os.path.join(root, file)
106
- #if file.endswith('.index'):
107
- # rvc_index_filename = file
108
-
 
 
 
 
109
  if rvc_model_filename is None:
110
  error_msg = f'No model file exists in {model_dir}.'
111
  raise_exception(error_msg, is_webui)
 
100
  for root, dirs, files in os.walk(model_dir):
101
  # Iterate over the files in the current directory
102
  for file in files:
103
+ # Check if the file has a .pth extension
104
  if file.endswith('.pth'):
105
  # Append the full path of the file to the list
106
  rvc_model_filename = os.path.join(root, file)
107
+ if file.endswith('.index'):
108
+ filename = os.path.join(root, file)
109
+ if rvc_index_filename != None:
110
+ if os.path.getsize(filename) >os.path.getsize(rvc_index_filename):
111
+ rvc_index_filename = filename
112
+ else:
113
+ rvc_index_filename = filename
114
  if rvc_model_filename is None:
115
  error_msg = f'No model file exists in {model_dir}.'
116
  raise_exception(error_msg, is_webui)
src/vc_infer_pipeline.py CHANGED
@@ -365,7 +365,7 @@ class VC(object):
365
  ) + 1
366
  f0_mel[f0_mel <= 1] = 1
367
  f0_mel[f0_mel > 255] = 255
368
- f0_coarse = np.rint(f0_mel).astype(np.int)
369
 
370
  return f0_coarse, f0bak # 1-0
371
 
@@ -504,7 +504,10 @@ class VC(object):
504
  try:
505
  index = faiss.read_index(file_index)
506
  # big_npy = np.load(file_big_npy)
507
- big_npy = index.reconstruct_n(0, index.ntotal)
 
 
 
508
  except:
509
  traceback.print_exc()
510
  index = big_npy = None
 
365
  ) + 1
366
  f0_mel[f0_mel <= 1] = 1
367
  f0_mel[f0_mel > 255] = 255
368
+ f0_coarse = np.rint(f0_mel).astype(int)
369
 
370
  return f0_coarse, f0bak # 1-0
371
 
 
504
  try:
505
  index = faiss.read_index(file_index)
506
  # big_npy = np.load(file_big_npy)
507
+ if index.ntotal == 0:
508
+ index = big_npy = None
509
+ else:
510
+ big_npy = index.reconstruct_n(0, index.ntotal)
511
  except:
512
  traceback.print_exc()
513
  index = big_npy = None