asigalov61 commited on
Commit
7b3dcbc
·
verified ·
1 Parent(s): 595138c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -55,6 +55,8 @@ SOUDFONT_PATH = 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2'
55
 
56
  NUM_OUT_BATCHES = 8
57
 
 
 
58
  #==================================================================================
59
 
60
  print('=' * 70)
@@ -339,21 +341,26 @@ def generate_callback(input_midi,
339
 
340
  tokens = batched_gen_tokens[i]
341
 
 
 
 
342
  # Save MIDI to a temporary file
343
- midi_score = save_midi(tokens, i)
344
 
345
  # MIDI plot
346
- midi_plot = TMIDIX.plot_ms_SONG(midi_score, plot_title='Batch # ' + str(i), return_plt=True)
347
 
348
- # File name
349
- fname = 'Giant-Music-Transformer-Music-Composition_'+str(i)
350
-
351
- # Save audio to a temporary file
352
- midi_audio = midi_to_colab_audio(fname + '.mid',
353
- soundfont_path=SOUDFONT_PATH,
354
- sample_rate=16000,
355
- output_for_gradio=True
356
- )
 
 
 
357
 
358
  outputs.append(((16000, midi_audio), midi_plot, tokens))
359
 
 
55
 
56
  NUM_OUT_BATCHES = 8
57
 
58
+ PREVIEW_LENGTH = 120
59
+
60
  #==================================================================================
61
 
62
  print('=' * 70)
 
341
 
342
  tokens = batched_gen_tokens[i]
343
 
344
+ # Preview
345
+ tokens_preview = final_composition[-PREVIEW_LENGTH:]
346
+
347
  # Save MIDI to a temporary file
348
+ midi_score = save_midi(tokens_preview + tokens, i)
349
 
350
  # MIDI plot
 
351
 
352
+ if len(final_composition) > PREVIEW_LENGTH:
353
+ midi_plot = TMIDIX.plot_ms_SONG(midi_score,
354
+ plot_title='Batch # ' + str(i),
355
+ preview_length_in_notes=int(PREVIEW_LENGTH / 3),
356
+ return_plt=True
357
+ )
358
+
359
+ else:
360
+ midi_plot = TMIDIX.plot_ms_SONG(midi_score,
361
+ plot_title='Batch # ' + str(i),
362
+ return_plt=True
363
+ )
364
 
365
  outputs.append(((16000, midi_audio), midi_plot, tokens))
366