Spaces:
Sleeping
Sleeping
import gradio as gr | |
import allin1 | |
from pathlib import Path | |
def greet(path, progress=gr.Progress(track_tqdm=True)): | |
path = Path(path) | |
result = allin1.analyze( | |
path, | |
keep_byproducts=True, # TODO: remove this | |
) | |
fig = allin1.visualize(result) | |
allin1.sonify(result, out_dir='./sonif') | |
import os | |
def list_files(startpath): | |
for root, dirs, files in os.walk(startpath): | |
level = root.replace(startpath, '').count(os.sep) | |
indent = ' ' * 4 * level | |
print('{}{}/'.format(indent, os.path.basename(root))) | |
subindent = ' ' * 4 * (level + 1) | |
for f in files: | |
print('{}{}'.format(subindent, f)) | |
startpath = '.' # start from the current directory | |
list_files(startpath) | |
return fig, Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix() | |
with gr.Blocks() as demo: | |
input_audio_path = gr.Audio( | |
label='Input', | |
source='upload', | |
type='filepath', | |
format='mp3', | |
show_download_button=False, | |
) | |
output_viz = gr.Plot(label='Visualization') | |
output_sonif = gr.Audio( | |
label='Sonification', | |
type='filepath', | |
format='mp3', | |
show_download_button=False, | |
) | |
greet_btn = gr.Button('Analyze') | |
greet_btn.click( | |
fn=greet, | |
inputs=input_audio_path, | |
outputs=[output_viz, output_sonif], | |
api_name='analyze', | |
) | |
if __name__ == '__main__': | |
demo.queue().launch() | |