vpavlenko commited on
Commit
b12171d
·
1 Parent(s): ddd0154

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -30
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import os
3
- import tarfile
4
  import allin1
 
5
 
6
  from pathlib import Path
7
 
@@ -49,6 +49,16 @@ HEADER = """
49
 
50
  CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
51
 
 
 
 
 
 
 
 
 
 
 
52
  def analyze(path):
53
  path = Path(path)
54
  result = allin1.analyze(
@@ -64,13 +74,9 @@ def analyze(path):
64
  sonif_path = Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix()
65
 
66
  dissector_file = generate_dissector_data(path.stem, result)
 
67
 
68
- bass_file_path = f"demix/htdemucs/{path.stem}/bass.wav"
69
- drums_file_path = f"demix/htdemucs/{path.stem}/drums.wav"
70
- other_file_path = f"demix/htdemucs/{path.stem}/other.wav"
71
- vocals_file_path = f"demix/htdemucs/{path.stem}/vocals.wav"
72
-
73
- return result.bpm, fig, sonif_path, bass_file_path, drums_file_path, other_file_path, vocals_file_path, dissector_file
74
 
75
 
76
  with gr.Blocks() as demo:
@@ -94,41 +100,28 @@ with gr.Blocks() as demo:
94
  show_download_button=False,
95
  scale=9,
96
  )
97
- output_bass = gr.File(
98
- label="Bass File",
99
- type="file",
100
- )
101
- output_drums = gr.File(
102
- label="Drums File",
103
- type="file",
104
- )
105
- output_other = gr.File(
106
- label="Other File",
107
- type="file",
108
- )
109
- output_vocals = gr.File(
110
- label="Vocals File",
111
- type="file",
112
- )
113
- output_dissector = gr.File(
114
- label="Dissector File",
115
- type="file",
116
  )
117
  gr.Examples(
118
  examples=[
119
- './assets/kult.mp3',
 
 
 
120
  ],
121
  inputs=input_audio_path,
122
- outputs=[output_bpm, output_viz, output_sonif, output_bass, output_drums, output_other, output_vocals, output_dissector],
123
  fn=analyze,
124
  cache_examples=CACHE_EXAMPLES,
125
  )
126
  button.click(
127
  fn=analyze,
128
  inputs=input_audio_path,
129
- outputs=[output_bpm, output_viz, output_sonif, output_bass, output_drums, output_other, output_vocals, output_dissector],
130
  api_name='analyze',
131
  )
132
 
133
  if __name__ == '__main__':
134
- demo.launch()
 
1
  import gradio as gr
2
  import os
 
3
  import allin1
4
+ import zipfile
5
 
6
  from pathlib import Path
7
 
 
49
 
50
  CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
51
 
52
+ def compress_files(folder_path, dissector_file):
53
+ """Compresses files in the specified folder into a .zip file"""
54
+ zip_path = folder_path + ".zip"
55
+ with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
56
+ for root, _, files in os.walk(folder_path):
57
+ for file in files:
58
+ zipf.write(os.path.join(root, file), arcname=file)
59
+ zipf.write(dissector_file, arcname=os.path.basename(dissector_file))
60
+ return zip_path
61
+
62
  def analyze(path):
63
  path = Path(path)
64
  result = allin1.analyze(
 
74
  sonif_path = Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix()
75
 
76
  dissector_file = generate_dissector_data(path.stem, result)
77
+ compressed_file = compress_files(f"demix/htdemucs/{path.stem}", dissector_file)
78
 
79
+ return result.bpm, fig, sonif_path, compressed_file
 
 
 
 
 
80
 
81
 
82
  with gr.Blocks() as demo:
 
100
  show_download_button=False,
101
  scale=9,
102
  )
103
+ output_compressed = gr.File(
104
+ label="Compressed Files",
105
+ type="file",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  )
107
  gr.Examples(
108
  examples=[
109
+ './assets/kult.mp3',
110
+ # './assets/krematorii.mp3',
111
+ # './assets/NewJeans - Super Shy.mp3',
112
+ # './assets/Bruno Mars - 24k Magic.mp3'
113
  ],
114
  inputs=input_audio_path,
115
+ outputs=[output_bpm, output_viz, output_sonif, output_compressed],
116
  fn=analyze,
117
  cache_examples=CACHE_EXAMPLES,
118
  )
119
  button.click(
120
  fn=analyze,
121
  inputs=input_audio_path,
122
+ outputs=[output_bpm, output_viz, output_sonif, output_compressed],
123
  api_name='analyze',
124
  )
125
 
126
  if __name__ == '__main__':
127
+ demo.launch()