rbarman commited on
Commit
3e5fbbc
1 Parent(s): 4feb81f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -9
app.py CHANGED
@@ -4,7 +4,7 @@ import tempfile
4
  import subprocess
5
 
6
  # Set Streamlit app title
7
- st.title("Audio Processing App")
8
 
9
  # Function to process the audio file
10
  def separate_audio(audio_path):
@@ -17,10 +17,7 @@ def separate_audio(audio_path):
17
  print(f"{gradio_temp_path=}")
18
  print(f"{audio_filename=}")
19
 
20
- # command = f"spleeter separate -o {gradio_temp_path} -p spleeter:2stems {audio_path}"
21
  command = f"spleeter separate -p spleeter:2stems {audio_path}"
22
- # command = f"ls {gradio_temp_path}"
23
- # command = f"cp {audio_path} output/test.wav"
24
  command = command.split()
25
  print(f"{command=}")
26
 
@@ -37,22 +34,71 @@ def separate_audio(audio_path):
37
 
38
  return vocals_path, accompaniment_path
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Streamlit app content
41
- st.write("Upload an audio file (.wav)")
42
 
43
  uploaded_file = st.file_uploader("Choose a file", type=["wav","mp3"])
 
44
 
45
  if uploaded_file is not None:
46
 
47
  # Save the uploaded file to a temporary location
48
- with tempfile.NamedTemporaryFile(delete=False) as temp_file:
49
  temp_file.write(uploaded_file.read())
50
  temp_file_path = temp_file.name
51
 
52
  # Process the uploaded audio file
53
- vocals_path, accompaniment_path = separate_audio(temp_file_path)
54
 
55
  # Display the output files for download
56
  st.write("Output Files:")
57
- st.audio(vocals_path, format="audio/wav", start_time=0)
58
- st.audio(accompaniment_path, format="audio/wav", start_time=0)
 
 
 
4
  import subprocess
5
 
6
  # Set Streamlit app title
7
+ st.title("Audio Separation App")
8
 
9
  # Function to process the audio file
10
  def separate_audio(audio_path):
 
17
  print(f"{gradio_temp_path=}")
18
  print(f"{audio_filename=}")
19
 
 
20
  command = f"spleeter separate -p spleeter:2stems {audio_path}"
 
 
21
  command = command.split()
22
  print(f"{command=}")
23
 
 
34
 
35
  return vocals_path, accompaniment_path
36
 
37
+
38
+ def separate_audio_by_stem(audio_path, stem_count):
39
+
40
+ print(f"{audio_path=}")
41
+ head, tail = os.path.split(audio_path)
42
+
43
+ gradio_temp_path = head
44
+ audio_filename = tail.split('.')[0]
45
+ print(f"{gradio_temp_path=}")
46
+ print(f"{audio_filename=}")
47
+ print(f"{stem_count=}")
48
+
49
+ command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path}"
50
+ command = command.split()
51
+ print(f"{command=}")
52
+
53
+ result = subprocess.run(command)
54
+ print(result)
55
+
56
+ if stem_count == 2:
57
+ accompaniment_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/accompaniment.wav"
58
+ vocals_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/vocals.wav"
59
+ print(f"{accompaniment_path=}")
60
+ print(os.path.exists(accompaniment_path))
61
+ print(f"{vocals_path=}")
62
+ print(os.path.exists(vocals_path))
63
+
64
+ return [vocals_path, accompaniment_path]
65
+
66
+ elif stem_count == 4:
67
+
68
+ vocals_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/vocals.wav"
69
+ drums_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/drums.wav"
70
+ bass_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/bass.wav"
71
+ other_path = f"{gradio_temp_path}/separated_audio/{audio_filename}/other.wav"
72
+
73
+ print(f"{vocals_path=} \t exists: {os.path.exists(vocals_path)}")
74
+ print(f"{drums_path=} \t exists: {os.path.exists(drums_path)}")
75
+ print(f"{bass_path=} \t exists: {os.path.exists(bass_path)}")
76
+ print(f"{other_path=} \t exists: {os.path.exists(other_path)}")
77
+
78
+
79
+ return [vocals_path, drums_path, bass_path, other_path]
80
+
81
+
82
+
83
  # Streamlit app content
84
+ st.write("Upload an audio file")
85
 
86
  uploaded_file = st.file_uploader("Choose a file", type=["wav","mp3"])
87
+ selected_stem_count = st.radio("Select stem count", (2,3,5))
88
 
89
  if uploaded_file is not None:
90
 
91
  # Save the uploaded file to a temporary location
92
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
93
  temp_file.write(uploaded_file.read())
94
  temp_file_path = temp_file.name
95
 
96
  # Process the uploaded audio file
97
+ separated_audio_paths = separate_audio(temp_file_path)
98
 
99
  # Display the output files for download
100
  st.write("Output Files:")
101
+ # st.audio(vocals_path, format="audio/wav", start_time=0)
102
+ # st.audio(accompaniment_path, format="audio/wav", start_time=0)
103
+ for path in separated_audio_paths:
104
+ st.audio(path, format="audio/wav", start_time=0)