mrfakename commited on
Commit
3efa2af
1 Parent(s): 681218a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -1,12 +1,24 @@
1
  import gradio as gr
2
  from musiclib import musicgen
 
 
 
3
 
4
  def gen(piano_only):
 
5
  for item in musicgen(piano_only=piano_only):
6
- yield item
 
 
 
 
 
 
 
7
  with gr.Blocks() as demo:
8
  piano_only = gr.Checkbox(label="Piano Only")
9
  synth = gr.Button("Synthesize")
10
- fileout = gr.Textbox(interactive=False)
11
- synth.click(gen, inputs=[piano_only], outputs=[fileout])
 
12
  demo.queue().launch()
 
1
  import gradio as gr
2
  from musiclib import musicgen
3
+ from io import BytesIO
4
+ import midi_util
5
+ from midi_util import VocabConfig
6
 
7
  def gen(piano_only):
8
+ midi = ''
9
  for item in musicgen(piano_only=piano_only):
10
+ midi = item
11
+ yield item, None
12
+ bio = BytesIO()
13
+ cfg = VocabConfig.from_json('./vocab_config.json')
14
+ text = midi.strip()
15
+ mid = midi_util.convert_str_to_midi(cfg, text)
16
+ mid.save(bio)
17
+ return midi, bio.getvalue()
18
  with gr.Blocks() as demo:
19
  piano_only = gr.Checkbox(label="Piano Only")
20
  synth = gr.Button("Synthesize")
21
+ txtout = gr.Textbox(interactive=False)
22
+ fileout = gr.File(interactive=False)
23
+ synth.click(gen, inputs=[piano_only], outputs=[txtout, fileout])
24
  demo.queue().launch()