kevinwang676 commited on
Commit
1e05f4b
1 Parent(s): 3759491

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -109
app.py CHANGED
@@ -66,79 +66,6 @@ pattern = r'//www\.bilibili\.com/video[^"]*'
66
 
67
  pattern_zip = r"/([^/]+)\.zip$"
68
 
69
-
70
- #os.system("pip install fairseq")
71
- '''
72
- from fairseq import checkpoint_utils
73
-
74
- global hubert_model
75
- models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
76
- ["hubert_base.pt"],
77
- suffix="",
78
- )
79
- hubert_model = models[0]
80
- hubert_model = hubert_model.to(config.device)
81
- if config.is_half:
82
- hubert_model = hubert_model.half()
83
- else:
84
- hubert_model = hubert_model.float()
85
- hubert_model.eval()
86
- '''
87
-
88
- #from infer_rvc_python.main import load_hu_bert
89
-
90
- #load_hu_bert(config, "hubert_base.pt")
91
-
92
- from infer_rvc_python import BaseLoader
93
-
94
- #converter = BaseLoader(only_cpu=True, hubert_path="hubert_base.pt", rmvpe_path="rmvpe.pt")
95
- #converter = BaseLoader(only_cpu=True, hubert_path=None, rmvpe_path=None)
96
- '''
97
- @spaces.GPU()
98
- def convert_now(audio_files, random_tag, converter):
99
- return converter(
100
- audio_files,
101
- random_tag,
102
- overwrite=False,
103
- parallel_workers=8
104
- )
105
-
106
- converter_test = BaseLoader(only_cpu=False, hubert_path=None, rmvpe_path=None)
107
-
108
- converter_test.apply_conf(
109
- tag="yoimiya",
110
- file_model="model.pth",
111
- pitch_algo="rmvpe+",
112
- pitch_lvl=0,
113
- file_index="model.index",
114
- index_influence=0.66,
115
- respiration_median_filtering=3,
116
- envelope_ratio=0.25,
117
- consonant_breath_protection=0.33
118
- )
119
-
120
- convert_now("10.wav", "test", converter_test)
121
- '''
122
-
123
- @spaces.GPU()
124
- def load_hubert():
125
- global hubert_model
126
- from fairseq import checkpoint_utils
127
-
128
- models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
129
- ["hubert_base.pt"],
130
- suffix="",
131
- )
132
- hubert_model = models[0]
133
- hubert_model = hubert_model.to(config.device)
134
- if config.is_half:
135
- hubert_model = hubert_model.half()
136
- else:
137
- hubert_model = hubert_model.float()
138
- hubert_model.eval()
139
-
140
- load_hubert()
141
-
142
  def get_file_name(url):
143
  match = re.search(pattern_zip, url)
144
  if match:
