Spaces:
Sleeping
Sleeping
hugo flores garcia
commited on
Commit
·
1b1b9de
1
Parent(s):
08c78c6
defaults
Browse files
app.py
CHANGED
|
@@ -15,7 +15,6 @@ import gradio as gr
|
|
| 15 |
from vampnet.interface import Interface, signal_concat
|
| 16 |
from vampnet import mask as pmask
|
| 17 |
|
| 18 |
-
|
| 19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 20 |
|
| 21 |
interface = Interface.default()
|
|
@@ -165,7 +164,41 @@ def api_vamp(data):
|
|
| 165 |
)
|
| 166 |
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
with gr.Blocks() as demo:
|
|
@@ -211,7 +244,7 @@ with gr.Blocks() as demo:
|
|
| 211 |
minimum=0,
|
| 212 |
maximum=13,
|
| 213 |
step=1,
|
| 214 |
-
value=
|
| 215 |
)
|
| 216 |
|
| 217 |
onset_mask_width = gr.Slider(
|
|
@@ -385,6 +418,29 @@ with gr.Blocks() as demo:
|
|
| 385 |
api_name="vamp"
|
| 386 |
)
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
for i, btn in enumerate(use_as_input_btns):
|
| 389 |
btn.click(
|
| 390 |
fn=load_audio,
|
|
|
|
| 15 |
from vampnet.interface import Interface, signal_concat
|
| 16 |
from vampnet import mask as pmask
|
| 17 |
|
|
|
|
| 18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
|
| 20 |
interface = Interface.default()
|
|
|
|
| 164 |
)
|
| 165 |
|
| 166 |
|
| 167 |
+
OUT_DIR = Path("gradio-outputs")
|
| 168 |
+
OUT_DIR.mkdir(exist_ok=True)
|
| 169 |
+
def harp_vamp(input_audio_file, periodic_p, n_mask_codebooks, pitch_shift_amt):
|
| 170 |
+
sig = at.AudioSignal(input_audio_file)
|
| 171 |
+
sr, samples = sig.sample_rate, sig.samples[0][0].detach().cpu().numpy()
|
| 172 |
+
# convert to int32
|
| 173 |
+
samples = (samples * np.iinfo(np.int32).max).astype(np.int32)
|
| 174 |
+
sr, samples = _vamp(
|
| 175 |
+
seed=0,
|
| 176 |
+
input_audio=(sr, samples),
|
| 177 |
+
model_choice="default",
|
| 178 |
+
pitch_shift_amt=pitch_shift_amt,
|
| 179 |
+
periodic_p=periodic_p,
|
| 180 |
+
n_mask_codebooks=n_mask_codebooks,
|
| 181 |
+
periodic_w=1,
|
| 182 |
+
onset_mask_width=0,
|
| 183 |
+
dropout=0.0,
|
| 184 |
+
sampletemp=1.0,
|
| 185 |
+
typical_filtering=True,
|
| 186 |
+
typical_mass=0.15,
|
| 187 |
+
typical_min_tokens=64,
|
| 188 |
+
top_p=0.0,
|
| 189 |
+
sample_cutoff=1.0,
|
| 190 |
+
stretch_factor=1,
|
| 191 |
+
)
|
| 192 |
|
| 193 |
+
sig = at.AudioSignal(samples, sr)
|
| 194 |
+
# write to file
|
| 195 |
+
# clear the outdir
|
| 196 |
+
for p in OUT_DIR.glob("*"):
|
| 197 |
+
p.unlink()
|
| 198 |
+
OUT_DIR.mkdir(exist_ok=True)
|
| 199 |
+
outpath = OUT_DIR / f"{uuid.uuid4()}.wav"
|
| 200 |
+
sig.write(outpath)
|
| 201 |
+
return outpath
|
| 202 |
|
| 203 |
|
| 204 |
with gr.Blocks() as demo:
|
|
|
|
| 244 |
minimum=0,
|
| 245 |
maximum=13,
|
| 246 |
step=1,
|
| 247 |
+
value=7,
|
| 248 |
)
|
| 249 |
|
| 250 |
onset_mask_width = gr.Slider(
|
|
|
|
| 418 |
api_name="vamp"
|
| 419 |
)
|
| 420 |
|
| 421 |
+
from pyharp import ModelCard, build_endpoint
|
| 422 |
+
card = ModelCard(
|
| 423 |
+
name="vampnet",
|
| 424 |
+
description="vampnet is a model for generating audio from audio",
|
| 425 |
+
author="hugo flores garcía",
|
| 426 |
+
tags=["music generation"],
|
| 427 |
+
midi_in=False,
|
| 428 |
+
midi_out=False
|
| 429 |
+
)
|
| 430 |
+
|
| 431 |
+
harp_in = gr.Audio(label="input audio", type="filepath", visible=False)
|
| 432 |
+
harp_out = gr.Audio(label="output audio", type="filepath", visible=False)
|
| 433 |
+
build_endpoint(
|
| 434 |
+
components=[
|
| 435 |
+
periodic_p,
|
| 436 |
+
n_mask_codebooks,
|
| 437 |
+
pitch_shift_amt,
|
| 438 |
+
],
|
| 439 |
+
process_fn=harp_vamp,
|
| 440 |
+
model_card=card
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
for i, btn in enumerate(use_as_input_btns):
|
| 445 |
btn.click(
|
| 446 |
fn=load_audio,
|