mrfakename commited on
Commit
8dacb10
1 Parent(s): 7095c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -3,6 +3,7 @@ from musiclib import musicgen
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):
@@ -12,8 +13,9 @@ def gen(piano_only, length):
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
- yield 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)
 
3
  from io import BytesIO
4
  import midi_util
5
  from midi_util import VocabConfig
6
+ import tempfile
7
  def gen(piano_only, length):
8
  midi = ''
9
  for item in musicgen(piano_only=piano_only, length=length):
 
13
  cfg = VocabConfig.from_json('./vocab_config.json')
14
  text = midi.strip()
15
  mid = midi_util.convert_str_to_midi(cfg, text)
16
+ with tempfile.NamedTemporaryFile(suffix='.midi', delete=False):
17
+ mid.save(file=bio)
18
+ yield midi, bio.getvalue()
19
  with gr.Blocks() as demo:
20
  piano_only = gr.Checkbox(label="Piano Only")
21
  length = gr.Slider(label="Length (in tokens)", minimum=4, maximum=4096, step=1, value=4096)