Commit
·
c06ddef
1
Parent(s):
7c6792a
feat: move spec plot to cpu task
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ def gen_task_id(location: str):
|
|
| 36 |
return md5(video).hexdigest()
|
| 37 |
|
| 38 |
|
| 39 |
-
def extract_audio(video: str) -> Tuple[str, str
|
| 40 |
task_id = gen_task_id(video)
|
| 41 |
os.makedirs(path.join("task", task_id), exist_ok=True)
|
| 42 |
|
|
@@ -50,6 +50,14 @@ def extract_audio(video: str) -> Tuple[str, str, str]:
|
|
| 50 |
f"ffmpeg -i {videodest} -vn -ar 48000 task/{task_id}/extracted_48k.wav"
|
| 51 |
)
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
spec = path.join("task", task_id, "extracted_48k.png")
|
| 54 |
if not path.exists(spec):
|
| 55 |
y, sr = librosa.load(wav48k, sr=16000)
|
|
@@ -57,11 +65,11 @@ def extract_audio(video: str) -> Tuple[str, str, str]:
|
|
| 57 |
fig.savefig(path.join("task", task_id, "extracted_48k.png"))
|
| 58 |
plt.close(fig)
|
| 59 |
|
| 60 |
-
return
|
| 61 |
|
| 62 |
|
| 63 |
@zero()
|
| 64 |
-
def extract_vocals(task_id: str) ->
|
| 65 |
audio = path.join("task", task_id, "extracted_48k.wav")
|
| 66 |
if not path.exists(audio):
|
| 67 |
raise gr.Error("Audio file not found")
|
|
@@ -83,6 +91,14 @@ def extract_vocals(task_id: str) -> Tuple[str, str]:
|
|
| 83 |
]
|
| 84 |
)
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
spec = path.join("task", task_id, "vocals.png")
|
| 87 |
if not path.exists(spec):
|
| 88 |
y, sr = librosa.load(vocals, sr=16000)
|
|
@@ -90,7 +106,7 @@ def extract_vocals(task_id: str) -> Tuple[str, str]:
|
|
| 90 |
fig.savefig(path.join("task", task_id, "vocals.png"))
|
| 91 |
plt.close(fig)
|
| 92 |
|
| 93 |
-
return
|
| 94 |
|
| 95 |
|
| 96 |
@zero(duration=60 * 2)
|
|
@@ -241,14 +257,11 @@ with gr.Blocks() as app:
|
|
| 241 |
speaker_clip_zip = gr.File(label="Download Audio Segments")
|
| 242 |
|
| 243 |
def preprocess(video: str):
|
| 244 |
-
task_id_val, extracted_audio_val
|
| 245 |
-
video
|
| 246 |
-
)
|
| 247 |
return {
|
| 248 |
preprocess_output: gr.Column(visible=True),
|
| 249 |
task_id: task_id_val,
|
| 250 |
extracted_audio: extracted_audio_val,
|
| 251 |
-
extracted_audio_spec: extracted_audio_spec_val,
|
| 252 |
preprocess_btn_label: gr.Markdown("", visible=False),
|
| 253 |
}
|
| 254 |
|
|
@@ -259,26 +272,34 @@ with gr.Blocks() as app:
|
|
| 259 |
preprocess_output,
|
| 260 |
task_id,
|
| 261 |
extracted_audio,
|
| 262 |
-
extracted_audio_spec,
|
| 263 |
preprocess_btn_label,
|
| 264 |
],
|
| 265 |
api_name="preprocess",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
)
|
| 267 |
|
| 268 |
def extract_vocals_fn(task_id: str):
|
| 269 |
-
vocals_val
|
| 270 |
return {
|
| 271 |
extract_vocals_output: gr.Column(visible=True),
|
| 272 |
vocals: vocals_val,
|
| 273 |
-
vocals_spec: vocals_spec_val,
|
| 274 |
extract_vocals_btn_label: gr.Markdown("", visible=False),
|
| 275 |
}
|
| 276 |
|
| 277 |
extract_vocals_btn.click(
|
| 278 |
fn=extract_vocals_fn,
|
| 279 |
inputs=[task_id],
|
| 280 |
-
outputs=[extract_vocals_output, vocals,
|
| 281 |
-
api_name="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
)
|
| 283 |
|
| 284 |
def diarize_fn(task_id: str):
|
|
|
|
| 36 |
return md5(video).hexdigest()
|
| 37 |
|
| 38 |
|
| 39 |
+
def extract_audio(video: str) -> Tuple[str, str]:
|
| 40 |
task_id = gen_task_id(video)
|
| 41 |
os.makedirs(path.join("task", task_id), exist_ok=True)
|
| 42 |
|
|
|
|
| 50 |
f"ffmpeg -i {videodest} -vn -ar 48000 task/{task_id}/extracted_48k.wav"
|
| 51 |
)
|
| 52 |
|
| 53 |
+
return (task_id, wav48k)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def extract_audio_post(task_id: str) -> str:
|
| 57 |
+
wav48k = path.join("task", task_id, "extracted_48k.wav")
|
| 58 |
+
if not path.exists(wav48k):
|
| 59 |
+
raise gr.Error("Audio file not found")
|
| 60 |
+
|
| 61 |
spec = path.join("task", task_id, "extracted_48k.png")
|
| 62 |
if not path.exists(spec):
|
| 63 |
y, sr = librosa.load(wav48k, sr=16000)
|
|
|
|
| 65 |
fig.savefig(path.join("task", task_id, "extracted_48k.png"))
|
| 66 |
plt.close(fig)
|
| 67 |
|
| 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):
|
| 75 |
raise gr.Error("Audio file not found")
|
|
|
|
| 91 |
]
|
| 92 |
)
|
| 93 |
|
| 94 |
+
return vocals
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def extract_vocals_post(task_id: str) -> str:
|
| 98 |
+
vocals = path.join("task", task_id, "htdemucs", "extracted_48k", "vocals.wav")
|
| 99 |
+
if not path.exists(vocals):
|
| 100 |
+
raise gr.Error("Vocals file not found")
|
| 101 |
+
|
| 102 |
spec = path.join("task", task_id, "vocals.png")
|
| 103 |
if not path.exists(spec):
|
| 104 |
y, sr = librosa.load(vocals, sr=16000)
|
|
|
|
| 106 |
fig.savefig(path.join("task", task_id, "vocals.png"))
|
| 107 |
plt.close(fig)
|
| 108 |
|
| 109 |
+
return spec
|
| 110 |
|
| 111 |
|
| 112 |
@zero(duration=60 * 2)
|
|
|
|
| 257 |
speaker_clip_zip = gr.File(label="Download Audio Segments")
|
| 258 |
|
| 259 |
def preprocess(video: str):
|
| 260 |
+
task_id_val, extracted_audio_val = extract_audio(video)
|
|
|
|
|
|
|
| 261 |
return {
|
| 262 |
preprocess_output: gr.Column(visible=True),
|
| 263 |
task_id: task_id_val,
|
| 264 |
extracted_audio: extracted_audio_val,
|
|
|
|
| 265 |
preprocess_btn_label: gr.Markdown("", visible=False),
|
| 266 |
}
|
| 267 |
|
|
|
|
| 272 |
preprocess_output,
|
| 273 |
task_id,
|
| 274 |
extracted_audio,
|
|
|
|
| 275 |
preprocess_btn_label,
|
| 276 |
],
|
| 277 |
api_name="preprocess",
|
| 278 |
+
).success(
|
| 279 |
+
fn=extract_audio_post,
|
| 280 |
+
inputs=[task_id],
|
| 281 |
+
outputs=[extracted_audio_spec],
|
| 282 |
+
api_name="preprocess-post",
|
| 283 |
)
|
| 284 |
|
| 285 |
def extract_vocals_fn(task_id: str):
|
| 286 |
+
vocals_val = extract_vocals(task_id)
|
| 287 |
return {
|
| 288 |
extract_vocals_output: gr.Column(visible=True),
|
| 289 |
vocals: vocals_val,
|
|
|
|
| 290 |
extract_vocals_btn_label: gr.Markdown("", visible=False),
|
| 291 |
}
|
| 292 |
|
| 293 |
extract_vocals_btn.click(
|
| 294 |
fn=extract_vocals_fn,
|
| 295 |
inputs=[task_id],
|
| 296 |
+
outputs=[extract_vocals_output, vocals, extract_vocals_btn_label],
|
| 297 |
+
api_name="extract-vocals",
|
| 298 |
+
).success(
|
| 299 |
+
fn=extract_vocals_post,
|
| 300 |
+
inputs=[task_id],
|
| 301 |
+
outputs=[vocals_spec],
|
| 302 |
+
api_name="extract-vocals-post",
|
| 303 |
)
|
| 304 |
|
| 305 |
def diarize_fn(task_id: str):
|