Update app.py
Browse files
app.py
CHANGED
|
@@ -313,73 +313,7 @@ def InpaintPitches(input_midi, input_num_of_notes, input_patch_number):
|
|
| 313 |
|
| 314 |
#==========================================================================
|
| 315 |
|
| 316 |
-
nidx = 0
|
| 317 |
-
first_inote = True
|
| 318 |
-
fidx = 0
|
| 319 |
|
| 320 |
-
number_of_prime_tokens = number_of_prime_notes * 3
|
| 321 |
-
|
| 322 |
-
for i, m in enumerate(melody_chords):
|
| 323 |
-
|
| 324 |
-
if 2304 <= melody_chords[i] < 18945:
|
| 325 |
-
|
| 326 |
-
cpatch = (melody_chords[i]-2304) // 129
|
| 327 |
-
|
| 328 |
-
if cpatch == inpaint_MIDI_patch:
|
| 329 |
-
nidx += 1
|
| 330 |
-
if first_inote:
|
| 331 |
-
fidx += 1
|
| 332 |
-
|
| 333 |
-
if first_inote and fidx == number_of_prime_notes:
|
| 334 |
-
number_of_prime_tokens = i
|
| 335 |
-
first_inote = False
|
| 336 |
-
|
| 337 |
-
if nidx == input_num_of_notes:
|
| 338 |
-
break
|
| 339 |
-
|
| 340 |
-
nidx = i
|
| 341 |
-
|
| 342 |
-
#==========================================================================
|
| 343 |
-
|
| 344 |
-
out2 = []
|
| 345 |
-
|
| 346 |
-
for m in melody_chords[:number_of_prime_tokens]:
|
| 347 |
-
out2.append(m)
|
| 348 |
-
|
| 349 |
-
for i in range(number_of_prime_tokens, len(melody_chords[:nidx])):
|
| 350 |
-
|
| 351 |
-
cpatch = (melody_chords[i]-2304) // 129
|
| 352 |
-
|
| 353 |
-
if 2304 <= melody_chords[i] < 18945 and (cpatch) == inpaint_MIDI_patch:
|
| 354 |
-
|
| 355 |
-
samples = []
|
| 356 |
-
|
| 357 |
-
for j in range(number_of_samples_per_inpainted_note):
|
| 358 |
-
|
| 359 |
-
inp = torch.LongTensor(out2[-number_of_memory_tokens:]).cuda()
|
| 360 |
-
|
| 361 |
-
with ctx:
|
| 362 |
-
out1 = model.generate(inp,
|
| 363 |
-
1,
|
| 364 |
-
temperature=temperature,
|
| 365 |
-
return_prime=True,
|
| 366 |
-
verbose=False)
|
| 367 |
-
|
| 368 |
-
with torch.no_grad():
|
| 369 |
-
test_loss, test_acc = model(out1)
|
| 370 |
-
|
| 371 |
-
samples.append([out1.tolist()[0][-1], test_acc.tolist()])
|
| 372 |
-
|
| 373 |
-
accs = [y[1] for y in samples]
|
| 374 |
-
max_acc = max(accs)
|
| 375 |
-
max_acc_sample = samples[accs.index(max_acc)][0]
|
| 376 |
-
|
| 377 |
-
cpitch = (max_acc_sample-2304) % 129
|
| 378 |
-
|
| 379 |
-
out2.extend([((cpatch * 129) + cpitch)+2304])
|
| 380 |
-
|
| 381 |
-
else:
|
| 382 |
-
out2.append(melody_chords[i])
|
| 383 |
|
| 384 |
print('=' * 70)
|
| 385 |
print('Done!')
|
|
|
|
| 313 |
|
| 314 |
#==========================================================================
|
| 315 |
|
|
|
|
|
|
|
|
|
|
| 316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
print('=' * 70)
|
| 319 |
print('Done!')
|