JacobLinCool commited on
Commit
f325db1
1 Parent(s): c06ddef

feat: zip with zipfile module

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -12,6 +12,7 @@ from demucs.separate import main as demucs
12
  from pyannote.audio import Pipeline
13
  from json import dumps, loads
14
  import shutil
 
15
 
16
  accelerator = Accelerator()
17
  device = accelerator.device
@@ -68,7 +69,7 @@ def extract_audio_post(task_id: str) -> str:
68
  return spec
69
 
70
 
71
- @zero()
72
  def extract_vocals(task_id: str) -> str:
73
  audio = path.join("task", task_id, "extracted_48k.wav")
74
  if not path.exists(audio):
@@ -199,7 +200,10 @@ def generate_clips(task_id: str, speaker: str) -> Tuple[str, str]:
199
 
200
  segments_zip = path.join("task", task_id, f"{speaker}.zip")
201
  if not path.exists(segments_zip):
202
- os.system(f"zip -r {segments_zip} {segments}")
 
 
 
203
 
204
  return mp4, segments_zip
205
 
 
12
  from pyannote.audio import Pipeline
13
  from json import dumps, loads
14
  import shutil
15
+ import zipfile
16
 
17
  accelerator = Accelerator()
18
  device = accelerator.device
 
69
  return spec
70
 
71
 
72
+ @zero(duration=60 * 2)
73
  def extract_vocals(task_id: str) -> str:
74
  audio = path.join("task", task_id, "extracted_48k.wav")
75
  if not path.exists(audio):
 
200
 
201
  segments_zip = path.join("task", task_id, f"{speaker}.zip")
202
  if not path.exists(segments_zip):
203
+ with zipfile.ZipFile(segments_zip, "w") as zipf:
204
+ files = [f for f in os.listdir(segments) if f.endswith(".wav")]
205
+ for file in files:
206
+ zipf.write(path.join(segments, file), file)
207
 
208
  return mp4, segments_zip
209