asigalov61 commited on
Commit
5244019
·
verified ·
1 Parent(s): 5f04547

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -114,7 +114,7 @@ model.eval()
114
  # -----------------------------
115
  def render_midi_output(final_composition):
116
  """Generate MIDI score, plot, and audio from final composition."""
117
- midi_score = save_midi(final_composition)
118
  time_val = midi_score[-1][1] / 1000 # seconds marker from last note
119
  midi_plot = TMIDIX.plot_ms_SONG(
120
  midi_score,
@@ -122,7 +122,6 @@ def render_midi_output(final_composition):
122
  block_lines_times_list=[],
123
  return_plt=True
124
  )
125
- fname = save_midi(final_composition) # The file name is embedded in the saved MIDI.
126
  midi_audio = midi_to_colab_audio(
127
  fname + '.mid',
128
  soundfont_path=SOUDFONT_PATH,
@@ -260,12 +259,12 @@ def generate_music_and_state(input_midi, num_prime_tokens, num_gen_tokens, num_m
260
  output_batches = []
261
  for i, tokens in enumerate(batched_gen_tokens):
262
  preview_tokens = final_composition[-PREVIEW_LENGTH:]
263
- midi_fname = save_midi(preview_tokens + tokens, batch_number=i)
264
  plot_kwargs = {'plot_title': f'Batch # {i}', 'return_plt': True}
265
  if len(final_composition) > PREVIEW_LENGTH:
266
  plot_kwargs['preview_length_in_notes'] = int(PREVIEW_LENGTH / 3)
267
  TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(
268
- preview_tokens + tokens,
269
  output_signature='Godzilla Piano Transformer',
270
  output_file_name=midi_fname,
271
  track_name='Project Los Angeles',
@@ -298,7 +297,7 @@ def add_batch(batch_number, final_composition, generated_batches, block_lines):
298
  """Add tokens from the specified batch to the final composition and update outputs."""
299
  if generated_batches:
300
  final_composition.extend(generated_batches[batch_number])
301
- midi_fname = save_midi(final_composition)
302
  block_lines.append(final_composition[-1] if final_composition else 0)
303
  midi_score = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(
304
  final_composition,
@@ -330,8 +329,8 @@ def remove_batch(batch_number, num_tokens, final_composition, generated_batches,
330
  final_composition = final_composition[:-num_tokens]
331
  if block_lines:
332
  block_lines.pop()
333
- midi_fname = save_midi(final_composition)
334
- midi_score = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(
335
  final_composition,
336
  output_signature='Godzilla Piano Transformer',
337
  output_file_name=midi_fname,
 
114
  # -----------------------------
115
  def render_midi_output(final_composition):
116
  """Generate MIDI score, plot, and audio from final composition."""
117
+ fname, midi_score = save_midi(final_composition)
118
  time_val = midi_score[-1][1] / 1000 # seconds marker from last note
119
  midi_plot = TMIDIX.plot_ms_SONG(
120
  midi_score,
 
122
  block_lines_times_list=[],
123
  return_plt=True
124
  )
 
125
  midi_audio = midi_to_colab_audio(
126
  fname + '.mid',
127
  soundfont_path=SOUDFONT_PATH,
 
259
  output_batches = []
260
  for i, tokens in enumerate(batched_gen_tokens):
261
  preview_tokens = final_composition[-PREVIEW_LENGTH:]
262
+ midi_fname, midi_score = save_midi(preview_tokens + tokens, batch_number=i)
263
  plot_kwargs = {'plot_title': f'Batch # {i}', 'return_plt': True}
264
  if len(final_composition) > PREVIEW_LENGTH:
265
  plot_kwargs['preview_length_in_notes'] = int(PREVIEW_LENGTH / 3)
266
  TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(
267
+ midi_score,
268
  output_signature='Godzilla Piano Transformer',
269
  output_file_name=midi_fname,
270
  track_name='Project Los Angeles',
 
297
  """Add tokens from the specified batch to the final composition and update outputs."""
298
  if generated_batches:
299
  final_composition.extend(generated_batches[batch_number])
300
+ midi_fname, midi_score = save_midi(final_composition)
301
  block_lines.append(final_composition[-1] if final_composition else 0)
302
  midi_score = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(
303
  final_composition,
 
329
  final_composition = final_composition[:-num_tokens]
330
  if block_lines:
331
  block_lines.pop()
332
+ midi_fname, midi_score = save_midi(final_composition)
333
+ TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(
334
  final_composition,
335
  output_signature='Godzilla Piano Transformer',
336
  output_file_name=midi_fname,