Update app.py
Browse files
app.py
CHANGED
|
@@ -178,7 +178,6 @@ def load_midi(input_midi):
|
|
| 178 |
def Inpaint_Pitches(input_midi,
|
| 179 |
patches_to_inpaint,
|
| 180 |
inpaint_every_nth_note,
|
| 181 |
-
forbid_original_pitches,
|
| 182 |
max_inpainted_pitch_dev,
|
| 183 |
max_inpaint_tries_per_note,
|
| 184 |
num_prime_tokens,
|
|
@@ -206,7 +205,6 @@ def Inpaint_Pitches(input_midi,
|
|
| 206 |
|
| 207 |
print('Patches to inpaint:', patches_to_inpaint)
|
| 208 |
print('Inpaint every nth note:', inpaint_every_nth_note)
|
| 209 |
-
print('Forbid original pitches:', forbid_original_pitches)
|
| 210 |
print('Max inpainted pitch dev:', max_inpainted_pitch_dev)
|
| 211 |
print('Max inpaint tries per note:', max_inpaint_tries_per_note)
|
| 212 |
print('-' * 70)
|
|
@@ -251,18 +249,17 @@ def Inpaint_Pitches(input_midi,
|
|
| 251 |
if old_patch in ipatches and notes_counter % inpaint_every_nth_note == 0:
|
| 252 |
|
| 253 |
x = torch.LongTensor(inpainted_song[-num_mem_tokens:]).cuda()
|
| 254 |
-
|
| 255 |
-
new_pitch = old_pitch
|
| 256 |
tries = 0
|
| 257 |
|
| 258 |
-
while (
|
| 259 |
|
| 260 |
with ctx:
|
| 261 |
out = model.generate(x,
|
| 262 |
1,
|
| 263 |
-
temperature=
|
| 264 |
filter_logits_fn=top_k,
|
| 265 |
-
filter_kwargs={'k':
|
| 266 |
return_prime=False,
|
| 267 |
verbose=False)
|
| 268 |
|
|
@@ -272,9 +269,6 @@ def Inpaint_Pitches(input_midi,
|
|
| 272 |
|
| 273 |
tries += 1
|
| 274 |
|
| 275 |
-
if not forbid_original_pitches:
|
| 276 |
-
break
|
| 277 |
-
|
| 278 |
if tries == max_inpaint_tries_per_note:
|
| 279 |
new_pitch = old_pitch
|
| 280 |
|
|
@@ -453,7 +447,6 @@ with gr.Blocks() as demo:
|
|
| 453 |
)
|
| 454 |
|
| 455 |
inpaint_every_nth_note = gr.Slider(1, 10, value=1, step=1, label="Inpaint every nth note")
|
| 456 |
-
forbid_original_pitches = gr.Checkbox(value=False, label="Forbid repeating original pitches")
|
| 457 |
max_inpainted_pitch_dev = gr.Slider(12, 24, value=12, step=12, label="Maximum inpainted pitch deviation")
|
| 458 |
max_inpaint_tries_per_note = gr.Slider(5, 100, value=10, step=1, label="Maximum inpainting attempts per note")
|
| 459 |
|
|
@@ -476,7 +469,6 @@ with gr.Blocks() as demo:
|
|
| 476 |
[input_midi,
|
| 477 |
patches_to_inpaint,
|
| 478 |
inpaint_every_nth_note,
|
| 479 |
-
forbid_original_pitches,
|
| 480 |
max_inpainted_pitch_dev,
|
| 481 |
max_inpaint_tries_per_note,
|
| 482 |
num_prime_tokens,
|
|
@@ -491,12 +483,11 @@ with gr.Blocks() as demo:
|
|
| 491 |
)
|
| 492 |
|
| 493 |
gr.Examples(
|
| 494 |
-
[["Orpheus-Music-Transformer-MI-Seed-1.mid", "Clarinet", 1,
|
| 495 |
],
|
| 496 |
[input_midi,
|
| 497 |
patches_to_inpaint,
|
| 498 |
inpaint_every_nth_note,
|
| 499 |
-
forbid_original_pitches,
|
| 500 |
max_inpainted_pitch_dev,
|
| 501 |
max_inpaint_tries_per_note,
|
| 502 |
num_prime_tokens,
|
|
|
|
| 178 |
def Inpaint_Pitches(input_midi,
|
| 179 |
patches_to_inpaint,
|
| 180 |
inpaint_every_nth_note,
|
|
|
|
| 181 |
max_inpainted_pitch_dev,
|
| 182 |
max_inpaint_tries_per_note,
|
| 183 |
num_prime_tokens,
|
|
|
|
| 205 |
|
| 206 |
print('Patches to inpaint:', patches_to_inpaint)
|
| 207 |
print('Inpaint every nth note:', inpaint_every_nth_note)
|
|
|
|
| 208 |
print('Max inpainted pitch dev:', max_inpainted_pitch_dev)
|
| 209 |
print('Max inpaint tries per note:', max_inpaint_tries_per_note)
|
| 210 |
print('-' * 70)
|
|
|
|
| 249 |
if old_patch in ipatches and notes_counter % inpaint_every_nth_note == 0:
|
| 250 |
|
| 251 |
x = torch.LongTensor(inpainted_song[-num_mem_tokens:]).cuda()
|
| 252 |
+
|
|
|
|
| 253 |
tries = 0
|
| 254 |
|
| 255 |
+
while (new_pitch > old_pitch + max_inpainted_pitch_dev or new_pitch < old_pitch - max_inpainted_pitch_dev) and tries < max_inpaint_tries_per_note:
|
| 256 |
|
| 257 |
with ctx:
|
| 258 |
out = model.generate(x,
|
| 259 |
1,
|
| 260 |
+
temperature=model_temperature,
|
| 261 |
filter_logits_fn=top_k,
|
| 262 |
+
filter_kwargs={'k': model_sampling_top_k},
|
| 263 |
return_prime=False,
|
| 264 |
verbose=False)
|
| 265 |
|
|
|
|
| 269 |
|
| 270 |
tries += 1
|
| 271 |
|
|
|
|
|
|
|
|
|
|
| 272 |
if tries == max_inpaint_tries_per_note:
|
| 273 |
new_pitch = old_pitch
|
| 274 |
|
|
|
|
| 447 |
)
|
| 448 |
|
| 449 |
inpaint_every_nth_note = gr.Slider(1, 10, value=1, step=1, label="Inpaint every nth note")
|
|
|
|
| 450 |
max_inpainted_pitch_dev = gr.Slider(12, 24, value=12, step=12, label="Maximum inpainted pitch deviation")
|
| 451 |
max_inpaint_tries_per_note = gr.Slider(5, 100, value=10, step=1, label="Maximum inpainting attempts per note")
|
| 452 |
|
|
|
|
| 469 |
[input_midi,
|
| 470 |
patches_to_inpaint,
|
| 471 |
inpaint_every_nth_note,
|
|
|
|
| 472 |
max_inpainted_pitch_dev,
|
| 473 |
max_inpaint_tries_per_note,
|
| 474 |
num_prime_tokens,
|
|
|
|
| 483 |
)
|
| 484 |
|
| 485 |
gr.Examples(
|
| 486 |
+
[["Orpheus-Music-Transformer-MI-Seed-1.mid", "Clarinet", 1, 12, 10, 128, 4096, 0.9, 15]
|
| 487 |
],
|
| 488 |
[input_midi,
|
| 489 |
patches_to_inpaint,
|
| 490 |
inpaint_every_nth_note,
|
|
|
|
| 491 |
max_inpainted_pitch_dev,
|
| 492 |
max_inpaint_tries_per_note,
|
| 493 |
num_prime_tokens,
|