Spaces:
Runtime error
Runtime error
Updated full code
Browse files
app.py
CHANGED
@@ -1,67 +1,51 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from scipy.io.wavfile import write
|
4 |
-
import subprocess
|
5 |
-
|
6 |
-
|
7 |
-
from audio_separator import Separator
|
8 |
-
|
9 |
|
|
|
10 |
|
11 |
def inference(audio):
|
12 |
os.makedirs("out", exist_ok=True)
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
return files
|
50 |
-
|
51 |
-
title = "Source Sepration Demo"
|
52 |
-
description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio"
|
53 |
gr.Interface(
|
54 |
inference,
|
55 |
gr.components.Audio(type="numpy", label="Input"),
|
56 |
-
[gr.components.Audio(type="filepath", label="Full Vocals"
|
57 |
-
gr.components.Audio(type="filepath", label="Lead Vocals"),
|
58 |
-
gr.components.Audio(type="filepath", label="Chorus"),
|
59 |
-
gr.components.Audio(type="filepath", label="Bass"),
|
60 |
-
gr.components.Audio(type="filepath", label="Drums"),
|
61 |
-
gr.components.Audio(type="filepath", label="Other"),
|
62 |
-
gr.components.Audio(type="filepath", label="Piano"),
|
63 |
-
gr.components.Audio(type="filepath", label="Guitar"),
|
64 |
-
],
|
65 |
title=title,
|
66 |
description=description,
|
67 |
-
).launch(
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from scipy.io.wavfile import write
|
4 |
+
import subprocess
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
from audio_separator import Separator # Ensure this is correctly implemented
|
7 |
|
8 |
def inference(audio):
|
9 |
os.makedirs("out", exist_ok=True)
|
10 |
+
audio_path = 'test.wav'
|
11 |
+
write(audio_path, audio[0], audio[1])
|
12 |
+
|
13 |
+
try:
|
14 |
+
# Using subprocess.run for better control
|
15 |
+
command = f"python3 -m demucs.separate -n htdemucs_6s -d cpu {audio_path} -o out"
|
16 |
+
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
17 |
+
print("Demucs script output:", process.stdout.decode())
|
18 |
+
except subprocess.CalledProcessError as e:
|
19 |
+
print("Error in Demucs script:", e.stderr.decode())
|
20 |
+
return None
|
21 |
+
|
22 |
+
try:
|
23 |
+
# Separating the stems using your custom separator
|
24 |
+
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=False, output_format='mp3')
|
25 |
+
primary_stem_path, secondary_stem_path = separator.separate()
|
26 |
+
except Exception as e:
|
27 |
+
print("Error in custom separation:", str(e))
|
28 |
+
return None
|
29 |
+
|
30 |
+
# Collecting all file paths
|
31 |
+
files = [f"./out/htdemucs_6s/test/{stem}.wav" for stem in ["vocals", "bass", "drums", "other", "piano", "guitar"]]
|
32 |
+
files.extend([primary_stem_path, secondary_stem_path])
|
33 |
+
|
34 |
+
# Check if files exist
|
35 |
+
existing_files = [file for file in files if os.path.isfile(file)]
|
36 |
+
if not existing_files:
|
37 |
+
print("No files were created.")
|
38 |
+
return None
|
39 |
+
|
40 |
+
return existing_files
|
41 |
+
|
42 |
+
# Gradio Interface
|
43 |
+
title = "Source Separation Demo"
|
44 |
+
description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio."
|
|
|
|
|
|
|
|
|
|
|
45 |
gr.Interface(
|
46 |
inference,
|
47 |
gr.components.Audio(type="numpy", label="Input"),
|
48 |
+
[gr.components.Audio(type="filepath", label=stem) for stem in ["Full Vocals", "Lead Vocals", "Chorus", "Bass", "Drums", "Other", "Piano", "Guitar"]],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
title=title,
|
50 |
description=description,
|
51 |
+
).launch()
|