Spaces:
Runtime error
Runtime error
Commit
·
650decf
1
Parent(s):
ceb86b8
Update app_multi.py
Browse files- app_multi.py +83 -7
app_multi.py
CHANGED
|
@@ -3,6 +3,8 @@ from typing import Union
|
|
| 3 |
from argparse import ArgumentParser
|
| 4 |
from pathlib import Path
|
| 5 |
import subprocess
|
|
|
|
|
|
|
| 6 |
|
| 7 |
import asyncio
|
| 8 |
import json
|
|
@@ -29,6 +31,8 @@ from vc_infer_pipeline import VC
|
|
| 29 |
# Reference: https://huggingface.co/spaces/zomehwh/rvc-models/blob/main/app.py#L21 # noqa
|
| 30 |
in_hf_space = getenv('SYSTEM') == 'spaces'
|
| 31 |
|
|
|
|
|
|
|
| 32 |
# Argument parsing
|
| 33 |
arg_parser = ArgumentParser()
|
| 34 |
arg_parser.add_argument(
|
|
@@ -169,6 +173,72 @@ def youtube_downloader(
|
|
| 169 |
else:
|
| 170 |
return None
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
# https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI/blob/main/infer-web.py#L118 # noqa
|
| 173 |
def vc_func(
|
| 174 |
input_audio, model_index, pitch_adjust, f0_method, feat_ratio,
|
|
@@ -340,17 +410,23 @@ with app:
|
|
| 340 |
'A lot of inspiration from what\'s already out there, including [zomehwh/rvc-models](https://huggingface.co/spaces/zomehwh/rvc-models) & [DJQmUKV/rvc-inference](https://huggingface.co/spaces/DJQmUKV/rvc-inference).\n ' # thx noqa
|
| 341 |
)
|
| 342 |
|
| 343 |
-
with gr.Tab("
|
| 344 |
with gr.Row():
|
| 345 |
with gr.Column():
|
| 346 |
-
ydl_url_input = gr.Textbox(label="
|
| 347 |
-
start = gr.Number(value=0, label="
|
| 348 |
-
end = gr.Number(value=15, label="
|
| 349 |
-
ydl_url_submit = gr.Button("
|
|
|
|
| 350 |
with gr.Column():
|
| 351 |
-
ydl_audio_output = gr.Audio(label="Audio from
|
| 352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
ydl_url_submit.click(fn=youtube_downloader, inputs=[ydl_url_input, start, end], outputs=[ydl_audio_output])
|
|
|
|
| 354 |
|
| 355 |
with gr.Row():
|
| 356 |
with gr.Column():
|
|
|
|
| 3 |
from argparse import ArgumentParser
|
| 4 |
from pathlib import Path
|
| 5 |
import subprocess
|
| 6 |
+
import librosa
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
import asyncio
|
| 10 |
import json
|
|
|
|
| 31 |
# Reference: https://huggingface.co/spaces/zomehwh/rvc-models/blob/main/app.py#L21 # noqa
|
| 32 |
in_hf_space = getenv('SYSTEM') == 'spaces'
|
| 33 |
|
| 34 |
+
high_quality = True
|
| 35 |
+
|
| 36 |
# Argument parsing
|
| 37 |
arg_parser = ArgumentParser()
|
| 38 |
arg_parser.add_argument(
|
|
|
|
| 173 |
else:
|
| 174 |
return None
|
| 175 |
|
| 176 |
+
def audio_separated(audio_input, progress=gr.Progress()):
|
| 177 |
+
# start progress
|
| 178 |
+
progress(progress=0, desc="Starting...")
|
| 179 |
+
time.sleep(0.1)
|
| 180 |
+
|
| 181 |
+
# check file input
|
| 182 |
+
if audio_input is None:
|
| 183 |
+
# show progress
|
| 184 |
+
for i in progress.tqdm(range(100), desc="Please wait..."):
|
| 185 |
+
time.sleep(0.01)
|
| 186 |
+
|
| 187 |
+
return (None, None, 'Please input audio.')
|
| 188 |
+
|
| 189 |
+
# create filename
|
| 190 |
+
filename = str(random.randint(10000,99999))+datetime.now().strftime("%d%m%Y%H%M%S")
|
| 191 |
+
|
| 192 |
+
# progress
|
| 193 |
+
progress(progress=0.10, desc="Please wait...")
|
| 194 |
+
|
| 195 |
+
# make dir output
|
| 196 |
+
os.makedirs("output", exist_ok=True)
|
| 197 |
+
|
| 198 |
+
# progress
|
| 199 |
+
progress(progress=0.20, desc="Please wait...")
|
| 200 |
+
|
| 201 |
+
# write
|
| 202 |
+
if high_quality:
|
| 203 |
+
write(filename+".wav", audio_input[0], audio_input[1])
|
| 204 |
+
else:
|
| 205 |
+
write(filename+".mp3", audio_input[0], audio_input[1])
|
| 206 |
+
|
| 207 |
+
# progress
|
| 208 |
+
progress(progress=0.50, desc="Please wait...")
|
| 209 |
+
|
| 210 |
+
# demucs process
|
| 211 |
+
if high_quality:
|
| 212 |
+
command_demucs = "python3 -m demucs --two-stems=vocals -d cpu "+filename+".wav -o output"
|
| 213 |
+
else:
|
| 214 |
+
command_demucs = "python3 -m demucs --two-stems=vocals --mp3 --mp3-bitrate 128 -d cpu "+filename+".mp3 -o output"
|
| 215 |
+
|
| 216 |
+
os.system(command_demucs)
|
| 217 |
+
|
| 218 |
+
# progress
|
| 219 |
+
progress(progress=0.70, desc="Please wait...")
|
| 220 |
+
|
| 221 |
+
# remove file audio
|
| 222 |
+
if high_quality:
|
| 223 |
+
command_delete = "rm -v ./"+filename+".wav"
|
| 224 |
+
else:
|
| 225 |
+
command_delete = "rm -v ./"+filename+".mp3"
|
| 226 |
+
|
| 227 |
+
os.system(command_delete)
|
| 228 |
+
|
| 229 |
+
# progress
|
| 230 |
+
progress(progress=0.80, desc="Please wait...")
|
| 231 |
+
|
| 232 |
+
# progress
|
| 233 |
+
for i in progress.tqdm(range(80,100), desc="Please wait..."):
|
| 234 |
+
time.sleep(0.1)
|
| 235 |
+
|
| 236 |
+
if high_quality:
|
| 237 |
+
return "./output/htdemucs/"+filename+"/vocals.wav","./output/htdemucs/"+filename+"/no_vocals.wav","Successfully..."
|
| 238 |
+
else:
|
| 239 |
+
return "./output/htdemucs/"+filename+"/vocals.mp3","./output/htdemucs/"+filename+"/no_vocals.mp3","Successfully..."
|
| 240 |
+
|
| 241 |
+
|
| 242 |
# https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI/blob/main/infer-web.py#L118 # noqa
|
| 243 |
def vc_func(
|
| 244 |
input_audio, model_index, pitch_adjust, f0_method, feat_ratio,
|
|
|
|
| 410 |
'A lot of inspiration from what\'s already out there, including [zomehwh/rvc-models](https://huggingface.co/spaces/zomehwh/rvc-models) & [DJQmUKV/rvc-inference](https://huggingface.co/spaces/DJQmUKV/rvc-inference).\n ' # thx noqa
|
| 411 |
)
|
| 412 |
|
| 413 |
+
with gr.Tab("🤗 - B站视频提取声音"):
|
| 414 |
with gr.Row():
|
| 415 |
with gr.Column():
|
| 416 |
+
ydl_url_input = gr.Textbox(label="B站视频网址(请填写相应的BV号)", value = "https://www.bilibili.com/video/BV...")
|
| 417 |
+
start = gr.Number(value=0, label="起始时间 (秒)")
|
| 418 |
+
end = gr.Number(value=15, label="结束时间 (秒)")
|
| 419 |
+
ydl_url_submit = gr.Button("提取声音文件吧", variant="primary")
|
| 420 |
+
as_audio_submit = gr.Button("去除背景音吧", variant="primary")
|
| 421 |
with gr.Column():
|
| 422 |
+
ydl_audio_output = gr.Audio(label="Audio from Bilibili")
|
| 423 |
+
as_audio_input = ydl_audio_output
|
| 424 |
+
as_audio_vocals = gr.Audio(label="Vocal only")
|
| 425 |
+
as_audio_no_vocals = gr.Audio(label="Music only", type="filepath")
|
| 426 |
+
as_audio_message = gr.Textbox(label="Message", visible=False)
|
| 427 |
+
|
| 428 |
ydl_url_submit.click(fn=youtube_downloader, inputs=[ydl_url_input, start, end], outputs=[ydl_audio_output])
|
| 429 |
+
as_audio_submit.click(fn=audio_separated, inputs=[as_audio_input], outputs=[as_audio_vocals, as_audio_no_vocals, as_audio_message], show_progress=True, queue=True)
|
| 430 |
|
| 431 |
with gr.Row():
|
| 432 |
with gr.Column():
|