Spaces:
Runtime error
Runtime error
amirgame197
commited on
Commit
•
c56a4ac
1
Parent(s):
458cf0b
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
import subprocess
|
5 |
+
|
6 |
+
def separate_audio(audio_path, stem_count):
|
7 |
+
print(f"{audio_path=}")
|
8 |
+
head, tail = os.path.split(audio_path)
|
9 |
+
|
10 |
+
gradio_temp_path = head
|
11 |
+
audio_filename = tail.split('.')[0]
|
12 |
+
print(f"{gradio_temp_path=}")
|
13 |
+
print(f"{audio_filename=}")
|
14 |
+
print(f"{stem_count=}")
|
15 |
+
|
16 |
+
command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path}"
|
17 |
+
command = command.split()
|
18 |
+
print(f"{command=}")
|
19 |
+
|
20 |
+
result = subprocess.run(command, capture_output=True)
|
21 |
+
print(result)
|
22 |
+
if result.returncode != 0:
|
23 |
+
print(f"Error: {result.stderr}")
|
24 |
+
return []
|
25 |
+
|
26 |
+
randomnumber = str(random.randint(111111111, 999999999))
|
27 |
+
output_folder = f"{gradio_temp_path}/separated_audio/{randomnumber}"
|
28 |
+
os.makedirs(output_folder, exist_ok=True) # Ensure the output directory exists
|
29 |
+
|
30 |
+
paths = []
|
31 |
+
stems = ['vocals', 'drums', 'bass', 'other', 'piano']
|
32 |
+
for i, stem in enumerate(stems[:stem_count]):
|
33 |
+
stem_path = os.path.join(output_folder, f"{stem}.wav")
|
34 |
+
if os.path.exists(stem_path):
|
35 |
+
paths.append((stem.capitalize(), stem_path))
|
36 |
+
|
37 |
+
# Return audio components for Gradio interface
|
38 |
+
audio_outputs = []
|
39 |
+
for label, path in paths:
|
40 |
+
audio_outputs.append(gr.Audio(file=path, label=label))
|
41 |
+
|
42 |
+
return audio_outputs
|
43 |
+
|
44 |
+
iface = gr.Interface(
|
45 |
+
fn=separate_audio,
|
46 |
+
inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
|
47 |
+
outputs=[gr.Audio(label="Accompaniment"), gr.Audio(label="Vocals"), gr.Audio(label="Drums"), gr.Audio(label="Bass"), gr.Audio(label="Other"), gr.Audio(label="Piano")]
|
48 |
+
)
|
49 |
+
|
50 |
+
iface.launch()
|