TheStinger commited on
Commit
bdcf458
β€’
1 Parent(s): fa04576

Added support to download audio files from Google Drive

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -3,6 +3,21 @@ import matplotlib.pyplot as plt
3
  import numpy as np
4
  import os
5
  import soundfile as sf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def main():
8
  # Gradio Interface
@@ -10,10 +25,10 @@ def main():
10
  gr.Markdown(
11
  """
12
  # <div align="center"> Ilaria Audio Analyzer πŸ’– </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
 
@@ -21,10 +36,19 @@ def main():
21
  with gr.Column():
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)
@@ -64,11 +88,12 @@ def create_spectrogram_and_get_info(audio_file):
64
  speed_in_kbps = audio_info.samplerate * bit_depth / 1000
65
 
66
  # Create a table with the audio file info
 
67
  info_table = f"""
68
 
69
  | Information | Value |
70
  | :---: | :---: |
71
- | File Name | {os.path.basename(audio_file)} |
72
  | Duration | {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds |
73
  | Bitrate | {speed_in_kbps} kbp/s |
74
  | Audio Channels | {audio_info.channels} |
 
3
  import numpy as np
4
  import os
5
  import soundfile as sf
6
+ import requests
7
+
8
+ def download_file(url):
9
+ # Estrai l'ID del file dal link di Google Drive
10
+ file_id = url.split('/')[-2]
11
+
12
+ # Crea il link di download diretto
13
+ download_url = f'https://docs.google.com/uc?export=download&id={file_id}'
14
+
15
+ # Scarica il file
16
+ response = requests.get(download_url, allow_redirects=True)
17
+ local_filename = url.split('/')[-1] + '.wav'
18
+ open(local_filename, 'wb').write(response.content)
19
+
20
+ return local_filename
21
 
22
  def main():
23
  # Gradio Interface
 
25
  gr.Markdown(
26
  """
27
  # <div align="center"> Ilaria Audio Analyzer πŸ’– </div>
28
+ Audio Analyzer Software by Ilaria, Help me on Ko-Fi\n
29
+ Special thanks to Alex Murkoff for helping me coding it!
30
 
31
+ Need help with AI? Join AI Hub!
32
  """
33
  )
34
 
 
36
  with gr.Column():
37
  audio_input = gr.Audio(type='filepath')
38
  create_spec_butt = gr.Button(value='Create Spectrogram And Get Info', variant='primary')
39
+
40
  with gr.Column():
41
  output_markdown = gr.Markdown(value="", visible=True)
42
  image_output = gr.Image(type='filepath', interactive=False)
43
+
44
+ with gr.Accordion('Audio Downloader', open=False):
45
+ url_input = gr.Textbox(value='', label='Google Drive Audio URL')
46
+ download_butt = gr.Button(value='Download audio', variant='primary')
47
+
48
+ download_butt.click(fn=download_file, inputs=[url_input], outputs=[audio_input])
49
+ create_spec_butt.click(fn=create_spectrogram_and_get_info, inputs=[audio_input], outputs=[output_markdown, image_output])
50
+
51
+ download_butt.click(fn=download_file, inputs=[url_input], outputs=[audio_input])
52
  create_spec_butt.click(fn=create_spectrogram_and_get_info, inputs=[audio_input], outputs=[output_markdown, image_output])
53
 
54
  app.queue(max_size=1022).launch(share=True)
 
88
  speed_in_kbps = audio_info.samplerate * bit_depth / 1000
89
 
90
  # Create a table with the audio file info
91
+ filename_without_extension, _ = os.path.splitext(os.path.basename(audio_file))
92
  info_table = f"""
93
 
94
  | Information | Value |
95
  | :---: | :---: |
96
+ | File Name | {filename_without_extension} |
97
  | Duration | {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds |
98
  | Bitrate | {speed_in_kbps} kbp/s |
99
  | Audio Channels | {audio_info.channels} |