Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,56 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from audio_separator.separator import Separator
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Function for separating the audio
|
| 6 |
-
def separate_audio(audio):
|
| 7 |
if audio is None:
|
| 8 |
return None, None
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
output_dir = "./output"
|
| 15 |
os.makedirs(output_dir, exist_ok=True)
|
| 16 |
|
|
@@ -21,13 +62,12 @@ def separate_audio(audio):
|
|
| 21 |
instrumental_path = os.path.join(output_dir, 'Instrumental.wav')
|
| 22 |
|
| 23 |
with gr.Progress() as progress:
|
| 24 |
-
# Load model
|
| 25 |
progress(0, "Loading model...")
|
| 26 |
-
separator.load_model(model_filename=
|
| 27 |
progress(20, "Model loaded. Starting separation...")
|
| 28 |
|
| 29 |
# Step 3: Splitting track into Vocal and Instrumental
|
| 30 |
-
voc_inst = separator.separate(
|
| 31 |
|
| 32 |
# Check if separation was successful
|
| 33 |
if len(voc_inst) != 2:
|
|
@@ -49,6 +89,8 @@ with gr.Blocks(theme="NoCrypt/[email protected]") as demo:
|
|
| 49 |
with gr.Row():
|
| 50 |
with gr.Column():
|
| 51 |
link_input = gr.Audio(label="Upload Audio File", type="filepath")
|
|
|
|
|
|
|
| 52 |
separate_button = gr.Button("Separate Audio")
|
| 53 |
|
| 54 |
with gr.Column():
|
|
@@ -58,7 +100,7 @@ with gr.Blocks(theme="NoCrypt/[email protected]") as demo:
|
|
| 58 |
# Define button functionality
|
| 59 |
separate_button.click(
|
| 60 |
separate_audio,
|
| 61 |
-
inputs=[link_input],
|
| 62 |
outputs=[
|
| 63 |
instrumental_output,
|
| 64 |
vocals_output,
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from audio_separator.separator import Separator
|
| 4 |
|
| 5 |
+
# Define models
|
| 6 |
+
models = {
|
| 7 |
+
"Roformer": {
|
| 8 |
+
'BS-Roformer-Viperx-1297.ckpt': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
|
| 9 |
+
'BS-Roformer-Viperx-1296.ckpt': 'model_bs_roformer_ep_368_sdr_12.9628.ckpt',
|
| 10 |
+
'BS-Roformer-Viperx-1053.ckpt': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt',
|
| 11 |
+
'Mel-Roformer-Viperx-1143.ckpt': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt'
|
| 12 |
+
},
|
| 13 |
+
"MDX23C": [
|
| 14 |
+
'MDX23C_D1581.ckpt',
|
| 15 |
+
'MDX23C-8KFFT-InstVoc_HQ.ckpt',
|
| 16 |
+
'MDX23C-8KFFT-InstVoc_HQ_2.ckpt',
|
| 17 |
+
],
|
| 18 |
+
"MDXNet": [
|
| 19 |
+
'UVR-MDX-NET-Inst_full_292.onnx',
|
| 20 |
+
'UVR-MDX-NET_Inst_187_beta.onnx',
|
| 21 |
+
# Add remaining models as needed
|
| 22 |
+
],
|
| 23 |
+
"VRArch": [
|
| 24 |
+
'1_HP-UVR.pth',
|
| 25 |
+
'2_HP-UVR.pth',
|
| 26 |
+
# Add remaining models as needed
|
| 27 |
+
],
|
| 28 |
+
"Demucs": [
|
| 29 |
+
'htdemucs_ft.yaml',
|
| 30 |
+
'htdemucs.yaml',
|
| 31 |
+
# Add remaining models as needed
|
| 32 |
+
]
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
# Function for separating the audio
|
| 36 |
+
def separate_audio(audio, model_name):
|
| 37 |
if audio is None:
|
| 38 |
return None, None
|
| 39 |
|
| 40 |
+
# Get the selected model path
|
| 41 |
+
model_path = None
|
| 42 |
+
for model_group in models.values():
|
| 43 |
+
if isinstance(model_group, dict):
|
| 44 |
+
model_path = model_group.get(model_name)
|
| 45 |
+
if model_path:
|
| 46 |
+
break
|
| 47 |
+
elif model_name in model_group:
|
| 48 |
+
model_path = model_name
|
| 49 |
+
break
|
| 50 |
+
|
| 51 |
+
if model_path is None:
|
| 52 |
+
return None, None
|
| 53 |
|
| 54 |
+
# Set up output directory and models for separation
|
| 55 |
output_dir = "./output"
|
| 56 |
os.makedirs(output_dir, exist_ok=True)
|
| 57 |
|
|
|
|
| 62 |
instrumental_path = os.path.join(output_dir, 'Instrumental.wav')
|
| 63 |
|
| 64 |
with gr.Progress() as progress:
|
|
|
|
| 65 |
progress(0, "Loading model...")
|
| 66 |
+
separator.load_model(model_filename=model_path)
|
| 67 |
progress(20, "Model loaded. Starting separation...")
|
| 68 |
|
| 69 |
# Step 3: Splitting track into Vocal and Instrumental
|
| 70 |
+
voc_inst = separator.separate(audio)
|
| 71 |
|
| 72 |
# Check if separation was successful
|
| 73 |
if len(voc_inst) != 2:
|
|
|
|
| 89 |
with gr.Row():
|
| 90 |
with gr.Column():
|
| 91 |
link_input = gr.Audio(label="Upload Audio File", type="filepath")
|
| 92 |
+
model_dropdown = gr.Dropdown(label="Select Model", choices=list(
|
| 93 |
+
models["Roformer"].keys()) + models["MDX23C"] + models["MDXNet"] + models["VRArch"] + models["Demucs"])
|
| 94 |
separate_button = gr.Button("Separate Audio")
|
| 95 |
|
| 96 |
with gr.Column():
|
|
|
|
| 100 |
# Define button functionality
|
| 101 |
separate_button.click(
|
| 102 |
separate_audio,
|
| 103 |
+
inputs=[link_input, model_dropdown],
|
| 104 |
outputs=[
|
| 105 |
instrumental_output,
|
| 106 |
vocals_output,
|