Spaces:
Running
Running
File size: 2,562 Bytes
7a3b53b 88490a8 b069716 88490a8 1aa2e4c 88490a8 7a3b53b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import gradio as gr
import os
from transformer_wrapper import TransformerWrapper
from omegaconf import OmegaConf
def get_file_content_as_string(path):
return open(path, "r", encoding="utf-8").read()
def model_load():
config = OmegaConf.load("config.yaml")
wrapper = TransformerWrapper(config)
wrapper = wrapper.load_from_checkpoint(
"https://huggingface.co/sweetcocoa/pop2piano/resolve/main/model-1999-val_0.67311615.ckpt",
config=config,
map_location="cpu",
)
model_id = "dpipqxiy"
wrapper.eval()
return wrapper, model_id, config
wrapper, model_id, config = model_load()
composers = list(config.composer_to_feature_token.keys())
dest_dir = "ytsamples"
os.makedirs(dest_dir, exist_ok=True)
def inference(file_up, composer):
midi, arranger, mix_path, midi_path = wrapper.generate(
audio_path=file_up,
composer=composer,
model=model_id,
ignore_duplicate=True,
show_plot=False,
save_midi=True,
save_mix=True,
)
return mix_path
block = gr.Blocks()
with block:
gr.HTML(
"""
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
<div
style="
display: inline-flex;
align-items: center;
gap: 0.8rem;
font-size: 1.75rem;
"
>
<h1 style="font-weight: 900; margin-bottom: 7px;">
Pop2piano
</h1>
</div>
<p style="margin-bottom: 10px; font-size: 94%">
A demo for Pop2Piano:Pop Audio-based Piano Cover Generation. Please select the composer and upload the pop audio to submit.
</p>
</div>
"""
)
with gr.Group():
with gr.Box():
with gr.Row().style(mobile_collapse=False, equal_height=True):
file_up = gr.Audio(label="Upload an audio", type="filepath")
composer = gr.Dropdown(label="Arranger", choices=composers, value="composer1")
btn = gr.Button("Convert")
out = gr.Audio(label="Output")
btn.click(inference, inputs=[file_up, composer], outputs=out)
gr.HTML(
"""
<div class="footer">
<p><a href="http://sweetcocoa.github.io/pop2piano_samples" style="text-decoration: underline;" target="_blank">Project Page</a>
</p>
</div>
"""
)
block.launch(debug=True)
|