@@ -417,11 +344,11 @@ def combine_vocal_and_inst(model_name, song_name, song_id, split_model, cover_so
417
  print(result.stdout.decode())
418
  return output_path
419
 
420
- '''
421
  def load_hubert():
 
422
  from fairseq import checkpoint_utils
423
 
424
- global hubert_model
425
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
426
  ["hubert_base.pt"],
427
  suffix="",
@@ -433,35 +360,8 @@ def load_hubert():
433
  else:
434
  hubert_model = hubert_model.float()
435
  hubert_model.eval()
436
- '''
437
- '''
438
- def load_hubert():
439
- global hubert_model
440
-
441
- # Load the model state dictionary from the file
442
- state_dict = torch.load("hubert_base.pt", map_location="cpu")
443
-
444
- # Initialize the model
445
- from fairseq.models.hubert import HubertModel
446
- hubert_model = HubertModel.build_model(state_dict['args'], task=None)
447
-
448
- # Load the state dictionary into the model
449
- hubert_model.load_state_dict(state_dict['model'])
450
-
451
- # Move the model to the desired device
452
- hubert_model = hubert_model.to("cpu")
453
-
454
- # Set the model to half precision if required
455
- if config.is_half:
456
- hubert_model = hubert_model.half()
457
- else:
458
- hubert_model = hubert_model.float()
459
-
460
- # Set the model to evaluation mode
461
- hubert_model.eval()
462
 
463
- load_hubert()
464
- '''
465
 
466
  def rvc_models(model_name):
467
  global vc, net_g, index_files, tgt_sr, version
@@ -475,7 +375,7 @@ def rvc_models(model_name):
475
  if pth_files == []:
476
  print(f"Model [{model_count}/{len(w_dirs)}]: No Model file detected, skipping...")
477
  continue
478
- cpt = torch.load(pth_files[0], map_location="cpu")
479
  tgt_sr = cpt["config"][-1]
480
  cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
481
  if_f0 = cpt.get("f0", 1)
@@ -513,7 +413,6 @@ def rvc_models(model_name):
513
  categories.append(["Models", "", models])
514
  return vc, net_g, index_files, tgt_sr, version
515
 
516
- #load_hubert()
517
 
518
  singers="您的专属AI歌手阵容:"
519
 
@@ -541,8 +440,6 @@ def infer_gpu(hubert_model, net_g, audio, f0_up_key, index_file, tgt_sr, version
541
  )
542
 
543
  def rvc_infer_music(url, model_name, song_name, split_model, f0_up_key, vocal_volume, inst_volume):
544
- #load_hubert()
545
- #print(hubert_model)
546
  url = url.strip().replace(" ", "")
547
  model_name = model_name.strip().replace(" ", "")
548
  if url.startswith('https://download.openxlab.org.cn/models/'):
@@ -552,13 +449,13 @@ def rvc_infer_music(url, model_name, song_name, split_model, f0_up_key, vocal_vo
552
  global singers
553
  if model_name not in singers:
554
  singers = singers+ ' '+ model_name
555
- print("开始下载模型...")
556
  download_online_model(url, model_name)
557
  rvc_models(zip_path)
558
  song_name = song_name.strip().replace(" ", "")
559
  video_identifier = search_bilibili(song_name)
560
  song_id = get_bilibili_video_id(video_identifier)
561
-
562
  if os.path.isdir(f"./output/{split_model}/{song_id}")==True:
563
  audio, sr = librosa.load(f"./output/{split_model}/{song_id}/vocal_{song_id}.wav_10.wav", sr=16000, mono=True)
564
  song_infer = infer_gpu(hubert_model, net_g, audio, f0_up_key, index_files[0], tgt_sr, version, f0_file=None)
 
66
 
67
  pattern_zip = r"/([^/]+)\.zip$"
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  def get_file_name(url):
70
  match = re.search(pattern_zip, url)
71
  if match:
 
344
  print(result.stdout.decode())
345
  return output_path
346
 
347
+ @spaces.GPU()
348
  def load_hubert():
349
+ global hubert_model
350
  from fairseq import checkpoint_utils
351
 
 
352
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
353
  ["hubert_base.pt"],
354
  suffix="",
 
360
  else:
361
  hubert_model = hubert_model.float()
362
  hubert_model.eval()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
+ load_hubert()
 
365
 
366
  def rvc_models(model_name):
367
  global vc, net_g, index_files, tgt_sr, version
 
375
  if pth_files == []:
376
  print(f"Model [{model_count}/{len(w_dirs)}]: No Model file detected, skipping...")
377
  continue
378
+ cpt = torch.load(pth_files[0])
379
  tgt_sr = cpt["config"][-1]
380
  cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
381
  if_f0 = cpt.get("f0", 1)
 
413
  categories.append(["Models", "", models])
414
  return vc, net_g, index_files, tgt_sr, version
415
 
 
416
 
417
  singers="您的专属AI歌手阵容:"
418
 
 
440
  )
441
 
442
  def rvc_infer_music(url, model_name, song_name, split_model, f0_up_key, vocal_volume, inst_volume):
 
 
443
  url = url.strip().replace(" ", "")
444
  model_name = model_name.strip().replace(" ", "")
445
  if url.startswith('https://download.openxlab.org.cn/models/'):
 
449
  global singers
450
  if model_name not in singers:
451
  singers = singers+ ' '+ model_name
452
+ print("1.开始下载模型")
453
  download_online_model(url, model_name)
454
  rvc_models(zip_path)
455
  song_name = song_name.strip().replace(" ", "")
456
  video_identifier = search_bilibili(song_name)
457
  song_id = get_bilibili_video_id(video_identifier)
458
+ print("2.开始去除BGM及推理")
459
  if os.path.isdir(f"./output/{split_model}/{song_id}")==True:
460
  audio, sr = librosa.load(f"./output/{split_model}/{song_id}/vocal_{song_id}.wav_10.wav", sr=16000, mono=True)
461
  song_infer = infer_gpu(hubert_model, net_g, audio, f0_up_key, index_files[0], tgt_sr, version, f0_file=None)