Spaces:
Runtime error
Runtime error
app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
write('test.wav', audio[0], audio[1])
|
| 14 |
+
|
| 15 |
+
command = "python3 -m demucs.separate -n mdx_extra_q -d cpu test.wav -o out"
|
| 16 |
+
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 17 |
+
print("Demucs script output:", process.stdout.decode())
|
| 18 |
+
|
| 19 |
+
os.makedirs("out", exist_ok=True)
|
| 20 |
+
write('test.wav', audio[0], audio[1])
|
| 21 |
+
result = os.system("python3 -m demucs.separate -n mdx_extra_q -d cpu test.wav -o out")
|
| 22 |
+
print(f"Demucs script result: {result}")
|
| 23 |
+
|
| 24 |
+
# Initialize the Separator with the audio file and model name
|
| 25 |
+
separator = Separator("./out/mdx_extra_q/test/vocals.wav", model_name='UVR_MDXNET_KARA_2',use_cuda=False,output_format='mp3')
|
| 26 |
+
primary_stem_path, secondary_stem_path = separator.separate()
|
| 27 |
+
|
| 28 |
+
print(f'Primary stem saved at {primary_stem_path}')
|
| 29 |
+
print(f'Secondary stem saved at {secondary_stem_path}')
|
| 30 |
+
|
| 31 |
+
# Check if files exist before returning
|
| 32 |
+
files = ["./out/mdx_extra_q/test/vocals.wav",
|
| 33 |
+
secondary_stem_path,
|
| 34 |
+
primary_stem_path,
|
| 35 |
+
"./out/mdx_extra_q/test/bass.wav",
|
| 36 |
+
"./out/mdx_extra_q/test/drums.wav",
|
| 37 |
+
"./out/mdx_extra_q/test/other.wav",
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
for file in files:
|
| 42 |
+
if not os.path.isfile(file):
|
| 43 |
+
print(f"File not found: {file}")
|
| 44 |
+
else:
|
| 45 |
+
print(f"File exists: {file}")
|
| 46 |
+
|
| 47 |
+
return files
|
| 48 |
+
|
| 49 |
+
title = "Source Sepration Demo"
|
| 50 |
+
description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio"
|
| 51 |
+
gr.Interface(
|
| 52 |
+
inference,
|
| 53 |
+
gr.components.Audio(type="numpy", label="Input"),
|
| 54 |
+
[gr.components.Audio(type="filepath", label="Full Vocals"),
|
| 55 |
+
gr.components.Audio(type="filepath", label="Lead Vocals"),
|
| 56 |
+
gr.components.Audio(type="filepath", label="Chorus"),
|
| 57 |
+
gr.components.Audio(type="filepath", label="Bass"),
|
| 58 |
+
gr.components.Audio(type="filepath", label="Drums"),
|
| 59 |
+
gr.components.Audio(type="filepath", label="Other"),
|
| 60 |
+
],
|
| 61 |
+
title=title,
|
| 62 |
+
description=description,
|
| 63 |
+
).launch()
|