Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,22 +141,23 @@ def prepare_output_dir(input_file, output_dir):
|
|
| 141 |
raise RuntimeError(f"Failed to prepare output directory {out_dir}: {e}")
|
| 142 |
return out_dir
|
| 143 |
|
| 144 |
-
def rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem):
|
| 145 |
base_name = os.path.splitext(os.path.basename(audio))[0]
|
| 146 |
stems = {
|
| 147 |
-
"Vocals": vocals_stem.replace("
|
| 148 |
-
"Instrumental": instrumental_stem.replace("
|
| 149 |
-
"Drums": drums_stem.replace("
|
| 150 |
-
"Bass": bass_stem.replace("
|
| 151 |
-
"Other": other_stem.replace("
|
| 152 |
-
"Guitar": guitar_stem.replace("
|
| 153 |
-
"Piano": piano_stem.replace("
|
| 154 |
}
|
| 155 |
return stems
|
| 156 |
|
|
|
|
| 157 |
def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 158 |
"""Separate audio using Roformer model."""
|
| 159 |
-
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem)
|
| 160 |
print_message(audio, model_key)
|
| 161 |
model = ROFORMER_MODELS[model_key]
|
| 162 |
try:
|
|
@@ -192,7 +193,7 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
|
|
| 192 |
|
| 193 |
def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 194 |
"""Separate audio using MDX23C model."""
|
| 195 |
-
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem)
|
| 196 |
print_message(audio, model)
|
| 197 |
try:
|
| 198 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
@@ -227,7 +228,7 @@ def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_s
|
|
| 227 |
|
| 228 |
def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 229 |
"""Separate audio using MDX-NET model."""
|
| 230 |
-
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem)
|
| 231 |
print_message(audio, model)
|
| 232 |
try:
|
| 233 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
@@ -262,7 +263,7 @@ def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_di
|
|
| 262 |
|
| 263 |
def vr_separator(audio, model, window_size, aggression, tta, post_process, post_process_threshold, high_end_process, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 264 |
"""Separate audio using VR ARCH model."""
|
| 265 |
-
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem)
|
| 266 |
print_message(audio, model)
|
| 267 |
try:
|
| 268 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
@@ -299,7 +300,7 @@ def vr_separator(audio, model, window_size, aggression, tta, post_process, post_
|
|
| 299 |
|
| 300 |
def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 301 |
"""Separate audio using Demucs model."""
|
| 302 |
-
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem)
|
| 303 |
print_message(audio, model)
|
| 304 |
try:
|
| 305 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
@@ -327,7 +328,7 @@ def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled,
|
|
| 327 |
print(f"Separation complete!\nResults: {', '.join(separation)}")
|
| 328 |
|
| 329 |
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
| 330 |
-
|
| 331 |
if model == "htdemucs_6s.yaml":
|
| 332 |
return stems[0], stems[1], stems[2], stems[3], stems[4], stems[5]
|
| 333 |
else:
|
|
@@ -335,12 +336,7 @@ def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled,
|
|
| 335 |
except Exception as e:
|
| 336 |
raise RuntimeError(f"Demucs separation failed: {e}") from e
|
| 337 |
|
| 338 |
-
|
| 339 |
-
if model == "htdemucs_6s.yaml":
|
| 340 |
-
return gr.update(visible=True)
|
| 341 |
-
else:
|
| 342 |
-
return gr.update(visible=False)
|
| 343 |
-
|
| 344 |
with gr.Blocks(
|
| 345 |
title="🎵 PolUVR 🎵",
|
| 346 |
css="footer{display:none !important}",
|
|
@@ -437,7 +433,6 @@ with gr.Blocks(
|
|
| 437 |
with gr.Row():
|
| 438 |
demucs_stem1 = gr.Audio(label="Stem 1", type="filepath", interactive=False)
|
| 439 |
demucs_stem2 = gr.Audio(label="Stem 2", type="filepath", interactive=False)
|
| 440 |
-
with gr.Row():
|
| 441 |
demucs_stem3 = gr.Audio(label="Stem 3", type="filepath", interactive=False)
|
| 442 |
demucs_stem4 = gr.Audio(label="Stem 4", type="filepath", interactive=False)
|
| 443 |
with gr.Row(visible=False) as stem6:
|
|
@@ -453,22 +448,26 @@ with gr.Blocks(
|
|
| 453 |
output_format = gr.Dropdown(value="wav", choices=["wav", "flac", "mp3"], label="Output Format", info="The format of the output audio file.")
|
| 454 |
with gr.Row():
|
| 455 |
norm_threshold = gr.Slider(minimum=0.1, maximum=1, step=0.1, value=0.9, label="Normalization threshold", info="The threshold for audio normalization.")
|
| 456 |
-
amp_threshold = gr.Slider(minimum=0.
|
| 457 |
with gr.Row():
|
| 458 |
batch_size = gr.Slider(minimum=1, maximum=16, step=1, value=1, label="Batch Size", info="Larger consumes more RAM but may process slightly faster.")
|
| 459 |
|
| 460 |
with gr.Accordion("Rename Stems", open=False):
|
| 461 |
-
gr.HTML("<h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
with gr.Row():
|
| 463 |
-
vocals_stem = gr.Textbox(value="
|
| 464 |
-
instrumental_stem = gr.Textbox(value="
|
| 465 |
-
other_stem = gr.Textbox(value="
|
| 466 |
with gr.Row():
|
| 467 |
-
drums_stem = gr.Textbox(value="
|
| 468 |
-
bass_stem = gr.Textbox(value="
|
| 469 |
with gr.Row():
|
| 470 |
-
guitar_stem = gr.Textbox(value="
|
| 471 |
-
piano_stem = gr.Textbox(value="
|
| 472 |
|
| 473 |
demucs_model.change(update_stems, inputs=[demucs_model], outputs=stem6)
|
| 474 |
|
|
@@ -600,7 +599,7 @@ with gr.Blocks(
|
|
| 600 |
)
|
| 601 |
|
| 602 |
def main():
|
| 603 |
-
app.launch(share=True
|
| 604 |
|
| 605 |
if __name__ == "__main__":
|
| 606 |
main()
|
|
|
|
| 141 |
raise RuntimeError(f"Failed to prepare output directory {out_dir}: {e}")
|
| 142 |
return out_dir
|
| 143 |
|
| 144 |
+
def rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, model):
|
| 145 |
base_name = os.path.splitext(os.path.basename(audio))[0]
|
| 146 |
stems = {
|
| 147 |
+
"Vocals": vocals_stem.replace("<IN>", base_name).replace("<SN>", "Vocals").replace("<MN>", model),
|
| 148 |
+
"Instrumental": instrumental_stem.replace("<IN>", base_name).replace("<SN>", "Instrumental").replace("<MN>", model),
|
| 149 |
+
"Drums": drums_stem.replace("<IN>", base_name).replace("<SN>", "Drums").replace("<MN>", model),
|
| 150 |
+
"Bass": bass_stem.replace("<IN>", base_name).replace("<SN>", "Bass").replace("<MN>", model),
|
| 151 |
+
"Other": other_stem.replace("<IN>", base_name).replace("<SN>", "Other").replace("<MN>", model),
|
| 152 |
+
"Guitar": guitar_stem.replace("<IN>", base_name).replace("<SN>", "Guitar").replace("<MN>", model),
|
| 153 |
+
"Piano": piano_stem.replace("<IN>", base_name).replace("<SN>", "Piano").replace("<MN>", model),
|
| 154 |
}
|
| 155 |
return stems
|
| 156 |
|
| 157 |
+
# Обновленные функции для сепарации
|
| 158 |
def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 159 |
"""Separate audio using Roformer model."""
|
| 160 |
+
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, model_key)
|
| 161 |
print_message(audio, model_key)
|
| 162 |
model = ROFORMER_MODELS[model_key]
|
| 163 |
try:
|
|
|
|
| 193 |
|
| 194 |
def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 195 |
"""Separate audio using MDX23C model."""
|
| 196 |
+
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, model)
|
| 197 |
print_message(audio, model)
|
| 198 |
try:
|
| 199 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
|
|
| 228 |
|
| 229 |
def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 230 |
"""Separate audio using MDX-NET model."""
|
| 231 |
+
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, model)
|
| 232 |
print_message(audio, model)
|
| 233 |
try:
|
| 234 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
|
|
| 263 |
|
| 264 |
def vr_separator(audio, model, window_size, aggression, tta, post_process, post_process_threshold, high_end_process, model_dir, out_dir, out_format, norm_thresh, amp_thresh, batch_size, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 265 |
"""Separate audio using VR ARCH model."""
|
| 266 |
+
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, model)
|
| 267 |
print_message(audio, model)
|
| 268 |
try:
|
| 269 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
|
|
| 300 |
|
| 301 |
def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, progress=gr.Progress(track_tqdm=True)):
|
| 302 |
"""Separate audio using Demucs model."""
|
| 303 |
+
stemname = rename_stems(audio, vocals_stem, instrumental_stem, other_stem, drums_stem, bass_stem, guitar_stem, piano_stem, model)
|
| 304 |
print_message(audio, model)
|
| 305 |
try:
|
| 306 |
out_dir = prepare_output_dir(audio, out_dir)
|
|
|
|
| 328 |
print(f"Separation complete!\nResults: {', '.join(separation)}")
|
| 329 |
|
| 330 |
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
| 331 |
+
|
| 332 |
if model == "htdemucs_6s.yaml":
|
| 333 |
return stems[0], stems[1], stems[2], stems[3], stems[4], stems[5]
|
| 334 |
else:
|
|
|
|
| 336 |
except Exception as e:
|
| 337 |
raise RuntimeError(f"Demucs separation failed: {e}") from e
|
| 338 |
|
| 339 |
+
# Обновленный интерфейс
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
with gr.Blocks(
|
| 341 |
title="🎵 PolUVR 🎵",
|
| 342 |
css="footer{display:none !important}",
|
|
|
|
| 433 |
with gr.Row():
|
| 434 |
demucs_stem1 = gr.Audio(label="Stem 1", type="filepath", interactive=False)
|
| 435 |
demucs_stem2 = gr.Audio(label="Stem 2", type="filepath", interactive=False)
|
|
|
|
| 436 |
demucs_stem3 = gr.Audio(label="Stem 3", type="filepath", interactive=False)
|
| 437 |
demucs_stem4 = gr.Audio(label="Stem 4", type="filepath", interactive=False)
|
| 438 |
with gr.Row(visible=False) as stem6:
|
|
|
|
| 448 |
output_format = gr.Dropdown(value="wav", choices=["wav", "flac", "mp3"], label="Output Format", info="The format of the output audio file.")
|
| 449 |
with gr.Row():
|
| 450 |
norm_threshold = gr.Slider(minimum=0.1, maximum=1, step=0.1, value=0.9, label="Normalization threshold", info="The threshold for audio normalization.")
|
| 451 |
+
amp_threshold = gr.Slider(minimum=0.1, maximum=1, step=0.1, value=0.0, label="Amplification threshold", info="The threshold for audio amplification.")
|
| 452 |
with gr.Row():
|
| 453 |
batch_size = gr.Slider(minimum=1, maximum=16, step=1, value=1, label="Batch Size", info="Larger consumes more RAM but may process slightly faster.")
|
| 454 |
|
| 455 |
with gr.Accordion("Rename Stems", open=False):
|
| 456 |
+
gr.HTML("<h3>Input File Name: <code><IN></code> - Automatic detection</h3>")
|
| 457 |
+
gr.HTML("<h3>Stem Name: <code><SN></code> - Automatic detection (e.g., Vocals, Instrumental)</h3>")
|
| 458 |
+
gr.HTML("<h3>Model Name: <code><MN></code> - Automatic detection (e.g., BS-Roformer-Viperx-1297)</h3>")
|
| 459 |
+
gr.HTML("<h3>Usage Example: <code><IN>_<SN>_<MN></code></h3>")
|
| 460 |
+
gr.HTML("<h3>Output File Name: <code>Music_(Vocals)_BS-Roformer-Viperx-1297</code></h3>")
|
| 461 |
with gr.Row():
|
| 462 |
+
vocals_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Vocals Stem", info="Пример вывода: Music_(Vocals)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 463 |
+
instrumental_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Instrumental Stem", info="Пример вывода: Music_(Instrumental)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 464 |
+
other_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Other Stem", info="Пример вывода: Music_(Other)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 465 |
with gr.Row():
|
| 466 |
+
drums_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Drums Stem", info="Пример вывода: Music_(Drums)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 467 |
+
bass_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Bass Stem", info="Пример вывода: Music_(Bass)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 468 |
with gr.Row():
|
| 469 |
+
guitar_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Guitar Stem", info="Пример вывода: Music_(Guitar)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 470 |
+
piano_stem = gr.Textbox(value="<IN>_(<SN>)_<MN>", label="Piano Stem", info="Пример вывода: Music_(Piano)_BS-Roformer-Viperx-1297", placeholder="<IN>_(<SN>)_<MN>")
|
| 471 |
|
| 472 |
demucs_model.change(update_stems, inputs=[demucs_model], outputs=stem6)
|
| 473 |
|
|
|
|
| 599 |
)
|
| 600 |
|
| 601 |
def main():
|
| 602 |
+
app.launch(share=True)
|
| 603 |
|
| 604 |
if __name__ == "__main__":
|
| 605 |
main()
|