TheStinger commited on
Commit
cb85b93
1 Parent(s): 0e08ca7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -26,13 +26,10 @@ def main():
26
  image_output = gr.Image(type='filepath', interactive=False)
27
 
28
  create_spec_butt.click(fn=create_spectrogram_and_get_info, inputs=[audio_input], outputs=[output_markdown, image_output])
29
- audio_input.change(fn=lambda: ({"value": "", "__type__": "update"},
30
- {"value": "", "__type__": "update"}),
31
- inputs=[], outputs=[image_output, output_markdown])
32
 
33
  app.queue(max_size=1022).launch(share=True)
34
 
35
- def create_spectrogram_and_get_info(audio_file):
36
  # Clear figure in case it has data in it
37
  plt.clf()
38
 
@@ -45,7 +42,7 @@ def create_spectrogram_and_get_info(audio_file):
45
 
46
  # Create the spectrogram
47
  plt.specgram(audio_data, Fs=sample_rate / 1, NFFT=4096, sides='onesided',
48
- cmap="Reds_r", scale_by_freq=True, scale='dB', mode='magnitude')
49
 
50
  # Save the spectrogram to a PNG file
51
  plt.savefig('spectrogram.png')
@@ -82,8 +79,15 @@ def create_spectrogram_and_get_info(audio_file):
82
  </center>
83
  """
84
 
 
 
 
 
 
 
85
  # Return the PNG file of the spectrogram and the info table
86
- return {"value": info_table, "__type__": "update"}, 'spectrogram.png'
 
87
 
88
  # Create the Gradio interface
89
- main()
 
26
  image_output = gr.Image(type='filepath', interactive=False)
27
 
28
  create_spec_butt.click(fn=create_spectrogram_and_get_info, inputs=[audio_input], outputs=[output_markdown, image_output])
 
 
 
29
 
30
  app.queue(max_size=1022).launch(share=True)
31
 
32
+ def create_spectrogram_and_get_info(audio_file, output_markdown):
33
  # Clear figure in case it has data in it
34
  plt.clf()
35
 
 
42
 
43
  # Create the spectrogram
44
  plt.specgram(audio_data, Fs=sample_rate / 1, NFFT=4096, sides='onesided',
45
+ cmap="Reds_r", scale_by_freq=True, scale='dB', mode='magnitude', window=np.hanning(4096))
46
 
47
  # Save the spectrogram to a PNG file
48
  plt.savefig('spectrogram.png')
 
79
  </center>
80
  """
81
 
82
+ # Delete the audio file after analyzing it
83
+ os.remove(audio_file)
84
+
85
+ # Clear the markdown content
86
+ output_markdown.update({"value": "", "__type__": "update"})
87
+
88
  # Return the PNG file of the spectrogram and the info table
89
+ return info_table, 'spectrogram.png'
90
+
91
 
92
  # Create the Gradio interface
93
+ main()