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( """

Pop2piano

A demo for Pop2Piano:Pop Audio-based Piano Cover Generation. Please select the composer and upload the pop audio to submit.

""" ) 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( """ """ ) block.launch(debug=True)