projectlosangeles commited on
Commit
3c2c36c
·
verified ·
1 Parent(s): 31b453f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -24
app.py CHANGED
@@ -115,6 +115,8 @@ def load_midi(input_midi):
115
  if escore_notes:
116
 
117
  escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes[0], sort_drums_last=True)
 
 
118
 
119
  dscore = TMIDIX.delta_score_notes(escore_notes)
120
 
@@ -213,43 +215,53 @@ def Generate_Drums(input_midi,
213
 
214
  print('Loading MIDI...')
215
 
216
- score = load_midi(input_midi.name)
217
 
218
- if score is not None:
219
 
220
  print('Sample score tokens', score[:10])
221
 
222
  #==================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
- full_chunk = score[:1536]
225
- left_chunk = full_chunk[:512]
226
- right_chunk = full_chunk[-512:]
227
-
228
- bridge_chunk = full_chunk[448:1088]
229
-
230
- seq = [18815] + left_chunk + [18816] + right_chunk + [18817]
231
-
232
  #==================================================================
233
 
234
  print('=' * 70)
235
  print('Generating...')
 
 
236
 
237
- x = torch.LongTensor(seq).to(device_type)
238
-
239
- with ctx:
240
- out = model.generate(x,
241
- 641,
242
- temperature=model_temperature,
243
- filter_logits_fn=top_p,
244
- filter_kwargs={'thres': model_sampling_top_p},
245
- return_prime=False,
246
- eos_token=18818,
247
- verbose=False)
248
 
249
- y = out.tolist()
 
 
250
 
251
- final_song = left_chunk + y[64:-64] + right_chunk
252
-
253
  #==================================================================
254
 
255
  print('=' * 70)
 
115
  if escore_notes:
116
 
117
  escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes[0], sort_drums_last=True)
118
+
119
+ escore_notes = TMIDIX.recalculate_score_timings([e for e in escore_notes if e[3] != 9])
120
 
121
  dscore = TMIDIX.delta_score_notes(escore_notes)
122
 
 
215
 
216
  print('Loading MIDI...')
217
 
218
+ score, chords = load_midi(input_midi.name)
219
 
220
+ if score is not None and chords is not None:
221
 
222
  print('Sample score tokens', score[:10])
223
 
224
  #==================================================================
225
+
226
+ def gen_drums(seq):
227
+
228
+ y = 256
229
+ seq.append((128*128)+38+256) # Drum pitch
230
+
231
+ while y > 255:
232
+
233
+ x = torch.LongTensor(seq).to(device_type)
234
+
235
+ with ctx:
236
+ out = model.generate(x,
237
+ 1,
238
+ temperature=model_temperature,
239
+ filter_logits_fn=top_p,
240
+ filter_kwargs={'thres': model_sampling_top_p},
241
+ return_prime=False,
242
+ eos_token=18818,
243
+ verbose=False)
244
 
245
+ y = out.tolist()[0]
246
+
247
+ if y > 255:
248
+ seq.append(y)
249
+
250
+ return seq
251
+
 
252
  #==================================================================
253
 
254
  print('=' * 70)
255
  print('Generating...')
256
+
257
+ final_song = [18816]
258
 
259
+ for i in range(len(chords)):
 
 
 
 
 
 
 
 
 
 
260
 
261
+ final_song.extend(chords[i])
262
+
263
+ final_song = gen_drums(final_song)
264
 
 
 
265
  #==================================================================
266
 
267
  print('=' * 70)