File size: 1,374 Bytes
27b1390
b1d66c1
27b1390
afa4c92
27b1390
afa4c92
 
 
b1d66c1
afa4c92
b1d66c1
 
afa4c92
 
b1d66c1
cb80448
 
 
 
 
 
 
 
 
 
 
 
 
 
756b159
b1d66c1
 
 
afa4c92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
756b159
afa4c92
b1d66c1
afa4c92
 
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
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()