kevinwang676 commited on
Commit
1b68c97
·
verified ·
1 Parent(s): 34c5f01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -41,7 +41,7 @@ from vc_infer_pipeline import VC
41
  from config import Config
42
  config = Config()
43
  logging.getLogger("numba").setLevel(logging.WARNING)
44
- spaces = True #os.getenv("SYSTEM") == "spaces"
45
  force_support = True
46
 
47
  audio_mode = []
@@ -236,8 +236,8 @@ def youtube_downloader(
236
 
237
  # Original code
238
 
239
- if force_support is False or spaces is True:
240
- if spaces is True:
241
  audio_mode = ["Upload audio", "TTS Audio"]
242
  else:
243
  audio_mode = ["Input path", "Upload audio", "TTS Audio"]
@@ -278,7 +278,7 @@ def create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, file_index):
278
  return "You need to upload an audio", None
279
  sampling_rate, audio = vc_upload
280
  duration = audio.shape[0] / sampling_rate
281
- if duration > 20 and spaces:
282
  return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None
283
  audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
284
  if len(audio.shape) > 1:
@@ -390,6 +390,7 @@ singers="您的专属AI歌手阵容:"
390
 
391
  @spaces.GPU(duration=120)
392
  def rvc_infer_music_gpu(zip_path, song_name, song_id, split_model, f0_up_key, vocal_volume, inst_volume):
 
393
  from fairseq import checkpoint_utils
394
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
395
  ["hubert_base.pt"],
@@ -402,9 +403,10 @@ def rvc_infer_music_gpu(zip_path, song_name, song_id, split_model, f0_up_key, vo
402
  else:
403
  hubert_model = hubert_model.float()
404
  hubert_model.eval()
 
405
  rvc_models(zip_path)
406
-
407
  if os.path.isdir(f"./output/{split_model}/{song_id}")==True:
 
408
  audio, sr = librosa.load(f"./output/{split_model}/{song_id}/vocal_{song_id}.wav_10.wav", sr=16000, mono=True)
409
  song_infer = vc.pipeline(
410
  hubert_model,
@@ -427,7 +429,9 @@ def rvc_infer_music_gpu(zip_path, song_name, song_id, split_model, f0_up_key, vo
427
  f0_file=None,
428
  )
429
  else:
 
430
  audio, sr = librosa.load(youtube_downloader(song_id, split_model)[0], sr=16000, mono=True)
 
431
  song_infer = vc.pipeline(
432
  hubert_model,
433
  net_g,
@@ -463,6 +467,7 @@ def rvc_infer_music(url, model_name, song_name, split_model, f0_up_key, vocal_vo
463
  global singers
464
  if model_name not in singers:
465
  singers = singers+ ' '+ model_name
 
466
  download_online_model(url, model_name)
467
  song_name = song_name.strip().replace(" ", "")
468
  video_identifier = search_bilibili(song_name)
@@ -471,6 +476,7 @@ def rvc_infer_music(url, model_name, song_name, split_model, f0_up_key, vocal_vo
471
  video_info = get_video_info(video_identifier)
472
  print(video_info)
473
  audio_content = get_response(video_info).content
 
474
  with open(song_id.strip() + ".wav", mode="wb") as f:
475
  f.write(audio_content)
476
  output_full_song, singers = rvc_infer_music_gpu(zip_path, song_name, song_id, split_model, f0_up_key, vocal_volume, inst_volume)
 
41
  from config import Config
42
  config = Config()
43
  logging.getLogger("numba").setLevel(logging.WARNING)
44
+ spaces_hf = True #os.getenv("SYSTEM") == "spaces"
45
  force_support = True
46
 
47
  audio_mode = []
 
236
 
237
  # Original code
238
 
239
+ if force_support is False or spaces_hf is True:
240
+ if spaces_hf is True:
241
  audio_mode = ["Upload audio", "TTS Audio"]
242
  else:
243
  audio_mode = ["Input path", "Upload audio", "TTS Audio"]
 
278
  return "You need to upload an audio", None
279
  sampling_rate, audio = vc_upload
280
  duration = audio.shape[0] / sampling_rate
281
+ if duration > 20 and spaces_hf:
282
  return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None
283
  audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
284
  if len(audio.shape) > 1:
 
390
 
391
  @spaces.GPU(duration=120)
392
  def rvc_infer_music_gpu(zip_path, song_name, song_id, split_model, f0_up_key, vocal_volume, inst_volume):
393
+ print("3.开始加载HuBert模型...")
394
  from fairseq import checkpoint_utils
395
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
396
  ["hubert_base.pt"],
 
403
  else:
404
  hubert_model = hubert_model.float()
405
  hubert_model.eval()
406
+ print("3.开始加载AI歌手模型参数...")
407
  rvc_models(zip_path)
 
408
  if os.path.isdir(f"./output/{split_model}/{song_id}")==True:
409
+ print("4.直接开始推理")
410
  audio, sr = librosa.load(f"./output/{split_model}/{song_id}/vocal_{song_id}.wav_10.wav", sr=16000, mono=True)
411
  song_infer = vc.pipeline(
412
  hubert_model,
 
429
  f0_file=None,
430
  )
431
  else:
432
+ print("4.1.开始去除BGM")
433
  audio, sr = librosa.load(youtube_downloader(song_id, split_model)[0], sr=16000, mono=True)
434
+ print("4.1.开始推理")
435
  song_infer = vc.pipeline(
436
  hubert_model,
437
  net_g,
 
467
  global singers
468
  if model_name not in singers:
469
  singers = singers+ ' '+ model_name
470
+ print("1.开始下载AI歌手模型...")
471
  download_online_model(url, model_name)
472
  song_name = song_name.strip().replace(" ", "")
473
  video_identifier = search_bilibili(song_name)
 
476
  video_info = get_video_info(video_identifier)
477
  print(video_info)
478
  audio_content = get_response(video_info).content
479
+ print("2.开始下载AI翻唱歌曲...")
480
  with open(song_id.strip() + ".wav", mode="wb") as f:
481
  f.write(audio_content)
482
  output_full_song, singers = rvc_infer_music_gpu(zip_path, song_name, song_id, split_model, f0_up_key, vocal_volume, inst_volume)