Ahsen Khaliq commited on
Commit
24f7fef
1 Parent(s): edc651d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from pathlib import Path
4
+
5
+ os.system("midi_ddsp_download_model_weights")
6
+
7
+
8
+ os.system("git clone --branch=main https://github.com/google-research/t5x")
9
+ os.system("mv t5x t5x_tmp; mv t5x_tmp/* .; rm -r t5x_tmp")
10
+ os.system("sed -i 's:jax\[tpu\]:jax:' setup.py")
11
+ os.system("python3 -m pip install -e .")
12
+
13
+ # install mt3
14
+ os.system("git clone --branch=main https://github.com/magenta/mt3")
15
+ os.system("mv mt3 mt3_tmp; mv mt3_tmp/* .; rm -r mt3_tmp")
16
+ os.system("python3 -m pip install -e .")
17
+
18
+ # copy checkpoints
19
+ os.system("gsutil -q -m cp -r gs://mt3/checkpoints .")
20
+
21
+ # copy soundfont (originally from https://sites.google.com/site/soundfonts4u)
22
+ os.system("gsutil -q -m cp gs://magentadata/soundfonts/SGM-v2.01-Sal-Guit-Bass-V1.3.sf2 .")
23
+
24
+
25
+ def inference(audio):
26
+ os.system("midi_ddsp_synthesize --midi_path "+audio.name)
27
+ return Path(audio.name).stem+"/0_violin.wav"
28
+
29
+ title = "Midi-DDSP"
30
+ description = "Gradio demo for MIDI-DDSP: Detailed Control of Musical Performance via Hierarchical Modeling. To use it, simply upload your midi file, or click one of the examples to load them. Read more at the links below."
31
+
32
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.09312' target='_blank'>MIDI-DDSP: Detailed Control of Musical Performance via Hierarchical Modeling</a> | <a href='https://github.com/magenta/midi-ddsp' target='_blank'>Github Repo</a></p>"
33
+
34
+ examples=[['input.mid']]
35
+
36
+ gr.Interface(
37
+ inference,
38
+ gr.inputs.File(type="file", label="Input"),
39
+ [gr.outputs.Audio(type="file", label="Output")],
40
+ title=title,
41
+ description=description,
42
+ article=article,
43
+ examples=examples,
44
+ enable_queue=True
45
+ ).launch(debug=True)