vpavlenko commited on
Commit
a07d0b1
·
1 Parent(s): ccee7e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -46,6 +46,14 @@ HEADER = """
46
 
47
  CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
48
 
 
 
 
 
 
 
 
 
49
 
50
  def analyze(path):
51
  path = Path(path)
@@ -61,7 +69,9 @@ def analyze(path):
61
  allin1.sonify(result, out_dir='./sonif')
62
  sonif_path = Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix()
63
 
64
- return result.bpm, fig, sonif_path
 
 
65
 
66
 
67
  with gr.Blocks() as demo:
@@ -85,13 +95,19 @@ with gr.Blocks() as demo:
85
  show_download_button=False,
86
  scale=9,
87
  )
 
 
 
 
 
 
88
  gr.Examples(
89
  examples=[
90
  './assets/NewJeans - Super Shy.mp3',
91
  './assets/Bruno Mars - 24k Magic.mp3'
92
  ],
93
  inputs=input_audio_path,
94
- outputs=[output_bpm, output_viz, output_sonif],
95
  fn=analyze,
96
  cache_examples=CACHE_EXAMPLES,
97
  )
 
46
 
47
  CACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES', '1') == '1'
48
 
49
+ def compress_files(folder_path):
50
+ """Compresses files in the specified folder into a .tar.gz"""
51
+ tar_path = folder_path + ".tar.gz"
52
+ with tarfile.open(tar_path, "w:gz") as tar:
53
+ for root, _, files in os.walk(folder_path):
54
+ for file in files:
55
+ tar.add(os.path.join(root, file), arcname=file)
56
+ return tar_path
57
 
58
  def analyze(path):
59
  path = Path(path)
 
69
  allin1.sonify(result, out_dir='./sonif')
70
  sonif_path = Path(f'./sonif/{path.stem}.sonif{path.suffix}').resolve().as_posix()
71
 
72
+ compressed_file = compress_files(f"demix/htdemucs/{path.stem}")
73
+
74
+ return result.bpm, fig, sonif_path, compressed_file
75
 
76
 
77
  with gr.Blocks() as demo:
 
95
  show_download_button=False,
96
  scale=9,
97
  )
98
+ output_compressed = gr.File(
99
+ label="Compressed Files",
100
+ type="file",
101
+ format="tar.gz",
102
+ show_download_button=True,
103
+ )
104
  gr.Examples(
105
  examples=[
106
  './assets/NewJeans - Super Shy.mp3',
107
  './assets/Bruno Mars - 24k Magic.mp3'
108
  ],
109
  inputs=input_audio_path,
110
+ outputs=[output_bpm, output_viz, output_sonif, output_compressed],
111
  fn=analyze,
112
  cache_examples=CACHE_EXAMPLES,
113
  )