Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from model import PopMusicTransformer
|
2 |
+
import os
|
3 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
4 |
+
import tensorflow as tf
|
5 |
+
tf.compat.v1.disable_eager_execution()
|
6 |
+
import gradio as gr
|
7 |
+
import requests
|
8 |
+
import torchtext
|
9 |
+
import zipfile
|
10 |
+
|
11 |
+
torchtext.utils.download_from_url("https://drive.google.com/uc?id=1gxuTSkF51NP04JZgTE46Pg4KQsbHQKGo", root=".")
|
12 |
+
torchtext.utils.download_from_url("https://drive.google.com/uc?id=1nAKjaeahlzpVAX0F9wjQEG_hL4UosSbo", root=".")
|
13 |
+
|
14 |
+
with zipfile.ZipFile("REMI-tempo-checkpoint.zip","r") as zip_ref:
|
15 |
+
zip_ref.extractall(".")
|
16 |
+
with zipfile.ZipFile("REMI-tempo-chord-checkpoint.zip","r") as zip_ref:
|
17 |
+
zip_ref.extractall(".")
|
18 |
+
|
19 |
+
url = 'https://github.com/AK391/remi/blob/master/input.midi?raw=true'
|
20 |
+
r = requests.get(url, allow_redirects=True)
|
21 |
+
open("input.midi", 'wb').write(r.content)
|
22 |
+
|
23 |
+
|
24 |
+
# declare model
|
25 |
+
model = PopMusicTransformer(
|
26 |
+
checkpoint='REMI-tempo-checkpoint',
|
27 |
+
is_training=False)
|
28 |
+
|
29 |
+
def inference(midi):
|
30 |
+
# generate continuation
|
31 |
+
model.generate(
|
32 |
+
n_target_bar=4,
|
33 |
+
temperature=1.2,
|
34 |
+
topk=5,
|
35 |
+
output_path='./result/continuation.midi',
|
36 |
+
prompt=midi.name)
|
37 |
+
return './result/continuation.midi'
|
38 |
+
|
39 |
+
|
40 |
+
title = "Pop Music Transformer"
|
41 |
+
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."
|
42 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2002.00212'>Pop Music Transformer: Beat-based Modeling and Generation of Expressive Pop Piano Compositions</a> | <a href='https://github.com/YatingMusic/remi'>Github Repo</a></p>"
|
43 |
+
|
44 |
+
examples = [
|
45 |
+
['input.midi']
|
46 |
+
]
|
47 |
+
gr.Interface(
|
48 |
+
inference,
|
49 |
+
gr.inputs.File(label="Input Midi"),
|
50 |
+
gr.outputs.File(label="Output Midi"),
|
51 |
+
title=title,
|
52 |
+
description=description,
|
53 |
+
article=article,
|
54 |
+
examples=examples
|
55 |
+
).launch()
|