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( """
A demo for Pop2Piano:Pop Audio-based Piano Cover Generation. Please select the composer and upload the pop audio to submit.