import gradio as gr import os import allin1 import time from pathlib import Path HEADER = """

All-In-One Music Structure Analyzer 🔮

[Python Package] [Paper] [Visual Demo]

This Space demonstrates the music structure analyzer predicts:

For more information, please visit the links above ✨🧸

""" CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1' def analyze(path): #Measure time for inference start = time.time() path = Path(path) result, stems_paths = allin1.analyze( path, out_dir='./struct', multiprocess=False, keep_byproducts=True, # TODO: remove this ) print(stems_paths) #stems_paths_string ="" #for stem in stems_paths: # stems_paths_string += stem + '\n' fig = allin1.visualize( result, multiprocess=False, ) fig.set_dpi(300) allin1.sonify( result, out_dir='./sonif', multiprocess=False, ) sonif_path = Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix() #Measure time for inference end = time.time() elapsed_time = end-start return result.bpm, fig, sonif_path, stems_paths, elapsed_time with gr.Blocks() as demo: gr.HTML(HEADER) input_audio_path = gr.Audio( label='Input', source='upload', type='filepath', format='mp3', show_download_button=False, ) button = gr.Button('Analyze', variant='primary') output_viz = gr.Plot(label='Visualization') with gr.Row(): output_bpm = gr.Textbox(label='BPM', scale=1) output_sonif = gr.Audio( label='Sonification', type='filepath', format='mp3', show_download_button=False, scale=9, ) elapsed_time = gr.Textbox(label='Overall inference time', scale=1) with gr.Row(): stems_paths = gr.Textbox(label='stems paths', scale=1) #gr.Examples( # examples=[ # './assets/NewJeans - Super Shy.mp3', # './assets/Bruno Mars - 24k Magic.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, stems_paths, elapsed_time], api_name='analyze', ) if __name__ == '__main__': demo.launch()