fabiogra commited on
Commit
5e0ccc8
1 Parent(s): faebcc3

feat: add max amplitude, improve plots

Browse files
Files changed (2) hide show
  1. app/helpers.py +5 -2
  2. app/pages/Separate.py +1 -1
app/helpers.py CHANGED
@@ -43,14 +43,17 @@ def load_audio_segment(path: str, format: str) -> AudioSegment:
43
 
44
 
45
  @st.cache_data(show_spinner=False)
46
- def plot_audio(_audio_segment: AudioSegment, *args, **kwargs) -> Image.Image:
47
  samples = _audio_segment.get_array_of_samples()
48
  arr = np.array(samples)
49
 
50
  fig, ax = plt.subplots(figsize=(10, 2))
51
- ax.plot(arr, linewidth=0.05)
52
  ax.set_axis_off()
53
 
 
 
 
54
  # Set the background color to transparent
55
  fig.patch.set_alpha(0)
56
  ax.patch.set_alpha(0)
 
43
 
44
 
45
  @st.cache_data(show_spinner=False)
46
+ def plot_audio(_audio_segment: AudioSegment, max_y: float, *args, **kwargs) -> Image.Image:
47
  samples = _audio_segment.get_array_of_samples()
48
  arr = np.array(samples)
49
 
50
  fig, ax = plt.subplots(figsize=(10, 2))
51
+ ax.plot(arr, linewidth=0.04)
52
  ax.set_axis_off()
53
 
54
+ # Scale the plot based on max Y value
55
+ ax.set_ylim(bottom=-max_y, top=max_y)
56
+
57
  # Set the background color to transparent
58
  fig.patch.set_alpha(0)
59
  ax.patch.set_alpha(0)
app/pages/Separate.py CHANGED
@@ -72,7 +72,7 @@ def show_results(model_name: str, dir_name_output: str, file_sources: List):
72
  st.image(
73
  plot_audio(
74
  auseg,
75
- title="",
76
  file=file,
77
  model_name=model_name,
78
  dir_name_output=dir_name_output,
 
72
  st.image(
73
  plot_audio(
74
  auseg,
75
+ 32767,
76
  file=file,
77
  model_name=model_name,
78
  dir_name_output=dir_name_output,