Audio_separator / app.py
nevreal's picture
Create app.py
e4f5549 verified
import gradio as gr
from command import *
def downloader_conf():
return gr.Checkbox(
False,
label="URL-to-Audio",
# info="",
container=False,
)
def url_media_conf():
return gr.Textbox(
value="",
label="Enter URL",
placeholder="www.youtube.com/watch?v=g_9rPvbENUw",
visible=False,
lines=1,
)
def url_button_conf():
return gr.Button(
"Go",
variant="secondary",
visible=False,
)
def show_components_downloader(value_active):
return gr.update(
visible=value_active
), gr.update(
visible=value_active
)
def audio_conf():
return gr.File(
label="Audio file",
# file_count="multiple",
type="filepath",
container=True,
)
def stem_conf():
return gr.Radio(
choices=["vocal", "background"],
value="vocal",
label="Stem",
# info="",
)
def main_conf():
return gr.Checkbox(
False,
label="Main",
# info="",
)
def dereverb_conf():
return gr.Checkbox(
False,
label="Dereverb",
# info="",
visible=True,
)
def vocal_effects_conf():
return gr.Checkbox(
False,
label="Vocal Effects",
# info="",
visible=True,
)
def background_effects_conf():
return gr.Checkbox(
False,
label="Background Effects",
# info="",
visible=False,
)
def vocal_reverb_room_size_conf():
return gr.Number(
0.15,
label="Vocal Reverb Room Size",
minimum=0.0,
maximum=1.0,
step=0.05,
visible=True,
)
def vocal_reverb_damping_conf():
return gr.Number(
0.7,
label="Vocal Reverb Damping",
minimum=0.0,
maximum=1.0,
step=0.01,
visible=True,
)
def vocal_reverb_wet_level_conf():
return gr.Number(
0.2,
label="Vocal Reverb Wet Level",
minimum=0.0,
maximum=1.0,
step=0.05,
visible=True,
)
def vocal_reverb_dryness_level_conf():
return gr.Number(
0.8,
label="Vocal Reverb Dryness Level",
minimum=0.0,
maximum=1.0,
step=0.05,
visible=True,
)
def vocal_delay_seconds_conf():
return gr.Number(
0.,
label="Vocal Delay Seconds",
minimum=0.0,
maximum=1.0,
step=0.01,
visible=True,
)
def vocal_delay_mix_conf():
return gr.Number(
0.,
label="Vocal Delay Mix",
minimum=0.0,
maximum=1.0,
step=0.01,
visible=True,
)
def vocal_compressor_threshold_db_conf():
return gr.Number(
-15,
label="Vocal Compressor Threshold (dB)",
minimum=-60,
maximum=0,
step=1,
visible=True,
)
def vocal_compressor_ratio_conf():
return gr.Number(
4.,
label="Vocal Compressor Ratio",
minimum=0,
maximum=20,
step=0.1,
visible=True,
)
def vocal_compressor_attack_ms_conf():
return gr.Number(
1.0,
label="Vocal Compressor Attack (ms)",
minimum=0,
maximum=1000,
step=1,
visible=True,
)
def vocal_compressor_release_ms_conf():
return gr.Number(
100,
label="Vocal Compressor Release (ms)",
minimum=0,
maximum=3000,
step=1,
visible=True,
)
def vocal_gain_db_conf():
return gr.Number(
0,
label="Vocal Gain (dB)",
minimum=-40,
maximum=40,
step=1,
visible=True,
)
def background_highpass_freq_conf():
return gr.Number(
120,
label="Background Highpass Frequency (Hz)",
minimum=0,
maximum=1000,
step=1,
visible=True,
)
def background_lowpass_freq_conf():
return gr.Number(
11000,
label="Background Lowpass Frequency (Hz)",
minimum=0,
maximum=20000,
step=1,
visible=True,
)
def background_reverb_room_size_conf():
return gr.Number(
0.1,
label="Background Reverb Room Size",
minimum=0.0,
maximum=1.0,
step=0.1,
visible=True,
)
def background_reverb_damping_conf():
return gr.Number(
0.5,
label="Background Reverb Damping",
minimum=0.0,
maximum=1.0,
step=0.1,
visible=True,
)
def background_reverb_wet_level_conf():
return gr.Number(
0.25,
label="Background Reverb Wet Level",
minimum=0.0,
maximum=1.0,
step=0.05,
visible=True,
)
def background_compressor_threshold_db_conf():
return gr.Number(
-15,
label="Background Compressor Threshold (dB)",
minimum=-60,
maximum=0,
step=1,
visible=True,
)
def background_compressor_ratio_conf():
return gr.Number(
4.,
label="Background Compressor Ratio",
minimum=0,
maximum=20,
step=0.1,
visible=True,
)
def background_compressor_attack_ms_conf():
return gr.Number(
15,
label="Background Compressor Attack (ms)",
minimum=0,
maximum=1000,
step=1,
visible=True,
)
def background_compressor_release_ms_conf():
return gr.Number(
60,
label="Background Compressor Release (ms)",
minimum=0,
maximum=3000,
step=1,
visible=True,
)
def background_gain_db_conf():
return gr.Number(
0,
label="Background Gain (dB)",
minimum=-40,
maximum=40,
step=1,
visible=True,
)
def button_conf():
return gr.Button(
"Inference",
variant="primary",
)
def output_conf():
return gr.File(
label="Result",
file_count="multiple",
interactive=False,
)
def show_vocal_components(value_name):
if value_name == "vocal":
return gr.update(visible=True), gr.update(
visible=True
), gr.update(visible=True), gr.update(
visible=False
)
else:
return gr.update(visible=False), gr.update(
visible=False
), gr.update(visible=False), gr.update(
visible=True
)
def get_gui(theme):
with gr.Blocks(theme="hev832/Applio") as app:
gr.Markdown(title)
with gr.Accordion("read this", open=False):
gr.Markdown(description)
downloader_gui = downloader_conf()
with gr.Row():
with gr.Column(scale=2):
url_media_gui = url_media_conf()
with gr.Column(scale=1):
url_button_gui = url_button_conf()
downloader_gui.change(
show_components_downloader,
[downloader_gui],
[url_media_gui, url_button_gui]
)
aud = audio_conf()
url_button_gui.click(
audio_downloader,
[url_media_gui],
[aud]
)
with gr.Column():
with gr.Row():
stem_gui = stem_conf()
with gr.Column():
with gr.Row():
main_gui = main_conf()
dereverb_gui = dereverb_conf()
vocal_effects_gui = vocal_effects_conf()
background_effects_gui = background_effects_conf()
# with gr.Column():
with gr.Accordion("Vocal Effects Parameters", open=False): # with gr.Row():
# gr.Label("Vocal Effects Parameters")
with gr.Row():
vocal_reverb_room_size_gui = vocal_reverb_room_size_conf()
vocal_reverb_damping_gui = vocal_reverb_damping_conf()
vocal_reverb_dryness_gui = vocal_reverb_dryness_level_conf()
vocal_reverb_wet_level_gui = vocal_reverb_wet_level_conf()
vocal_delay_seconds_gui = vocal_delay_seconds_conf()
vocal_delay_mix_gui = vocal_delay_mix_conf()
vocal_compressor_threshold_db_gui = vocal_compressor_threshold_db_conf()
vocal_compressor_ratio_gui = vocal_compressor_ratio_conf()
vocal_compressor_attack_ms_gui = vocal_compressor_attack_ms_conf()
vocal_compressor_release_ms_gui = vocal_compressor_release_ms_conf()
vocal_gain_db_gui = vocal_gain_db_conf()
with gr.Accordion("Background Effects Parameters", open=False): # with gr.Row():
# gr.Label("Background Effects Parameters")
with gr.Row():
background_highpass_freq_gui = background_highpass_freq_conf()
background_lowpass_freq_gui = background_lowpass_freq_conf()
background_reverb_room_size_gui = background_reverb_room_size_conf()
background_reverb_damping_gui = background_reverb_damping_conf()
background_reverb_wet_level_gui = background_reverb_wet_level_conf()
background_compressor_threshold_db_gui = background_compressor_threshold_db_conf()
background_compressor_ratio_gui = background_compressor_ratio_conf()
background_compressor_attack_ms_gui = background_compressor_attack_ms_conf()
background_compressor_release_ms_gui = background_compressor_release_ms_conf()
background_gain_db_gui = background_gain_db_conf()
stem_gui.change(
show_vocal_components,
[stem_gui],
[main_gui, dereverb_gui, vocal_effects_gui, background_effects_gui],
)
button_base = button_conf()
output_base = output_conf()
button_base.click(
sound_separate,
inputs=[
aud,
stem_gui,
main_gui,
dereverb_gui,
vocal_effects_gui,
background_effects_gui,
vocal_reverb_room_size_gui, vocal_reverb_damping_gui, vocal_reverb_dryness_gui, vocal_reverb_wet_level_gui,
vocal_delay_seconds_gui, vocal_delay_mix_gui, vocal_compressor_threshold_db_gui, vocal_compressor_ratio_gui,
vocal_compressor_attack_ms_gui, vocal_compressor_release_ms_gui, vocal_gain_db_gui,
background_highpass_freq_gui, background_lowpass_freq_gui, background_reverb_room_size_gui,
background_reverb_damping_gui, background_reverb_wet_level_gui, background_compressor_threshold_db_gui,
background_compressor_ratio_gui, background_compressor_attack_ms_gui, background_compressor_release_ms_gui,
background_gain_db_gui,
],
outputs=[output_base],
)
return app
if __name__ == "__main__":
for id_model in UVR_MODELS:
download_manager(
os.path.join(MDX_DOWNLOAD_LINK, id_model), mdxnet_models_dir
)
app = get_gui(theme)
app.queue(default_concurrency_limit=40)
app.launch(
max_threads=40,
share=True,
show_error=True,
quiet=False,
debug=True,
)