Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,75 +1,4 @@
|
|
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 |
-
"""
|
15 |
-
)
|
16 |
-
|
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)
|
32 |
-
|
33 |
-
bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)
|
34 |
-
|
35 |
-
# Convert duration to minutes, seconds, and milliseconds
|
36 |
-
minutes, seconds = divmod(audio_info.duration, 60)
|
37 |
-
seconds, milliseconds = divmod(seconds, 1)
|
38 |
-
milliseconds *= 1000 # convert from seconds to milliseconds
|
39 |
-
|
40 |
-
# Convert bitrate to kbp/s
|
41 |
-
bitrate = audio_info.samplerate * audio_info.channels * bit_depth / 1000
|
42 |
-
|
43 |
-
# Calculate speed in kbps
|
44 |
-
speed_in_kbps = audio_info.samplerate * bit_depth / 1000
|
45 |
-
|
46 |
-
# Create a table with the audio file info
|
47 |
-
info_table = f"""
|
48 |
-
| Information | Value |
|
49 |
-
| :---: | :---: |
|
50 |
-
| File Name | {os.path.basename(audio_file)} |
|
51 |
-
| Duration | {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds |
|
52 |
-
| Bitrate | {bitrate} kbp/s |
|
53 |
-
| Audio Channels | {audio_info.channels} |
|
54 |
-
| Samples per second | {audio_info.samplerate} Hz |
|
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
|
63 |
-
|
64 |
-
|
65 |
-
if __name__ == "__main__":
|
66 |
-
main()
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
------------------
|
72 |
-
import gradio as gr
|
73 |
import matplotlib.pyplot as plt
|
74 |
import numpy as np
|
75 |
import os
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import numpy as np
|
4 |
import os
|