asigalov61 commited on
Commit
c04453c
1 Parent(s): 41327e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -13,15 +13,17 @@ from midi_synthesizer import synthesis
13
 
14
  in_space = os.getenv("SYSTEM") == "spaces"
15
 
16
- def run(search_prompt, mid=None):
17
- mid_seq = []
18
 
19
  if mid == None:
20
 
21
- for m in meta_data:
 
22
  mid_seq.extend(m[1][17:])
23
  mid_seq_ticks = m[1][16][1]
24
- break
 
25
 
26
  elif mid is not None:
27
  mid_seq = MIDI.midi2score(mid)
@@ -29,7 +31,7 @@ def run(search_prompt, mid=None):
29
  with open(f"output.mid", 'wb') as f:
30
  f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
31
  audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
32
- yield mid_seq, "output.mid", (44100, audio)
33
 
34
 
35
  def cancel_run(mid_seq):
@@ -87,9 +89,11 @@ if __name__ == "__main__":
87
 
88
  search_btn = gr.Button("search", variant="primary")
89
  stop_btn = gr.Button("stop and output")
90
- output_midi_seq = gr.Textbox()
91
  output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
92
  output_midi = gr.File(label="output midi", file_types=[".mid"])
 
 
93
  run_event = search_btn.click(run, [search_prompt],
94
  [output_midi_seq, output_midi, output_audio])
95
  stop_btn.click(cancel_run, output_midi_seq, [output_midi, output_audio], cancels=run_event, queue=False)
 
13
 
14
  in_space = os.getenv("SYSTEM") == "spaces"
15
 
16
+ def run(search_prompt, mid=None, progress=gr.Progress()):
17
+
18
 
19
  if mid == None:
20
 
21
+ for m in progress.tqdm(meta_data):
22
+ mid_seq = []
23
  mid_seq.extend(m[1][17:])
24
  mid_seq_ticks = m[1][16][1]
25
+ mdata = m[1][:17]
26
+ # break
27
 
28
  elif mid is not None:
29
  mid_seq = MIDI.midi2score(mid)
 
31
  with open(f"output.mid", 'wb') as f:
32
  f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
33
  audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
34
+ yield mdata, "output.mid", (44100, audio)
35
 
36
 
37
  def cancel_run(mid_seq):
 
89
 
90
  search_btn = gr.Button("search", variant="primary")
91
  stop_btn = gr.Button("stop and output")
92
+
93
  output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
94
  output_midi = gr.File(label="output midi", file_types=[".mid"])
95
+ output_midi_seq = gr.Textbox()
96
+
97
  run_event = search_btn.click(run, [search_prompt],
98
  [output_midi_seq, output_midi, output_audio])
99
  stop_btn.click(cancel_run, output_midi_seq, [output_midi, output_audio], cancels=run_event, queue=False)