Spaces:
Build error
Build error
update checkbox
Browse files
app.py
CHANGED
@@ -76,8 +76,8 @@ def inference(audio):
|
|
76 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
77 |
print(f"Using device: {device}")
|
78 |
|
79 |
-
# Run Demucs script
|
80 |
try:
|
|
|
81 |
command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
|
82 |
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
83 |
print("Demucs script output:", process.stdout.decode())
|
@@ -85,9 +85,9 @@ def inference(audio):
|
|
85 |
print("Error in Demucs script:", e.stderr.decode())
|
86 |
return None
|
87 |
|
88 |
-
# Run custom separator
|
89 |
use_cuda = device == 'cuda'
|
90 |
try:
|
|
|
91 |
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=use_cuda, output_format='mp3')
|
92 |
primary_stem_path, secondary_stem_path = separator.separate()
|
93 |
except Exception as e:
|
@@ -108,26 +108,24 @@ def inference(audio):
|
|
108 |
|
109 |
return existing_files
|
110 |
|
111 |
-
# Function to return selected
|
112 |
-
def
|
113 |
-
return stems
|
114 |
|
115 |
# Gradio Interface
|
116 |
title = "Source Separation Demo"
|
117 |
description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio."
|
118 |
|
119 |
audio_input = gr.components.Audio(type="numpy", label="Input")
|
120 |
-
|
121 |
-
|
122 |
|
123 |
gr.Interface(
|
124 |
-
fn=lambda audio,
|
125 |
-
inputs=[audio_input,
|
126 |
-
outputs=
|
127 |
title=title,
|
128 |
-
description=description
|
129 |
-
live=True # Enable live update for dynamic output
|
130 |
).launch()
|
131 |
|
132 |
|
133 |
-
|
|
|
76 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
77 |
print(f"Using device: {device}")
|
78 |
|
|
|
79 |
try:
|
80 |
+
# Using subprocess.run for better control
|
81 |
command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
|
82 |
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
83 |
print("Demucs script output:", process.stdout.decode())
|
|
|
85 |
print("Error in Demucs script:", e.stderr.decode())
|
86 |
return None
|
87 |
|
|
|
88 |
use_cuda = device == 'cuda'
|
89 |
try:
|
90 |
+
# Separating the stems using your custom separator
|
91 |
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=use_cuda, output_format='mp3')
|
92 |
primary_stem_path, secondary_stem_path = separator.separate()
|
93 |
except Exception as e:
|
|
|
108 |
|
109 |
return existing_files
|
110 |
|
111 |
+
# Function to return selected audios
|
112 |
+
def get_selected_audios(stems, *selected_stems):
|
113 |
+
return [stems[stem] for stem in selected_stems if stem in stems]
|
114 |
|
115 |
# Gradio Interface
|
116 |
title = "Source Separation Demo"
|
117 |
description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio."
|
118 |
|
119 |
audio_input = gr.components.Audio(type="numpy", label="Input")
|
120 |
+
checkboxes = [gr.components.Checkbox(label=stem) for stem in ["vocals", "bass", "drums", "other", "piano", "guitar", "lead_vocals", "backing_vocals"]]
|
121 |
+
audio_outputs = [gr.components.Audio(type="filepath", label=stem) for stem in ["vocals", "bass", "drums", "other", "piano", "guitar", "lead_vocals", "backing_vocals"]]
|
122 |
|
123 |
gr.Interface(
|
124 |
+
fn=lambda audio, *args: get_selected_audios(inference(audio), *args),
|
125 |
+
inputs=[audio_input, *checkboxes],
|
126 |
+
outputs=audio_outputs,
|
127 |
title=title,
|
128 |
+
description=description
|
|
|
129 |
).launch()
|
130 |
|
131 |
|
|