awacke1 commited on
Commit
8c6d739
1 Parent(s): 962a7c0

Update app_onnx.py

Browse files
Files changed (1) hide show
  1. app_onnx.py +46 -11
app_onnx.py CHANGED
@@ -494,17 +494,7 @@ if __name__ == "__main__":
494
  load_javascript()
495
  app = gr.Blocks(theme=gr.themes.Soft())
496
  with app:
497
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Midi Composer</h1>")
498
- gr.Markdown("![Visitors](https://api.visitorbadge.io/api/visitors?path=skytnt.midi-composer&style=flat)\n\n"
499
- "Midi event transformer for symbolic music generation\n\n"
500
- "Demo for [SkyTNT/midi-model](https://github.com/SkyTNT/midi-model)\n\n"
501
- "[Open In Colab]"
502
- "(https://colab.research.google.com/github/SkyTNT/midi-model/blob/main/demo.ipynb)"
503
- " or [download windows app](https://github.com/SkyTNT/midi-model/releases)"
504
- " for unlimited generation\n\n"
505
- "**Update v1.3**: MIDITokenizerV2 and new MidiVisualizer\n\n"
506
- "The current **best** model: generic pretrain model (tv2o-medium) by skytnt"
507
- )
508
  js_msg = gr.Textbox(elem_id="msg_receiver", visible=False)
509
  js_msg.change(None, [js_msg], [], js="""
510
  (msg_json) =>{
@@ -595,12 +585,23 @@ if __name__ == "__main__":
595
  audio_outputs = []
596
  with gr.Tabs(elem_id="output_tabs"):
597
  for i in range(OUTPUT_BATCH_SIZE):
 
 
 
 
 
 
 
598
  with gr.TabItem(f"output {i + 1}") as tab1:
599
  output_midi_visualizer = gr.HTML(elem_id=f"midi_visualizer_container_{i}")
600
  output_audio = gr.Audio(label="output audio", format="mp3", elem_id=f"midi_audio_{i}")
601
  output_midi = gr.File(label="output midi", file_types=[".mid"])
 
602
  midi_outputs.append(output_midi)
603
  audio_outputs.append(output_audio)
 
 
 
604
  run_event = run_btn.click(run, [input_model, tab_select, output_midi_seq, output_continuation_state,
605
  input_continuation_select, input_instruments, input_drum_kit, input_bpm,
606
  input_time_sig, input_key_sig, input_midi, input_midi_events,
@@ -620,6 +621,40 @@ if __name__ == "__main__":
620
  queue=False)
621
  # stop_btn.click(None, [], [], cancels=run_event,
622
  # queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
  undo_btn.click(undo_continuation, [input_model, output_midi_seq, output_continuation_state],
624
  [output_midi_seq, output_continuation_state, js_msg], queue=False)
625
  app.queue().launch(server_port=opt.port, share=opt.share, inbrowser=True, ssr_mode=False)
 
494
  load_javascript()
495
  app = gr.Blocks(theme=gr.themes.Soft())
496
  with app:
497
+
 
 
 
 
 
 
 
 
 
 
498
  js_msg = gr.Textbox(elem_id="msg_receiver", visible=False)
499
  js_msg.change(None, [js_msg], [], js="""
500
  (msg_json) =>{
 
585
  audio_outputs = []
586
  with gr.Tabs(elem_id="output_tabs"):
587
  for i in range(OUTPUT_BATCH_SIZE):
588
+
589
+ with gr.Row():
590
+ arpeggio_intro = gr.Button("🎵 Intro Arpeggio", variant="primary")
591
+ arpeggio_verse = gr.Button("🎸 Verse Arpeggio", variant="primary")
592
+ arpeggio_chorus = gr.Button("🎹 Chorus Arpeggio", variant="primary")
593
+ arpeggio_outro = gr.Button("🎷 Outro Arpeggio", variant="primary")
594
+
595
  with gr.TabItem(f"output {i + 1}") as tab1:
596
  output_midi_visualizer = gr.HTML(elem_id=f"midi_visualizer_container_{i}")
597
  output_audio = gr.Audio(label="output audio", format="mp3", elem_id=f"midi_audio_{i}")
598
  output_midi = gr.File(label="output midi", file_types=[".mid"])
599
+
600
  midi_outputs.append(output_midi)
601
  audio_outputs.append(output_audio)
602
+
603
+
604
+
605
  run_event = run_btn.click(run, [input_model, tab_select, output_midi_seq, output_continuation_state,
606
  input_continuation_select, input_instruments, input_drum_kit, input_bpm,
607
  input_time_sig, input_key_sig, input_midi, input_midi_events,
 
621
  queue=False)
622
  # stop_btn.click(None, [], [], cancels=run_event,
623
  # queue=False)
624
+
625
+
626
+
627
+ def add_intro_arpeggio(model_name, mid_seq):
628
+ tokenizer = models[model_name].tokenizer
629
+ sequence = ['C', 'D', 'Am', 'G']
630
+ pattern = [0, 1, 2, 1] # Root, Third, Fifth, Third
631
+ return add_arpeggio_sequence(tokenizer, mid_seq, sequence, pattern)
632
+
633
+ def add_verse_arpeggio(model_name, mid_seq):
634
+ tokenizer = models[model_name].tokenizer
635
+ sequence = ['D', 'C', 'Am', 'G']
636
+ pattern = [0, 2, 1, 2] # Root, Fifth, Third, Fifth
637
+ return add_arpeggio_sequence(tokenizer, mid_seq, sequence, pattern)
638
+
639
+ def add_chorus_arpeggio(model_name, mid_seq):
640
+ tokenizer = models[model_name].tokenizer
641
+ sequence = ['G', 'D', 'Am', 'C']
642
+ pattern = [0, 1, 2, 1, 0, 2] # Root, Third, Fifth, Third, Root, Fifth
643
+ return add_arpeggio_sequence(tokenizer, mid_seq, sequence, pattern)
644
+
645
+ def add_outro_arpeggio(model_name, mid_seq):
646
+ tokenizer = models[model_name].tokenizer
647
+ sequence = ['Am', 'G', 'D', 'C']
648
+ pattern = [2, 1, 0, 1] # Fifth, Third, Root, Third
649
+ return add_arpeggio_sequence(tokenizer, mid_seq, sequence, pattern)
650
+
651
+ arpeggio_intro.click(add_intro_arpeggio, [input_model, output_midi_seq], output_midi_seq)
652
+ arpeggio_verse.click(add_verse_arpeggio, [input_model, output_midi_seq], output_midi_seq)
653
+ arpeggio_chorus.click(add_chorus_arpeggio, [input_model, output_midi_seq], output_midi_seq)
654
+ arpeggio_outro.click(add_outro_arpeggio, [input_model, output_midi_seq], output_midi_seq)
655
+
656
+
657
+
658
  undo_btn.click(undo_continuation, [input_model, output_midi_seq, output_continuation_state],
659
  [output_midi_seq, output_continuation_state, js_msg], queue=False)
660
  app.queue().launch(server_port=opt.port, share=opt.share, inbrowser=True, ssr_mode=False)