Spaces:
Runtime error
Runtime error
kevinwang676
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -217,7 +217,12 @@ pre_fun_hp5 = func(
|
|
217 |
)
|
218 |
|
219 |
# Separate vocals
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
221 |
def youtube_downloader(
|
222 |
video_identifier,
|
223 |
filename,
|
@@ -238,8 +243,8 @@ def youtube_downloader(
|
|
238 |
pre_fun = pre_fun_hp2
|
239 |
else:
|
240 |
pre_fun = pre_fun_hp5
|
241 |
-
|
242 |
-
pre_fun._path_audio_(audio_path, f"./output/{split_model}/{filename}/", f"./output/{split_model}/{filename}/", "wav")
|
243 |
os.remove(filename.strip()+".wav")
|
244 |
|
245 |
return f"./output/{split_model}/{filename}/vocal_{filename}.wav_10.wav", f"./output/{split_model}/{filename}/instrument_{filename}.wav_10.wav"
|
@@ -375,7 +380,7 @@ def rvc_models(model_name):
|
|
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)
|
@@ -455,12 +460,14 @@ def rvc_infer_music(url, model_name, song_name, split_model, f0_up_key, vocal_vo
|
|
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)
|
462 |
else:
|
|
|
463 |
audio, sr = librosa.load(youtube_downloader(video_identifier, song_id, split_model)[0], sr=16000, mono=True)
|
|
|
464 |
song_infer = infer_gpu(hubert_model, net_g, audio, f0_up_key, index_files[0], tgt_sr, version, f0_file=None)
|
465 |
|
466 |
sf.write(song_name.strip()+zip_path+"AI翻唱.wav", song_infer, tgt_sr)
|
|
|
217 |
)
|
218 |
|
219 |
# Separate vocals
|
220 |
+
|
221 |
+
# GPU needed
|
222 |
+
@spaces.GPU(duration=120)
|
223 |
+
def get_vocal_gpu(audio_path, split_model, filename):
|
224 |
+
return pre_fun._path_audio_(audio_path, f"./output/{split_model}/{filename}/", f"./output/{split_model}/{filename}/", "wav")
|
225 |
+
|
226 |
def youtube_downloader(
|
227 |
video_identifier,
|
228 |
filename,
|
|
|
243 |
pre_fun = pre_fun_hp2
|
244 |
else:
|
245 |
pre_fun = pre_fun_hp5
|
246 |
+
get_vocal_gpu(audio_path, split_model, filename)
|
247 |
+
#pre_fun._path_audio_(audio_path, f"./output/{split_model}/{filename}/", f"./output/{split_model}/{filename}/", "wav")
|
248 |
os.remove(filename.strip()+".wav")
|
249 |
|
250 |
return f"./output/{split_model}/{filename}/vocal_{filename}.wav_10.wav", f"./output/{split_model}/{filename}/instrument_{filename}.wav_10.wav"
|
|
|
380 |
if pth_files == []:
|
381 |
print(f"Model [{model_count}/{len(w_dirs)}]: No Model file detected, skipping...")
|
382 |
continue
|
383 |
+
cpt = torch.load(pth_files[0], map_location="cpu")
|
384 |
tgt_sr = cpt["config"][-1]
|
385 |
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
386 |
if_f0 = cpt.get("f0", 1)
|
|
|
460 |
song_name = song_name.strip().replace(" ", "")
|
461 |
video_identifier = search_bilibili(song_name)
|
462 |
song_id = get_bilibili_video_id(video_identifier)
|
|
|
463 |
if os.path.isdir(f"./output/{split_model}/{song_id}")==True:
|
464 |
+
print("2.直接开始推理")
|
465 |
audio, sr = librosa.load(f"./output/{split_model}/{song_id}/vocal_{song_id}.wav_10.wav", sr=16000, mono=True)
|
466 |
song_infer = infer_gpu(hubert_model, net_g, audio, f0_up_key, index_files[0], tgt_sr, version, f0_file=None)
|
467 |
else:
|
468 |
+
print("2.1.开始去除BGM")
|
469 |
audio, sr = librosa.load(youtube_downloader(video_identifier, song_id, split_model)[0], sr=16000, mono=True)
|
470 |
+
print("2.2.开始推理")
|
471 |
song_infer = infer_gpu(hubert_model, net_g, audio, f0_up_key, index_files[0], tgt_sr, version, f0_file=None)
|
472 |
|
473 |
sf.write(song_name.strip()+zip_path+"AI翻唱.wav", song_infer, tgt_sr)
|