Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from demucs.separate import main
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
os.makedirs(output_dir, exist_ok=True)
|
| 8 |
-
main(["-n", "htdemucs", "-d", "cpu", "-o", output_dir, audio_file])
|
| 9 |
-
|
| 10 |
-
base = os.path.splitext(os.path.basename(audio_file))[0]
|
| 11 |
-
folder = os.path.join(output_dir, "htdemucs", base)
|
| 12 |
-
return [os.path.join(folder, f"{stem}.mp3") for stem in ["vocals", "drums", "bass", "other"]]
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
import gradio as gr
|
| 4 |
from demucs.separate import main
|
|
|
|
| 5 |
|
| 6 |
+
def separate_stems(audio_file):
|
| 7 |
+
input_path = "input.mp3"
|
| 8 |
+
shutil.copy(audio_file, input_path)
|
| 9 |
+
|
| 10 |
+
output_dir = "output"
|
| 11 |
+
if os.path.exists(output_dir):
|
| 12 |
+
shutil.rmtree(output_dir)
|
| 13 |
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Run Demucs
|
| 16 |
+
main(["-n", "htdemucs", "-o", output_dir, input_path])
|
| 17 |
+
|
| 18 |
+
# Build list of stems to return
|
| 19 |
+
base = os.path.splitext(os.path.basename(input_path))[0]
|
| 20 |
+
stem_path = os.path.join(output_dir, "htdemucs", base)
|
| 21 |
+
stems = [os.path.join(stem_path, f"{stem}.mp3") for stem in ["vocals", "drums", "bass", "other"]]
|
| 22 |
+
return stems
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=separate_stems,
|
| 26 |
+
inputs=gr.Audio(type="filepath", label="Upload Song"),
|
| 27 |
+
outputs=[
|
| 28 |
+
gr.Audio(label="Vocals"),
|
| 29 |
+
gr.Audio(label="Drums"),
|
| 30 |
+
gr.Audio(label="Bass"),
|
| 31 |
+
gr.Audio(label="Other"),
|
| 32 |
+
],
|
| 33 |
+
title="Demucs v4 Stem Separator",
|
| 34 |
+
description="Upload a song to separate vocals, drums, bass, and other using Facebook's Demucs model.",
|
| 35 |
)
|
| 36 |
|
| 37 |
+
demo.launch()
|