AlekseyKorshuk commited on
Commit
4d6b66b
1 Parent(s): 883e621

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import pretty_midi
4
+ from accompaniment_generator.generator.base import Generator
5
+
6
+
7
+ def inference(audio, num_epoch):
8
+ generator = Generator()
9
+ input_midi_data = pretty_midi.PrettyMIDI(audio.name)
10
+ output_midi_data = generator(audio.name, num_epoch=int(num_epoch))
11
+ data = input_midi_data.synthesize()
12
+ input_scaled = np.int16(data / np.max(np.abs(data)) * 32767)
13
+ data = output_midi_data.synthesize()
14
+ output_scaled = np.int16(data / np.max(np.abs(data)) * 32767)
15
+ return [(44100, input_scaled), (44100, output_scaled)]
16
+
17
+
18
+ title = "Accompaniment Generator"
19
+ 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."
20
+
21
+ article = "<p style='text-align: center'>" \
22
+ "<a href='https://github.com/AlekseyKorshuk/accompaniment-generator' target='_blank'>Github Repo</a>" \
23
+ "</p>"
24
+
25
+ examples = [['barbiegirl_mono.mid', 10]]
26
+
27
+ gr.Interface(
28
+ inference,
29
+ [gr.inputs.File(type="file", label="Input"), gr.inputs.Number(label="Number of epoch", default=10)],
30
+ [gr.outputs.Audio(type="auto", label="Before"), gr.outputs.Audio(type="auto", label="After")],
31
+ title=title,
32
+ description=description,
33
+ article=article,
34
+ examples=examples,
35
+ ).launch(debug=True)