Spaces:
Running
on
Zero
Running
on
Zero
mrfakename
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,22 @@ from musiclib import musicgen
|
|
3 |
from io import BytesIO
|
4 |
import midi_util
|
5 |
from midi_util import VocabConfig
|
6 |
-
from midi2audio import FluidSynth
|
7 |
-
fs = FluidSynth()
|
8 |
def gen(piano_only, length):
|
9 |
midi = ''
|
10 |
for item in musicgen(piano_only=piano_only, length=length):
|
11 |
midi = item
|
12 |
-
yield item, None
|
13 |
bio = BytesIO()
|
14 |
cfg = VocabConfig.from_json('./vocab_config.json')
|
15 |
text = midi.strip()
|
16 |
mid = midi_util.convert_str_to_midi(cfg, text)
|
17 |
mid.save(file=bio)
|
18 |
-
|
19 |
-
fs.midi_to_audio(bio.getvalue(), audio)
|
20 |
-
return midi, bio.getvalue(), audio.getvalue()
|
21 |
with gr.Blocks() as demo:
|
22 |
piano_only = gr.Checkbox(label="Piano Only")
|
23 |
length = gr.Slider(label="Length (in tokens)", minimum=4, maximum=4096, step=1, value=4096)
|
24 |
synth = gr.Button("Synthesize")
|
25 |
txtout = gr.Textbox(interactive=False, label="MIDI Length")
|
26 |
fileout = gr.File(interactive=False, label="MIDI File")
|
27 |
-
|
28 |
-
synth.click(gen, inputs=[piano_only, length], outputs=[txtout, fileout, audioout])
|
29 |
demo.queue().launch()
|
|
|
3 |
from io import BytesIO
|
4 |
import midi_util
|
5 |
from midi_util import VocabConfig
|
|
|
|
|
6 |
def gen(piano_only, length):
|
7 |
midi = ''
|
8 |
for item in musicgen(piano_only=piano_only, length=length):
|
9 |
midi = item
|
10 |
+
yield item, None
|
11 |
bio = BytesIO()
|
12 |
cfg = VocabConfig.from_json('./vocab_config.json')
|
13 |
text = midi.strip()
|
14 |
mid = midi_util.convert_str_to_midi(cfg, text)
|
15 |
mid.save(file=bio)
|
16 |
+
return midi, bio.getvalue()
|
|
|
|
|
17 |
with gr.Blocks() as demo:
|
18 |
piano_only = gr.Checkbox(label="Piano Only")
|
19 |
length = gr.Slider(label="Length (in tokens)", minimum=4, maximum=4096, step=1, value=4096)
|
20 |
synth = gr.Button("Synthesize")
|
21 |
txtout = gr.Textbox(interactive=False, label="MIDI Length")
|
22 |
fileout = gr.File(interactive=False, label="MIDI File")
|
23 |
+
synth.click(gen, inputs=[piano_only, length], outputs=[txtout, fileout])
|
|
|
24 |
demo.queue().launch()
|