Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,125 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import os
|
3 |
-
import tempfile
|
4 |
-
import subprocess
|
5 |
-
|
6 |
-
def separate_audio(audio_path):
|
7 |
-
|
8 |
-
print(f"{audio_path=}")
|
9 |
-
head, tail = os.path.split(audio_path)
|
10 |
-
|
11 |
-
gradio_temp_path = head
|
12 |
-
audio_filename = tail.split('.')[0]
|
13 |
-
print(f"{gradio_temp_path=}")
|
14 |
-
print(f"{audio_filename=}")
|
15 |
-
|
16 |
-
command = f"spleeter separate -p spleeter:2stems {audio_path}"
|
17 |
-
command = command.split()
|
18 |
-
print(f"{command=}")
|
19 |
-
|
20 |
-
result = subprocess.run(command)
|
21 |
-
print(result)
|
22 |
-
|
23 |
-
print("--------")
|
24 |
-
accompaniment_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/accompaniment.wav"
|
25 |
-
vocals_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/vocals.wav"
|
26 |
-
print(f"{accompaniment_path=}")
|
27 |
-
print(os.path.exists(accompaniment_path))
|
28 |
-
print(f"{vocals_path=}")
|
29 |
-
print(os.path.exists(vocals_path))
|
30 |
-
|
31 |
-
return vocals_path, accompaniment_path
|
32 |
-
|
33 |
-
|
34 |
-
def separate_audio_by_stem(audio_path, stem_count):
|
35 |
-
|
36 |
-
print(f"{audio_path=}")
|
37 |
-
head, tail = os.path.split(audio_path)
|
38 |
-
|
39 |
-
gradio_temp_path = head
|
40 |
-
audio_filename = tail.split('.')[0]
|
41 |
-
print(f"{gradio_temp_path=}")
|
42 |
-
print(f"{audio_filename=}")
|
43 |
-
print(f"{stem_count=}")
|
44 |
-
|
45 |
-
command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path}"
|
46 |
-
command = command.split()
|
47 |
-
print(f"{command=}")
|
48 |
-
|
49 |
-
result = subprocess.run(command)
|
50 |
-
print(result)
|
51 |
-
|
52 |
-
if stem_count == 2:
|
53 |
-
accompaniment_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/accompaniment.wav"
|
54 |
-
vocals_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/vocals.wav"
|
55 |
-
|
56 |
-
print(f"{accompaniment_path=} \t exists: {os.path.exists(accompaniment_path)}")
|
57 |
-
print(f"{vocals_path=} \t exists: {os.path.exists(vocals_path)}")
|
58 |
-
|
59 |
-
return [
|
60 |
-
{'description': 'Accompaniment', 'path':accompaniment_path},
|
61 |
-
{'description': 'Vocals', 'path':vocals_path},
|
62 |
-
]
|
63 |
-
|
64 |
-
elif stem_count == 4:
|
65 |
-
|
66 |
-
vocals_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/vocals.wav"
|
67 |
-
drums_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/drums.wav"
|
68 |
-
bass_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/bass.wav"
|
69 |
-
other_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/other.wav"
|
70 |
-
|
71 |
-
print(f"{vocals_path=} \t exists: {os.path.exists(vocals_path)}")
|
72 |
-
print(f"{drums_path=} \t exists: {os.path.exists(drums_path)}")
|
73 |
-
print(f"{bass_path=} \t exists: {os.path.exists(bass_path)}")
|
74 |
-
print(f"{other_path=} \t exists: {os.path.exists(other_path)}")
|
75 |
-
|
76 |
-
return [
|
77 |
-
{'description': 'Vocals', 'path':vocals_path},
|
78 |
-
{'description': 'Drums', 'path':drums_path},
|
79 |
-
{'description': 'Bass', 'path':bass_path},
|
80 |
-
{'description': 'Other', 'path':other_path},
|
81 |
-
]
|
82 |
-
|
83 |
-
elif stem_count == 5:
|
84 |
-
|
85 |
-
piano_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/piano.wav"
|
86 |
-
vocals_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/vocals.wav"
|
87 |
-
drums_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/drums.wav"
|
88 |
-
bass_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/bass.wav"
|
89 |
-
other_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/other.wav"
|
90 |
-
|
91 |
-
print(f"{piano_path=} \t exists: {os.path.exists(vocals_path)}")
|
92 |
-
print(f"{vocals_path=} \t exists: {os.path.exists(vocals_path)}")
|
93 |
-
print(f"{drums_path=} \t exists: {os.path.exists(drums_path)}")
|
94 |
-
print(f"{bass_path=} \t exists: {os.path.exists(bass_path)}")
|
95 |
-
print(f"{other_path=} \t exists: {os.path.exists(other_path)}")
|
96 |
-
|
97 |
-
return [
|
98 |
-
{'description': 'Vocals', 'path':vocals_path},
|
99 |
-
{'description': 'Piano', 'path':piano_path},
|
100 |
-
{'description': 'Drums', 'path':drums_path},
|
101 |
-
{'description': 'Bass', 'path':bass_path},
|
102 |
-
{'description': 'Other', 'path':other_path},
|
103 |
-
]
|
104 |
-
|
105 |
-
|
106 |
-
uploaded_file = st.file_uploader("", type=["wav","mp3"])
|
107 |
-
selected_stem_count = 2
|
108 |
-
|
109 |
-
if uploaded_file is not None:
|
110 |
-
|
111 |
-
if st.button("Submit"):
|
112 |
-
|
113 |
-
# Save the uploaded file to a temporary location
|
114 |
-
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
115 |
-
temp_file.write(uploaded_file.read())
|
116 |
-
temp_file_path = temp_file.name
|
117 |
-
|
118 |
-
# Process the uploaded audio file
|
119 |
-
separate_audios = separate_audio_by_stem(temp_file_path, selected_stem_count)
|
120 |
-
|
121 |
-
# Display the output files for download
|
122 |
-
st.write("Output Files:")
|
123 |
-
for audio in separate_audios:
|
124 |
-
st.write(audio['description'])
|
125 |
-
st.audio(audio['path'], format="audio/wav", start_time=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|