Download app.py from akashdeb/audioo: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/akashdeb/audioo/resolve/main/app.py
- Command line
-
hf download hf://spaces/akashdeb/audioo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/akashdeb/audioo/resolve/main/app.py
1.39 kB
| import gradio as gr | |
| import os | |
| def display_audio_meter(audio_file): | |
| # Convert file path to a URL that can be used in the HTML and JavaScript | |
| audio_url = f"/file={audio_file}" | |
| # Embed the HTML for the audio meter visualization using wavesurfer.js | |
| html_code = f""" | |
| <html> | |
| <body> | |
| <script src="https://cdn.jsdelivr.net/npm/wavesurfer.js"></script> | |
| <div id="audio-meter" style="width: 100%; height: 128px; background-color: #f0f0f0;"></div> | |
| <script> | |
| const audioFile = '{audio_url}'; // Use the audio file URL in the script | |
| const waveSurfer = WaveSurfer.create({{ | |
| container: '#audio-meter', | |
| waveColor: 'blue', | |
| progressColor: 'green', | |
| height: 128 | |
| }}); | |
| waveSurfer.load(audioFile); // Load the audio file in the waveform | |
| </script> | |
| </body> | |
| </html> | |
| """ | |
| return html_code | |
| # Create Gradio Interface with a Submit button | |
| with gr.Blocks() as interface: | |
| # Audio input | |
| audio_input = gr.Audio(type="filepath") | |
| # Submit button | |
| submit_button = gr.Button("Submit") | |
| # Output area | |
| output = gr.HTML() | |
| # Button click triggers the audio meter display | |
| submit_button.click(fn=display_audio_meter, inputs=audio_input, outputs=output) | |
| # Launch the interface | |
| interface.launch(share=True) | |