asigalov61 commited on
Commit
4b3e8cb
1 Parent(s): 7dd6e93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -24,11 +24,28 @@ def run(search_prompt, mid=None, progress=gr.Progress()):
24
 
25
  elif mid is not None:
26
  mid_seq = MIDI.midi2score(mid)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  with open(f"output.mid", 'wb') as f:
29
  f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
30
  audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
31
- yield mdata, "output.mid", (44100, audio)
32
 
33
  if __name__ == "__main__":
34
  parser = argparse.ArgumentParser()
@@ -78,9 +95,10 @@ if __name__ == "__main__":
78
 
79
  output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
80
  output_midi = gr.File(label="output midi", file_types=[".mid"])
81
- output_midi_seq = gr.Textbox()
 
82
 
83
  run_event = search_btn.click(run, [search_prompt],
84
- [output_midi_seq, output_midi, output_audio])
85
 
86
  app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
 
24
 
25
  elif mid is not None:
26
  mid_seq = MIDI.midi2score(mid)
27
+
28
+
29
+ x = []
30
+ y = []
31
+ c = []
32
+
33
+ colors = ['red', 'yellow', 'green', 'cyan',
34
+ 'blue', 'pink', 'orange', 'purple',
35
+ 'gray', 'white', 'gold', 'silver',
36
+ 'lightgreen', 'indigo', 'maroon', 'turquoise']
37
+
38
+ for s in [m for m in mid_seq if m[0] == 'note']:
39
+ x.append(s[1] / mid_seq_ticks)
40
+ y.append(s[4])
41
+ c.append(colors[s[3]])
42
+
43
+ plot = [x, y, c]
44
 
45
  with open(f"output.mid", 'wb') as f:
46
  f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
47
  audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
48
+ yield mdata, "output.mid", (44100, audio), plot
49
 
50
  if __name__ == "__main__":
51
  parser = argparse.ArgumentParser()
 
95
 
96
  output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
97
  output_midi = gr.File(label="output midi", file_types=[".mid"])
98
+ output_midi_seq = gr.Textbox(label="output midi metadata")
99
+ output_plot = gr.ScatterPlot(label="output midi plot")
100
 
101
  run_event = search_btn.click(run, [search_prompt],
102
+ [output_midi_seq, output_midi, output_audio, output_plot])
103
 
104
  app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)