Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,82 +1,82 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
CHECKPOINTS_DIR =
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
#
|
| 18 |
MODEL_NAME = CHECKPOINTS_DIR / "audiosep_base_4M_steps.ckpt"
|
| 19 |
-
|
| 20 |
config_yaml="config/audiosep_base.yaml",
|
| 21 |
-
checkpoint_path=
|
| 22 |
-
|
| 23 |
)
|
| 24 |
|
| 25 |
|
| 26 |
-
|
| 27 |
-
# AudioSep:
|
| 28 |
-
[[
|
| 29 |
|
| 30 |
-
AudioSep
|
| 31 |
-
AudioSep
|
| 32 |
-
|
| 33 |
"""
|
| 34 |
|
| 35 |
|
| 36 |
-
def inference(
|
| 37 |
-
print(f"
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
)
|
| 46 |
|
| 47 |
input_dict = {
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
}
|
| 51 |
|
| 52 |
-
sep_segment =
|
| 53 |
|
| 54 |
sep_segment = sep_segment.squeeze(0).squeeze(0).data.cpu().numpy()
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
|
| 59 |
-
|
| 60 |
-
gr.Markdown(
|
| 61 |
-
|
| 62 |
-
|
| 63 |
input_audio = gr.Audio(label="Mixture", type="filepath")
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
output_audio = gr.Audio(label="
|
| 68 |
-
|
| 69 |
-
"
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
)
|
| 75 |
-
|
| 76 |
-
fn=
|
| 77 |
)
|
| 78 |
|
| 79 |
-
gr.Markdown("##
|
| 80 |
-
gr.Examples(
|
| 81 |
|
| 82 |
-
demo.queue().launch(
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from threading import Thread
|
| 3 |
|
| 4 |
+
import gdown
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import librosa
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
|
| 10 |
+
from gradio_examples import EXAMPLES
|
| 11 |
+
from pipeline import build_audiosep
|
| 12 |
|
| 13 |
+
CHECKPOINTS_DIR = Path("checkpoint")
|
| 14 |
|
| 15 |
+
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
|
| 17 |
+
# The model will be loaded in the future
|
| 18 |
MODEL_NAME = CHECKPOINTS_DIR / "audiosep_base_4M_steps.ckpt"
|
| 19 |
+
MODEL = build_audiosep(
|
| 20 |
config_yaml="config/audiosep_base.yaml",
|
| 21 |
+
checkpoint_path=MODEL_NAME,
|
| 22 |
+
device=DEVICE,
|
| 23 |
)
|
| 24 |
|
| 25 |
|
| 26 |
+
description = """
|
| 27 |
+
# AudioSep: Separate Anything You Describe
|
| 28 |
+
[[Project Page]](https://audio-agi.github.io/Separate-Anything-You-Describe) [[Paper]](https://audio-agi.github.io/Separate-Anything-You-Describe/AudioSep_arXiv.pdf) [[Code]](https://github.com/Audio-AGI/AudioSep)
|
| 29 |
|
| 30 |
+
AudioSep is a foundation model for open-domain sound separation with natural language queries.
|
| 31 |
+
AudioSep demonstrates strong separation performance and impressivezero-shot generalization ability on
|
| 32 |
+
numerous tasks such as audio event separation, musical instrument separation, and speech enhancement.
|
| 33 |
"""
|
| 34 |
|
| 35 |
|
| 36 |
+
def inference(audio_file_path: str, text: str):
|
| 37 |
+
print(f"Separate audio from [{audio_file_path}] with textual query [{text}]")
|
| 38 |
+
mixture, _ = librosa.load(audio_file_path, sr=32000, mono=True)
|
| 39 |
|
| 40 |
+
with torch.no_grad():
|
| 41 |
+
text = [text]
|
| 42 |
|
| 43 |
+
conditions = MODEL.query_encoder.get_query_embed(
|
| 44 |
+
modality="text", text=text, device=DEVICE
|
| 45 |
)
|
| 46 |
|
| 47 |
input_dict = {
|
| 48 |
+
"mixture": torch.Tensor(mixture)[None, None, :].to(DEVICE),
|
| 49 |
+
"condition": conditions,
|
| 50 |
}
|
| 51 |
|
| 52 |
+
sep_segment = MODEL.ss_model(input_dict)["waveform"]
|
| 53 |
|
| 54 |
sep_segment = sep_segment.squeeze(0).squeeze(0).data.cpu().numpy()
|
| 55 |
|
| 56 |
+
return 32000, np.round(sep_segment * 32767).astype(np.int16)
|
| 57 |
|
| 58 |
|
| 59 |
+
with gr.Blocks(title="AudioSep") as demo:
|
| 60 |
+
gr.Markdown(description)
|
| 61 |
+
with gr.Row():
|
| 62 |
+
with gr.Column():
|
| 63 |
input_audio = gr.Audio(label="Mixture", type="filepath")
|
| 64 |
+
text = gr.Textbox(label="Text Query")
|
| 65 |
+
with gr.Column():
|
| 66 |
+
with gr.Column():
|
| 67 |
+
output_audio = gr.Audio(label="Separation Result", scale=10)
|
| 68 |
+
button = gr.Button(
|
| 69 |
+
"Separate",
|
| 70 |
+
variant="primary",
|
| 71 |
+
scale=2,
|
| 72 |
+
size="lg",
|
| 73 |
+
interactive=True,
|
| 74 |
)
|
| 75 |
+
button.click(
|
| 76 |
+
fn=inference, inputs=[input_audio, text], outputs=[output_audio]
|
| 77 |
)
|
| 78 |
|
| 79 |
+
gr.Markdown("## Examples")
|
| 80 |
+
gr.Examples(examples=EXAMPLES, inputs=[input_audio, text])
|
| 81 |
|
| 82 |
+
demo.queue().launch(share=True)
|