diablofx commited on
Commit
ea674af
·
1 Parent(s): 8ef3f44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -33
app.py CHANGED
@@ -1,19 +1,14 @@
1
  import gradio as gr
2
- import matplotlib.pyplot as plt
3
- import numpy as np
4
  import os
5
  import soundfile as sf
6
- from pydub import AudioSegment
7
- import tempfile
8
- import zipfile
9
-
10
 
11
  def main():
12
  with gr.Blocks() as app:
13
  gr.Markdown(
14
  """
15
  # <div align="center"> diablofx Audio Interval Cutter (BETA) </div>
16
- Want to [support](https://ko-fi.com/diablofx) me? [Ko-Fi]\n
17
 
18
  Need help with AI? [Join AI Hub!](https://discord.gg/aihub)
19
  """
@@ -22,33 +17,15 @@ def main():
22
  with gr.Row():
23
  with gr.Column():
24
  audio_input = gr.File(label="Upload an audio file")
25
- interval_input = gr.Textbox("5000", label="Interval Length (ms)")
26
- process_button = gr.Button(value='Process Audio and Get Info', variant='primary')
27
  with gr.Column():
28
- output_html = gr.HTML("Processed audio information will appear here")
29
 
30
  process_button.click(fn=process_audio_and_display_info, inputs=[audio_input, interval_input], outputs=output_html)
31
 
32
  app.queue(max_size=1022).launch(share=True)
33
 
34
- def cut_audio(audio_file, output_path, interval):
35
- audio = AudioSegment.from_file(audio_file)
36
- duration = len(audio)
37
-
38
- cuts = [audio[i:i + interval] for i in range(0, duration, interval)]
39
-
40
- with tempfile.TemporaryDirectory() as temp_dir:
41
- for i, cut in enumerate(cuts):
42
- cut.export(os.path.join(temp_dir, f'cut_{i}.wav'), format="wav")
43
-
44
- zip_file_path = os.path.join(output_path, "cuts.zip")
45
- with zipfile.ZipFile(zip_file_path, 'w') as zipf:
46
- for root, _, files in os.walk(temp_dir):
47
- for file in files:
48
- zipf.write(os.path.join(root, file), os.path.basename(file))
49
-
50
- return zip_file_path
51
-
52
  def process_audio_and_display_info(audio_file, interval):
53
  # Get the audio file info
54
  audio_info = sf.info(audio_file)
@@ -78,11 +55,8 @@ def process_audio_and_display_info(audio_file, interval):
78
  | Bit per second | {audio_info.samplerate * audio_info.channels * bit_depth} bit/s |
79
  """
80
 
81
- # Process the audio file and get the path to the zip file
82
- zip_file_path = cut_audio(audio_file, tempfile.mkdtemp(), int(interval))
83
-
84
- # Create a download link
85
- download_link = f'<a href="/download/{os.path.basename(zip_file_path)}" download>Click here to download processed audio</a>'
86
 
87
  # Return the information table and the download link
88
  return info_table, download_link
 
1
  import gradio as gr
 
 
2
  import os
3
  import soundfile as sf
4
+ from audio_processor import process_audio
 
 
 
5
 
6
  def main():
7
  with gr.Blocks() as app:
8
  gr.Markdown(
9
  """
10
  # <div align="center"> diablofx Audio Interval Cutter (BETA) </div>
11
+ Want to [support](https://ko-fi.com/diablofx) me?\n
12
 
13
  Need help with AI? [Join AI Hub!](https://discord.gg/aihub)
14
  """
 
17
  with gr.Row():
18
  with gr.Column():
19
  audio_input = gr.File(label="Upload an audio file")
20
+ interval_input = gr.Textbox("5000", label="Interval Length (in ms)")
21
+ process_button = gr.Button(value='Start', variant='primary')
22
  with gr.Column():
23
+ output_html = gr.HTML("Processed data will appear here")
24
 
25
  process_button.click(fn=process_audio_and_display_info, inputs=[audio_input, interval_input], outputs=output_html)
26
 
27
  app.queue(max_size=1022).launch(share=True)
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def process_audio_and_display_info(audio_file, interval):
30
  # Get the audio file info
31
  audio_info = sf.info(audio_file)
 
55
  | Bit per second | {audio_info.samplerate * audio_info.channels * bit_depth} bit/s |
56
  """
57
 
58
+ # Process the audio file and get the download link
59
+ download_link = process_audio(audio_file, interval)
 
 
 
60
 
61
  # Return the information table and the download link
62
  return info_table, download_link