Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,116 @@
|
|
1 |
import gradio as gr
|
2 |
from rvc_infer import download_online_model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def download_model(url, dir_name):
|
5 |
output_models = download_online_model(url, dir_name)
|
6 |
return dir_name
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
CSS = """
|
10 |
"""
|
11 |
|
@@ -22,6 +127,41 @@ with gr.Blocks(theme="Hev832/Applio", fill_width=True, css=CSS) as demo:
|
|
22 |
download_button = gr.Button("Download Model")
|
23 |
download_button.click(download_model, inputs=[url_input, dir_name_input], outputs=url_input)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
with gr.Tab(" Credits"):
|
26 |
gr.Markdown(
|
27 |
"""
|
@@ -37,4 +177,5 @@ with gr.Blocks(theme="Hev832/Applio", fill_width=True, css=CSS) as demo:
|
|
37 |
|
38 |
|
39 |
|
|
|
40 |
demo.launch(debug=True,show_api=False)
|
|
|
1 |
import gradio as gr
|
2 |
from rvc_infer import download_online_model
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import random
|
6 |
+
from scipy.io.wavfile import write
|
7 |
+
from scipy.io.wavfile import read
|
8 |
+
import numpy as np
|
9 |
+
import yt_dlp
|
10 |
+
import subprocess
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
|
15 |
def download_model(url, dir_name):
|
16 |
output_models = download_online_model(url, dir_name)
|
17 |
return dir_name
|
18 |
|
19 |
|
20 |
+
uvr_models = {
|
21 |
+
'BS-Roformer-Viperx-1297.ckpt': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
|
22 |
+
'MDX23C-8KFFT-InstVoc_HQ.ckpt': 'MDX23C-8KFFT-InstVoc_HQ.ckpt',
|
23 |
+
'BS-Roformer-Viperx-1053.ckpt': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt',
|
24 |
+
'Mel-Roformer-Viperx-1143.ckpt': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt',
|
25 |
+
'Kim_Vocal_2.onnx: 'Kim_Vocal_2.onnx',
|
26 |
+
'UVR-De-Echo-Aggressive.pth': 'UVR-De-Echo-Aggressive.pth',
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
output_format = [
|
34 |
+
'wav',
|
35 |
+
'flac',
|
36 |
+
'mp3',
|
37 |
+
]
|
38 |
+
|
39 |
+
mdxnet_overlap_values = [
|
40 |
+
'0.25',
|
41 |
+
'0.5',
|
42 |
+
'0.75',
|
43 |
+
'0.99',
|
44 |
+
]
|
45 |
+
|
46 |
+
vrarch_window_size_values = [
|
47 |
+
'320',
|
48 |
+
'512',
|
49 |
+
'1024',
|
50 |
+
]
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
def download_audio(url):
|
58 |
+
ydl_opts = {
|
59 |
+
'format': 'bestaudio/best',
|
60 |
+
'outtmpl': 'ytdl/%(title)s.%(ext)s',
|
61 |
+
'postprocessors': [{
|
62 |
+
'key': 'FFmpegExtractAudio',
|
63 |
+
'preferredcodec': 'wav',
|
64 |
+
'preferredquality': '192',
|
65 |
+
}],
|
66 |
+
}
|
67 |
+
|
68 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
69 |
+
info_dict = ydl.extract_info(url, download=True)
|
70 |
+
file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
|
71 |
+
sample_rate, audio_data = read(file_path)
|
72 |
+
audio_array = np.asarray(audio_data, dtype=np.int16)
|
73 |
+
|
74 |
+
return sample_rate, audio_array
|
75 |
+
|
76 |
+
def roformer_separator(roformer_audio, roformer_model, roformer_output_format, roformer_overlap, roformer_segment_size, mdx23c_denoise, mdxnet_denoise, vrarch_tta, vrarch_high_end_process):
|
77 |
+
files_list = []
|
78 |
+
files_list.clear()
|
79 |
+
directory = "./outputs"
|
80 |
+
random_id = str(random.randint(10000, 99999))
|
81 |
+
pattern = f"{random_id}"
|
82 |
+
os.makedirs("outputs", exist_ok=True)
|
83 |
+
write(f'{random_id}.wav', roformer_audio[0], roformer_audio[1])
|
84 |
+
full_roformer_model = roformer_models[roformer_model]
|
85 |
+
prompt = f"audio-separator {random_id}.wav --model_filename {full_roformer_model} --output_dir=./outputs --output_format={roformer_output_format} --normalization=0.9 --mdxc_overlap={roformer_overlap} --mdxc_segment_size={roformer_segment_size}"
|
86 |
+
|
87 |
+
if mdx23c_denoise:
|
88 |
+
prompt += " --mdx_enable_denoise"
|
89 |
+
|
90 |
+
if mdxnet_denoise:
|
91 |
+
prompt += " --mdx_enable_denoise"
|
92 |
+
|
93 |
+
|
94 |
+
if vrarch_tta:
|
95 |
+
prompt += " --vr_enable_tta"
|
96 |
+
if vrarch_high_end_process:
|
97 |
+
prompt += " --vr_high_end_process"
|
98 |
+
|
99 |
+
os.system(prompt)
|
100 |
+
|
101 |
+
for file in os.listdir(directory):
|
102 |
+
if re.search(pattern, file):
|
103 |
+
files_list.append(os.path.join(directory, file))
|
104 |
+
|
105 |
+
stem1_file = files_list[0]
|
106 |
+
stem2_file = files_list[1]
|
107 |
+
|
108 |
+
return stem1_file, stem2_file
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
CSS = """
|
115 |
"""
|
116 |
|
|
|
127 |
download_button = gr.Button("Download Model")
|
128 |
download_button.click(download_model, inputs=[url_input, dir_name_input], outputs=url_input)
|
129 |
|
130 |
+
with gr.Tab("UVR5"):
|
131 |
+
roformer_model = gr.Dropdown(
|
132 |
+
label = "Select the Model",
|
133 |
+
choices=list(uvr_models.keys()),
|
134 |
+
interactive = True
|
135 |
+
)
|
136 |
+
roformer_output_format = gr.Dropdown(
|
137 |
+
label = "Select the Output Format",
|
138 |
+
choices = output_format,
|
139 |
+
interactive = True
|
140 |
+
)
|
141 |
+
roformer_overlap = gr.Slider(
|
142 |
+
minimum = 2,
|
143 |
+
maximum = 4,
|
144 |
+
step = 1,
|
145 |
+
label = "Overlap",
|
146 |
+
info = "Amount of overlap between prediction windows.",
|
147 |
+
value = 4,
|
148 |
+
interactive = True
|
149 |
+
)
|
150 |
+
roformer_segment_size = gr.Slider(
|
151 |
+
minimum = 32,
|
152 |
+
maximum = 4000,
|
153 |
+
step = 32,
|
154 |
+
label = "Segment Size",
|
155 |
+
info = "Larger consumes more resources, but may give better results.",
|
156 |
+
value = 256,
|
157 |
+
interactive = True
|
158 |
+
)
|
159 |
+
mdx23c_denoise = gr.Checkbox(
|
160 |
+
label = "Denoise",
|
161 |
+
info = "Enable denoising during separation.",
|
162 |
+
value = False,
|
163 |
+
interactive = True
|
164 |
+
)
|
165 |
with gr.Tab(" Credits"):
|
166 |
gr.Markdown(
|
167 |
"""
|
|
|
177 |
|
178 |
|
179 |
|
180 |
+
|
181 |
demo.launch(debug=True,show_api=False)
|