asigalov61 commited on
Commit
06b8dc2
·
verified ·
1 Parent(s): fc1422a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -23,7 +23,7 @@ in_space = os.getenv("SYSTEM") == "spaces"
23
  # =================================================================================================
24
 
25
  @spaces.GPU
26
- def GenerateAccompaniment(input_midi, input_num_tokens, input_acc_type):
27
  print('=' * 70)
28
  print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
29
  start_time = reqtime.time()
@@ -31,7 +31,7 @@ def GenerateAccompaniment(input_midi, input_num_tokens, input_acc_type):
31
  print('Loading model...')
32
 
33
  SEQ_LEN = 8192 # Models seq len
34
- PAD_IDX = 767 # Models pad index
35
  DEVICE = 'cuda' # 'cuda'
36
 
37
  # instantiate the model
@@ -50,7 +50,7 @@ def GenerateAccompaniment(input_midi, input_num_tokens, input_acc_type):
50
  print('Loading model checkpoint...')
51
 
52
  model.load_state_dict(
53
- torch.load('Ultimate_Accompaniment_Transformer_Small_Improved_Trained_Model_13649_steps_0.3229_loss_0.898_acc.pth',
54
  map_location=DEVICE))
55
  print('=' * 70)
56
 
@@ -369,21 +369,21 @@ if __name__ == "__main__":
369
 
370
  app = gr.Blocks()
371
  with app:
372
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Ultimate Accompaniment Transformer</h1>")
373
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Generate unique accompaniment for any melody</h1>")
374
  gr.Markdown(
375
- "![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Ultimate-Accompaniment-Transformer&style=flat)\n\n"
376
- "Accompaniment generation for any monophonic melody\n\n"
377
- "Check out [Ultimate Drums Transformer](https://github.com/asigalov61/Ultimate-Accompaniment-Transformer) on GitHub!\n\n"
378
  "[Open In Colab]"
379
- "(https://colab.research.google.com/github/asigalov61/Ultimate-Accompaniment-Transformer/blob/main/Ultimate_Accompaniment_Transformer.ipynb)"
380
  " for faster execution and endless generation"
381
  )
382
  gr.Markdown("## Upload your MIDI or select a sample example MIDI")
383
 
384
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
385
- input_num_tokens = gr.Slider(4, 128, value=32, step=1, label="Number of composition chords to generate accompaniment for")
386
- input_acc_type = gr.Checkbox(label='Force accompaniment generation for each melody note')
387
 
388
  run_btn = gr.Button("generate", variant="primary")
389
 
@@ -396,18 +396,24 @@ if __name__ == "__main__":
396
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
397
 
398
 
399
- run_event = run_btn.click(GenerateAccompaniment, [input_midi, input_num_tokens, input_acc_type],
400
  [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
401
 
402
  gr.Examples(
403
- [["Ultimate-Accompaniment-Transformer-Melody-Seed-1.mid", 128, True],
404
- ["Ultimate-Accompaniment-Transformer-Melody-Seed-2.mid", 128, False],
405
- ["Ultimate-Accompaniment-Transformer-Melody-Seed-3.mid", 128, True],
406
- ["Ultimate-Accompaniment-Transformer-Melody-Seed-4.mid", 128, False],
407
- ["Ultimate-Accompaniment-Transformer-Melody-Seed-5.mid", 128, True],
408
- ["Ultimate-Accompaniment-Transformer-Melody-Seed-6.mid", 128, False],
409
- ["Ultimate-Accompaniment-Transformer-Melody-Seed-7.mid", 128, True]],
410
- [input_midi, input_num_tokens, input_acc_type],
 
 
 
 
 
 
411
  [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
412
  GenerateAccompaniment,
413
  cache_examples=True,
 
23
  # =================================================================================================
24
 
25
  @spaces.GPU
26
+ def GenerateAccompaniment(input_midi, input_num_tokens, input_conditioning_type):
27
  print('=' * 70)
28
  print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
29
  start_time = reqtime.time()
 
31
  print('Loading model...')
32
 
33
  SEQ_LEN = 8192 # Models seq len
34
+ PAD_IDX = 707 # Models pad index
35
  DEVICE = 'cuda' # 'cuda'
36
 
37
  # instantiate the model
 
50
  print('Loading model checkpoint...')
51
 
52
  model.load_state_dict(
53
+ torch.load('Chords_Progressions_Transformer_Small_2048_Trained_Model_12947_steps_0.9316_loss_0.7386_acc.pth',
54
  map_location=DEVICE))
55
  print('=' * 70)
56
 
 
369
 
370
  app = gr.Blocks()
371
  with app:
372
+ gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Chords Progressions Transformer</h1>")
373
+ gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Chords-conditioned music transformer</h1>")
374
  gr.Markdown(
375
+ "![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Chords-Progressions-Transformer&style=flat)\n\n"
376
+ "Generate music based on chords progressions\n\n"
377
+ "Check out [Chords Progressions Transformer](https://github.com/asigalov61/Chords-Progressions-Transformer) on GitHub!\n\n"
378
  "[Open In Colab]"
379
+ "(https://colab.research.google.com/github/asigalov61/Chords-Progressions-Transformer/blob/main/Chords_Progressions_Transformer.ipynb)"
380
  " for faster execution and endless generation"
381
  )
382
  gr.Markdown("## Upload your MIDI or select a sample example MIDI")
383
 
384
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
385
+ input_num_tokens = gr.Slider(4, 128, value=32, step=1, label="Number of composition chords to generate progression for")
386
+ input_conditioning_type = gr.Radio(["Chords", "Chords-Times", "Chords-Times-Durations"], label="Conditioning type")
387
 
388
  run_btn = gr.Button("generate", variant="primary")
389
 
 
396
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
397
 
398
 
399
+ run_event = run_btn.click(GenerateAccompaniment, [input_midi, input_num_tokens, input_conditioning_type],
400
  [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
401
 
402
  gr.Examples(
403
+ [["Chords-Progressions-Transformer-Piano-Seed-1.mid", 128, "Chords"],
404
+ ["Chords-Progressions-Transformer-Piano-Seed-2.mid", 128, "Chords"],
405
+ ["Chords-Progressions-Transformer-Piano-Seed-3.mid", 128, "Chords"],
406
+ ["Chords-Progressions-Transformer-Piano-Seed-4.mid", 128, "Chords"],
407
+ ["Chords-Progressions-Transformer-Piano-Seed-5.mid", 128, "Chords"],
408
+ ["Chords-Progressions-Transformer-Piano-Seed-6.mid", 128, "Chords"],
409
+ ["Chords-Progressions-Transformer-MI-Seed-1.mid", 128, "Chords"]
410
+ ["Chords-Progressions-Transformer-MI-Seed-2.mid", 128, "Chords"]
411
+ ["Chords-Progressions-Transformer-MI-Seed-3.mid", 128, "Chords"]
412
+ ["Chords-Progressions-Transformer-MI-Seed-4.mid", 128, "Chords"]
413
+ ["Chords-Progressions-Transformer-MI-Seed-5.mid", 128, "Chords"]
414
+ ["Chords-Progressions-Transformer-MI-Seed-6.mid", 128, "Chords"]
415
+ ],
416
+ [input_midi, input_num_tokens, input_conditioning_type],
417
  [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
418
  GenerateAccompaniment,
419
  cache_examples=True,