Spaces:
Runtime error
Runtime error
File size: 1,985 Bytes
27b1390 3f9fabf b1d66c1 27b1390 afa4c92 27b1390 3f9fabf 4bb84bd afa4c92 269c399 3f9fabf 269c399 3f9fabf 4bb84bd 3f9fabf 4bb84bd afa4c92 b1d66c1 afa4c92 4bb84bd b1d66c1 afa4c92 4bb84bd b1d66c1 4bb84bd b1d66c1 3f9fabf 4bb84bd 3f9fabf afa4c92 4bb84bd afa4c92 4bb84bd 3f9fabf 4bb84bd afa4c92 4bb84bd 756b159 afa4c92 b1d66c1 3f9fabf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import gradio as gr
import os
import allin1
from pathlib import Path
HEADER = """
<header>
<h1>
All-In-One Music Structure Analyzer 🔮
</h1>
<p>
<a href="https://github.com/mir-aidj/all-in-one">[Python Package]</a>
<a href="https://arxiv.org/abs/2307.16425">[Paper]</a>
<a href="https://taejun.kim/music-dissector/">[Visual Demo]</a>
</p>
</header>
"""
DESCRIPTION = """
This Space demonstrates [All-In-One Music Structure Analyzer](https://github.com/mir-aidj/all-in-one),
a tool that predicts:
- BPM
- Beats
- Downbeats
- Functional segment boundaries
- Functional segment labels
For more information, please visit the links above ✨🧸
"""
CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
def analyze(path):
path = Path(path)
result = allin1.analyze(
path,
multiprocess=False,
keep_byproducts=True, # TODO: remove this
)
fig = allin1.visualize(result)
allin1.sonify(result, out_dir='./sonif')
sonif_path = Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix()
return result.bpm, fig, sonif_path
with gr.Blocks(css='style.css') as demo:
gr.HTML(HEADER)
gr.Markdown(DESCRIPTION)
input_audio_path = gr.Audio(
label='Input',
source='upload',
type='filepath',
format='mp3',
show_download_button=False,
)
button = gr.Button('Analyze', variant='primary')
output_bpm = gr.Textbox(label='BPM')
output_viz = gr.Plot(label='Visualization')
output_sonif = gr.Audio(
label='Sonification',
type='filepath',
format='mp3',
show_download_button=False,
)
gr.Examples(
examples=[
'./assets/NewJeans - Super Shy.mp3',
],
inputs=input_audio_path,
outputs=[output_bpm, output_viz, output_sonif],
fn=analyze,
cache_examples=CACHE_EXAMPLES,
)
button.click(
fn=analyze,
inputs=input_audio_path,
outputs=[output_bpm, output_viz, output_sonif],
api_name='analyze',
)
if __name__ == '__main__':
demo.launch()
|