diff --git a/README.md b/README.md index 255dee7..397e12e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ Authors: [Yu-Siang Huang](https://remyhuang.github.io/), [Yi-Hsuan Yang](http:// [**Paper (arXiv)**](https://arxiv.org/abs/2002.00212) | [**Blog**](https://ailabs.tw/human-interaction/pop-music-transformer/) | [**Audio demo (Google Drive)**](https://drive.google.com/open?id=1LzPBjHPip4S0CBOLquk5CNapvXSfys54) | [**Online interactive demo**](https://vibertthio.com/transformer/) +## Gradio Demo +[Gradio Web Demo](https://gradio.app/hub/AK391/remi) + REMI, which stands for `REvamped MIDI-derived events`, is a new event representation we propose for converting MIDI scores into text-like discrete tokens. Compared to the MIDI-like event representation adopted in exising Transformer-based music composition models, REMI provides sequence models a metrical context for modeling the rhythmic patterns of music. Using REMI as the event representation, we train a Transformer-XL model to generate minute-long Pop piano music with expressive, coherent and clear structure of rhythm and harmony, without needing any post-processing to refine the result. The model also provides controllability of local tempo changes and chord progression. ## Citation diff --git a/gradiodemo.py b/gradiodemo.py new file mode 100644 index 0000000..ba07eb9 --- /dev/null +++ b/gradiodemo.py @@ -0,0 +1,55 @@ +from model import PopMusicTransformer +import os +os.environ['CUDA_VISIBLE_DEVICES'] = '-1' +import tensorflow as tf +tf.compat.v1.disable_eager_execution() +import gradio as gr +import requests +import torchtext +import zipfile + +torchtext.utils.download_from_url("https://drive.google.com/uc?id=1gxuTSkF51NP04JZgTE46Pg4KQsbHQKGo", root=".") +torchtext.utils.download_from_url("https://drive.google.com/uc?id=1nAKjaeahlzpVAX0F9wjQEG_hL4UosSbo", root=".") + +with zipfile.ZipFile("REMI-tempo-checkpoint.zip","r") as zip_ref: + zip_ref.extractall(".") +with zipfile.ZipFile("REMI-tempo-chord-checkpoint.zip","r") as zip_ref: + zip_ref.extractall(".") + +url = 'https://github.com/AK391/remi/blob/master/input.midi?raw=true' +r = requests.get(url, allow_redirects=True) +open("input.midi", 'wb').write(r.content) + + +# declare model +model = PopMusicTransformer( + checkpoint='REMI-tempo-checkpoint', + is_training=False) + +def inference(midi): + # generate continuation + model.generate( + n_target_bar=4, + temperature=1.2, + topk=5, + output_path='./result/continuation.midi', + prompt=midi.name) + return './result/continuation.midi' + + +title = "Pop Music Transformer" +description = "demo for Pop Music Transformer. To use it, simply upload your midi file, or click one of the examples to load them. Read more at the links below." +article = "

Pop Music Transformer: Beat-based Modeling and Generation of Expressive Pop Piano Compositions | Github Repo

" + +examples = [ + ['input.midi'] +] +gr.Interface( + inference, + gr.inputs.File(label="Input Midi"), + gr.outputs.File(label="Output Midi"), + title=title, + description=description, + article=article, + examples=examples + ).launch() diff --git a/input.midi b/input.midi new file mode 100644 index 0000000..096cab1 Binary files /dev/null and b/input.midi differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a5a3b63 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +miditoolkit +tensorflow-gpu==1.14.0 +gradio +torchtext