fabiogra commited on
Commit
78dd18a
1 Parent(s): 4aa756b

fix: remove st_local_audio, convert orig audio to mp3 in inference script

Browse files
Files changed (2) hide show
  1. app/pages/Separate.py +7 -5
  2. scripts/inference.py +9 -1
app/pages/Separate.py CHANGED
@@ -13,7 +13,6 @@ from helpers import (
13
  load_audio_segment,
14
  load_list_of_songs,
15
  plot_audio,
16
- st_local_audio,
17
  url_is_valid,
18
  file_size_is_valid,
19
  delete_old_files,
@@ -34,7 +33,10 @@ label_sources = {
34
  }
35
 
36
  separation_mode_to_model = {
37
- "Vocals & Instrumental (Faster)": ("vocal_remover", ["vocals.mp3", "no_vocals.mp3"]),
 
 
 
38
  "Vocals & Instrumental (High Quality, Slower)": ("htdemucs", ["vocals.mp3", "no_vocals.mp3"]),
39
  "Vocals, Drums, Bass & Other (Slower)": (
40
  "htdemucs",
@@ -85,7 +87,7 @@ def show_results(model_name: str, dir_name_output: str, file_sources: List):
85
  use_column_width="always",
86
  )
87
  with cols[1]:
88
- st_local_audio(pathname, key=f"output_{file}_{dir_name_output}")
89
  log.info(f"Displaying results for {dir_name_output} - {model_name}")
90
 
91
 
@@ -195,7 +197,7 @@ def body():
195
  separation_mode = st.selectbox(
196
  "Choose the separation mode",
197
  [
198
- "Vocals & Instrumental (Faster)",
199
  "Vocals & Instrumental (High Quality, Slower)",
200
  "Vocals, Drums, Bass & Other (Slower)",
201
  "Vocal, Drums, Bass, Guitar, Piano & Other (Slowest)",
@@ -203,7 +205,7 @@ def body():
203
  on_change=reset_execution(),
204
  key="separation_mode",
205
  )
206
- if separation_mode == "Vocals & Instrumental (Faster)":
207
  max_duration = 30
208
  else:
209
  max_duration = 15
 
13
  load_audio_segment,
14
  load_list_of_songs,
15
  plot_audio,
 
16
  url_is_valid,
17
  file_size_is_valid,
18
  delete_old_files,
 
33
  }
34
 
35
  separation_mode_to_model = {
36
+ "Vocals & Instrumental (Low Quality, Faster)": (
37
+ "vocal_remover",
38
+ ["vocals.mp3", "no_vocals.mp3"],
39
+ ),
40
  "Vocals & Instrumental (High Quality, Slower)": ("htdemucs", ["vocals.mp3", "no_vocals.mp3"]),
41
  "Vocals, Drums, Bass & Other (Slower)": (
42
  "htdemucs",
 
87
  use_column_width="always",
88
  )
89
  with cols[1]:
90
+ st.audio(str(pathname))
91
  log.info(f"Displaying results for {dir_name_output} - {model_name}")
92
 
93
 
 
197
  separation_mode = st.selectbox(
198
  "Choose the separation mode",
199
  [
200
+ "Vocals & Instrumental (Low Quality, Faster)",
201
  "Vocals & Instrumental (High Quality, Slower)",
202
  "Vocals, Drums, Bass & Other (Slower)",
203
  "Vocal, Drums, Bass, Guitar, Piano & Other (Slowest)",
 
205
  on_change=reset_execution(),
206
  key="separation_mode",
207
  )
208
+ if separation_mode == "Vocals & Instrumental (Low Quality, Faster)":
209
  max_duration = 30
210
  else:
211
  max_duration = 15
scripts/inference.py CHANGED
@@ -1,7 +1,9 @@
1
  import argparse
2
  from pathlib import Path
3
-
4
  import warnings
 
 
 
5
  from app.service.vocal_remover.runner import load_model, separate
6
  from app.service.demucs_runner import separator
7
 
@@ -10,6 +12,11 @@ warnings.simplefilter("ignore", FutureWarning)
10
  warnings.filterwarnings("ignore", module="streamlit")
11
 
12
 
 
 
 
 
 
13
  def main():
14
  p = argparse.ArgumentParser()
15
  p.add_argument("--gpu", "-g", type=int, default=-1)
@@ -53,6 +60,7 @@ def main():
53
  output_dir=args.output_dir,
54
  only_no_vocals=True,
55
  )
 
56
 
57
 
58
  if __name__ == "__main__":
 
1
  import argparse
2
  from pathlib import Path
 
3
  import warnings
4
+
5
+ from pydub import AudioSegment
6
+
7
  from app.service.vocal_remover.runner import load_model, separate
8
  from app.service.demucs_runner import separator
9
 
 
12
  warnings.filterwarnings("ignore", module="streamlit")
13
 
14
 
15
+ def convert_to_mp3(input_file, output_file):
16
+ audio = AudioSegment.from_file(input_file)
17
+ audio.export(output_file, format="mp3")
18
+
19
+
20
  def main():
21
  p = argparse.ArgumentParser()
22
  p.add_argument("--gpu", "-g", type=int, default=-1)
 
60
  output_dir=args.output_dir,
61
  only_no_vocals=True,
62
  )
63
+ convert_to_mp3(input_file, input_file)
64
 
65
 
66
  if __name__ == "__main__":