Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,29 +106,6 @@ print('=' * 70)
|
|
| 106 |
|
| 107 |
# =================================================================================================
|
| 108 |
|
| 109 |
-
@spaces.GPU
|
| 110 |
-
def inpaint_pitches(inp_seq,
|
| 111 |
-
input_patch,
|
| 112 |
-
input_inpaint_ratio,
|
| 113 |
-
input_top_k
|
| 114 |
-
):
|
| 115 |
-
|
| 116 |
-
print('*' * 70)
|
| 117 |
-
print('Inpainting pitches...')
|
| 118 |
-
|
| 119 |
-
m_pos = [i for i in range(0, SEQ_LEN) if (128*input_patch)+256 < melody_chords[i] < (128*(input_patch+1))+256]
|
| 120 |
-
|
| 121 |
-
results = predict_masked_tokens(model, inp_seq[:SEQ_LEN], mask_positions=m_pos)
|
| 122 |
-
|
| 123 |
-
output_seq = results['predicted_ids']
|
| 124 |
-
|
| 125 |
-
print('Done!')
|
| 126 |
-
print('=' * 70)
|
| 127 |
-
|
| 128 |
-
return output_seq
|
| 129 |
-
|
| 130 |
-
# =================================================================================================
|
| 131 |
-
|
| 132 |
def load_midi(input_midi):
|
| 133 |
|
| 134 |
"""Process the input MIDI file and create a token sequence."""
|
|
@@ -296,6 +273,31 @@ def save_midi(tokens):
|
|
| 296 |
|
| 297 |
# =================================================================================================
|
| 298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
def Inpaint_Pitches(input_midi,
|
| 300 |
input_patch,
|
| 301 |
input_inpaint_ratio,
|
|
@@ -426,7 +428,7 @@ with app:
|
|
| 426 |
|
| 427 |
input_top_k = gr.Slider(1, 5, value=1, step=1, label="Top k value")
|
| 428 |
|
| 429 |
-
run_btn = gr.Button("
|
| 430 |
|
| 431 |
gr.Markdown("## Generation results")
|
| 432 |
|
|
|
|
| 106 |
|
| 107 |
# =================================================================================================
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
def load_midi(input_midi):
|
| 110 |
|
| 111 |
"""Process the input MIDI file and create a token sequence."""
|
|
|
|
| 273 |
|
| 274 |
# =================================================================================================
|
| 275 |
|
| 276 |
+
@spaces.GPU
|
| 277 |
+
def inpaint_pitches(inp_seq,
|
| 278 |
+
input_patch,
|
| 279 |
+
input_inpaint_ratio,
|
| 280 |
+
input_top_k
|
| 281 |
+
):
|
| 282 |
+
|
| 283 |
+
print('*' * 70)
|
| 284 |
+
print('Inpainting pitches...')
|
| 285 |
+
|
| 286 |
+
inp_seq = inp_seq[:SEQ_LEN]
|
| 287 |
+
|
| 288 |
+
m_pos = [i for i in range(0, SEQ_LEN) if (128*input_patch)+256 < inp_seq[i] < (128*(input_patch+1))+256]
|
| 289 |
+
|
| 290 |
+
results = predict_masked_tokens(model, inp_seq, mask_positions=m_pos)
|
| 291 |
+
|
| 292 |
+
output_seq = results['predicted_ids']
|
| 293 |
+
|
| 294 |
+
print('Done!')
|
| 295 |
+
print('=' * 70)
|
| 296 |
+
|
| 297 |
+
return output_seq
|
| 298 |
+
|
| 299 |
+
# =================================================================================================
|
| 300 |
+
|
| 301 |
def Inpaint_Pitches(input_midi,
|
| 302 |
input_patch,
|
| 303 |
input_inpaint_ratio,
|
|
|
|
| 428 |
|
| 429 |
input_top_k = gr.Slider(1, 5, value=1, step=1, label="Top k value")
|
| 430 |
|
| 431 |
+
run_btn = gr.Button("Inpaint Pitches", variant="primary")
|
| 432 |
|
| 433 |
gr.Markdown("## Generation results")
|
| 434 |
|