import argparse import glob import os.path import gradio as gr import pickle import tqdm import json import MIDI from midi_synthesizer import synthesis in_space = os.getenv("SYSTEM") == "spaces" def run(search_prompt, mid=None, progress=gr.Progress()): if mid == None: for m in progress.tqdm(meta_data): mid_seq = [] mid_seq.extend(m[1][17:]) mid_seq_ticks = m[1][16][1] mdata = m[1][:17] # break elif mid is not None: mid_seq = MIDI.midi2score(mid) with open(f"output.mid", 'wb') as f: f.write(MIDI.score2midi([mid_seq_ticks, mid_seq])) audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path) yield mdata, "output.mid", (44100, audio) def cancel_run(mid_seq): if mid_seq is None: return None, None with open(f"output.mid", 'wb') as f: f.write(MIDI.score2midi([1000, mid_seq])) audio = synthesis(MIDI.score2opus([1000, mid_seq]), soundfont_path) return "output.mid", (44100, audio) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--share", action="store_true", default=False, help="share gradio app") parser.add_argument("--port", type=int, default=7860, help="gradio server port") parser.add_argument("--max-gen", type=int, default=1024, help="max") opt = parser.parse_args() soundfont_path = "SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2" meta_data_path = "meta-data/LAMD_META_10000.pickle" models_info = {"generic pretrain model": ["skytnt/midi-model", ""], "j-pop finetune model": ["skytnt/midi-model-ft", "jpop/"], "touhou finetune model": ["skytnt/midi-model-ft", "touhou/"]} print('Loading meta-data...') with open(meta_data_path, 'rb') as f: meta_data = pickle.load(f) print('Done!') app = gr.Blocks() with app: gr.Markdown("