surya5289 commited on
Commit
314bd70
·
verified ·
1 Parent(s): bc6b61a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -18,10 +18,10 @@ def generate_mel_spectrogram(audio_path, sr=22050, n_mels=128, fmin=0, fmax=7000
18
 
19
  return S_dB, y, sr
20
 
21
- def detect_zero_db(spectrogram):
22
  # Create a binary mask where the spectrogram values are close to 0 dB
23
- threshold = -40 # +0 dB threshold
24
- mask = np.isclose(spectrogram, threshold, atol=10) # Use a tolerance to include values close to 0 dB
25
 
26
  return mask
27
 
@@ -53,9 +53,9 @@ def plot_frequency(times, frequencies, label, color, file_path):
53
  plt.savefig(file_path, format='png', bbox_inches='tight', pad_inches=0)
54
  plt.close()
55
 
56
- def process_audio(audio_file):
57
  mel_spectrogram, y, sr = generate_mel_spectrogram(audio_file)
58
- edges = detect_zero_db(mel_spectrogram)
59
 
60
  # Create temporary files to save the generated images
61
  with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as mel_file, \
@@ -110,13 +110,17 @@ def process_audio(audio_file):
110
 
111
  with gr.Blocks() as demo:
112
  with gr.Group():
 
 
113
  audio_input = gr.Audio(label="Upload an audio file in WAV format", type="filepath")
 
114
  img_slider = ImageSlider(label="Before and After Edge Detection", type="filepath", slider_color="pink")
115
  f0_plot = gr.Image(label="F0 Frequency Plot", type="filepath")
116
  f1_plot = gr.Image(label="F1 Frequency Plot", type="filepath")
117
  f2_plot = gr.Image(label="F2 Frequency Plot", type="filepath")
118
 
119
- audio_input.upload(process_audio, inputs=audio_input, outputs=[img_slider, f0_plot, f1_plot, f2_plot])
 
120
 
121
  if __name__ == "__main__":
122
- demo.launch()
 
18
 
19
  return S_dB, y, sr
20
 
21
+ def detect_zero_db(spectrogram,threshold,tol):
22
  # Create a binary mask where the spectrogram values are close to 0 dB
23
+ # +0 dB threshold
24
+ mask = np.isclose(spectrogram, threshold, atol=tol) # Use a tolerance to include values close to 0 dB
25
 
26
  return mask
27
 
 
53
  plt.savefig(file_path, format='png', bbox_inches='tight', pad_inches=0)
54
  plt.close()
55
 
56
+ def process_audio( threshold, audio_file,tol):
57
  mel_spectrogram, y, sr = generate_mel_spectrogram(audio_file)
58
+ edges = detect_zero_db(mel_spectrogram,threshold,tol)
59
 
60
  # Create temporary files to save the generated images
61
  with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as mel_file, \
 
110
 
111
  with gr.Blocks() as demo:
112
  with gr.Group():
113
+ threshold_slider =gr.Slider(-100,0,value=-20,info="Choose between -100 and 0")
114
+ tol_slider =gr.Slider(0,25,value=10,info="Choose between 0 and 25")
115
  audio_input = gr.Audio(label="Upload an audio file in WAV format", type="filepath")
116
+ submit_button = gr.Button("Submit")
117
  img_slider = ImageSlider(label="Before and After Edge Detection", type="filepath", slider_color="pink")
118
  f0_plot = gr.Image(label="F0 Frequency Plot", type="filepath")
119
  f1_plot = gr.Image(label="F1 Frequency Plot", type="filepath")
120
  f2_plot = gr.Image(label="F2 Frequency Plot", type="filepath")
121
 
122
+
123
+ submit_button.click(process_audio, inputs=[ threshold_slider, audio_input,tol_slider], outputs=[img_slider, f0_plot, f1_plot, f2_plot])
124
 
125
  if __name__ == "__main__":
126
+ demo.launch()