TheStinger commited on
Commit
ed72842
β€’
1 Parent(s): cb9b2c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -34
app.py CHANGED
@@ -3,7 +3,6 @@ import matplotlib.pyplot as plt
3
  import numpy as np
4
  import os
5
  import soundfile as sf
6
- from PIL import Image
7
 
8
  def main():
9
  # Gradio Interface
@@ -11,10 +10,10 @@ def main():
11
  gr.Markdown(
12
  """
13
  # <div align="center"> Ilaria Audio Analyzer πŸ’– (BETA) </div>
14
- Audio Analyzer Software by Ilaria, Help me on Ko-Fi\n
15
- Special thanks to Alex Murkoff for helping me coding it!
16
 
17
- Need help with AI? Join AI Hub!
18
  """
19
  )
20
 
@@ -23,10 +22,10 @@ def main():
23
  audio_input = gr.Audio(type='filepath')
24
  create_spec_butt = gr.Button(value='Create Spectrogram And Get Info', variant='primary')
25
  with gr.Column():
26
- output_image = gr.Image(type='filepath', interactive=False)
27
  image_output = gr.Image(type='filepath', interactive=False)
28
 
29
- create_spec_butt.click(fn=create_spectrogram_and_get_info, inputs=[audio_input], outputs=[output_image, image_output])
30
 
31
  app.queue(max_size=1022).launch(share=True)
32
 
@@ -63,35 +62,17 @@ def create_spectrogram_and_get_info(audio_file):
63
 
64
  # Create a table with the audio file info
65
  info_table = f"""
66
- File name: {os.path.basename(audio_file)}
67
- Duration: {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds
68
- Samples per second: {audio_info.samplerate} Hz
69
- Audio Channels: {audio_info.channels}
70
- Bitrate: {bitrate:.2f} Mb/s
 
 
71
  """
72
-
73
- # Create a new figure for the info table
74
- fig, ax = plt.subplots()
75
-
76
- # Hide axes
77
- ax.axis('tight')
78
- ax.axis('off')
79
-
80
- # Set figure background color
81
- fig.patch.set_facecolor('white')
82
-
83
- # Create table and save as image
84
- ax.text(0.5, 0.5, info_table, fontsize=140, ha='center', va='center', color='black')
85
- ax.text(0.95, 0.05, "Made by Ilaria Audio Analyzer", fontsize=10, ha='right', va='bottom', color='black')
86
-
87
- plt.savefig('info_table.png')
88
-
89
- # Open the images using PIL
90
- info_table_img = Image.open('info_table.png')
91
- spectrogram_img = Image.open('spectrogram.png')
92
-
93
- # Return the image data
94
- return info_table_img, spectrogram_img
95
 
96
  # Create the Gradio interface
97
  main()
 
3
  import numpy as np
4
  import os
5
  import soundfile as sf
 
6
 
7
  def main():
8
  # Gradio Interface
 
10
  gr.Markdown(
11
  """
12
  # <div align="center"> Ilaria Audio Analyzer πŸ’– (BETA) </div>
13
+ Audio Analyzer Software by Ilaria, Help me on [Ko-Fi](https://ko-fi.com/ilariaowo)\n
14
+ Special thanks to [Alex Murkoff](https://github.com/alexlnkp) for helping me coding it!
15
 
16
+ Need help with AI? [Join AI Hub!](https://discord.gg/aihub)
17
  """
18
  )
19
 
 
22
  audio_input = gr.Audio(type='filepath')
23
  create_spec_butt = gr.Button(value='Create Spectrogram And Get Info', variant='primary')
24
  with gr.Column():
25
+ output_markdown = gr.Markdown(value="", visible=True)
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
 
 
62
 
63
  # Create a table with the audio file info
64
  info_table = f"""
65
+
66
+ | Information | Value |
67
+ | --- | --- |
68
+ | Duration | {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds |
69
+ | Samples per second | {audio_info.samplerate} Hz |
70
+ | Audio Channels | {audio_info.channels} |
71
+ | Bitrate | {bitrate:.2f} Mb/s |
72
  """
73
+
74
+ # Return the PNG file of the spectrogram and the info table
75
+ return info_table, 'spectrogram.png'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  # Create the Gradio interface
78
  main()