Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -172,7 +172,8 @@ def load_midi(input_midi, melody_patch=-1, use_nth_note=1):
|
|
| 172 |
#==================================================================================
|
| 173 |
|
| 174 |
@spaces.GPU
|
| 175 |
-
def Generate_Accompaniment(input_midi,
|
|
|
|
| 176 |
generation_type,
|
| 177 |
melody_patch,
|
| 178 |
use_nth_note,
|
|
@@ -266,6 +267,7 @@ def Generate_Accompaniment(input_midi,
|
|
| 266 |
print('Requested settings:')
|
| 267 |
print('=' * 70)
|
| 268 |
print('Input MIDI file name:', fn)
|
|
|
|
| 269 |
print('Generation type:', generation_type)
|
| 270 |
print('Source melody patch:', melody_patch)
|
| 271 |
print('Use nth melody note:', use_nth_note)
|
|
@@ -275,7 +277,12 @@ def Generate_Accompaniment(input_midi,
|
|
| 275 |
|
| 276 |
#==================================================================
|
| 277 |
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
print('Sample score events', score[:12])
|
| 281 |
|
|
@@ -462,9 +469,11 @@ with gr.Blocks() as demo:
|
|
| 462 |
|
| 463 |
#==================================================================================
|
| 464 |
|
| 465 |
-
gr.Markdown("## Upload source melody MIDI or select
|
| 466 |
|
| 467 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
|
|
|
|
|
|
| 468 |
|
| 469 |
gr.Markdown("## Generation options")
|
| 470 |
|
|
@@ -482,7 +491,8 @@ with gr.Blocks() as demo:
|
|
| 482 |
output_midi = gr.File(label="MIDI file", file_types=[".mid"])
|
| 483 |
|
| 484 |
generate_btn.click(Generate_Accompaniment,
|
| 485 |
-
[input_midi,
|
|
|
|
| 486 |
generation_type,
|
| 487 |
melody_patch,
|
| 488 |
use_nth_note,
|
|
@@ -495,11 +505,11 @@ with gr.Blocks() as demo:
|
|
| 495 |
)
|
| 496 |
|
| 497 |
gr.Examples(
|
| 498 |
-
[["USSR-National-Anthem-Seed-Melody.mid", "Guided", -1, 1, 0.9],
|
| 499 |
-
["
|
| 500 |
-
["Sparks-Fly-Seed-Melody.mid", "Guided", -1, 1, 0.9]
|
| 501 |
],
|
| 502 |
-
[input_midi,
|
|
|
|
| 503 |
generation_type,
|
| 504 |
melody_patch,
|
| 505 |
use_nth_note,
|
|
|
|
| 172 |
#==================================================================================
|
| 173 |
|
| 174 |
@spaces.GPU
|
| 175 |
+
def Generate_Accompaniment(input_midi,
|
| 176 |
+
input_melody,
|
| 177 |
generation_type,
|
| 178 |
melody_patch,
|
| 179 |
use_nth_note,
|
|
|
|
| 267 |
print('Requested settings:')
|
| 268 |
print('=' * 70)
|
| 269 |
print('Input MIDI file name:', fn)
|
| 270 |
+
print('Input sample melody:', input_melody)
|
| 271 |
print('Generation type:', generation_type)
|
| 272 |
print('Source melody patch:', melody_patch)
|
| 273 |
print('Use nth melody note:', use_nth_note)
|
|
|
|
| 277 |
|
| 278 |
#==================================================================
|
| 279 |
|
| 280 |
+
if input_melody == 'Custom MIDI':
|
| 281 |
+
score, score_list = load_midi(input_midi.name, melody_patch, use_nth_note)
|
| 282 |
+
|
| 283 |
+
else:
|
| 284 |
+
score_list = popular_hook_melodies[[m[0] for m in popular_hook_melodies].index(input_melody)][1]
|
| 285 |
+
score = TMIDIX.flatten(score)
|
| 286 |
|
| 287 |
print('Sample score events', score[:12])
|
| 288 |
|
|
|
|
| 469 |
|
| 470 |
#==================================================================================
|
| 471 |
|
| 472 |
+
gr.Markdown("## Upload source melody MIDI or select a sample melody below")
|
| 473 |
|
| 474 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
| 475 |
+
|
| 476 |
+
input_melody = gr.Dropdown([m[0] for m in popular_hook_melodies], value="Custom MIDI", label="Popular melodies database")
|
| 477 |
|
| 478 |
gr.Markdown("## Generation options")
|
| 479 |
|
|
|
|
| 491 |
output_midi = gr.File(label="MIDI file", file_types=[".mid"])
|
| 492 |
|
| 493 |
generate_btn.click(Generate_Accompaniment,
|
| 494 |
+
[input_midi,
|
| 495 |
+
input_melody,
|
| 496 |
generation_type,
|
| 497 |
melody_patch,
|
| 498 |
use_nth_note,
|
|
|
|
| 505 |
)
|
| 506 |
|
| 507 |
gr.Examples(
|
| 508 |
+
[["USSR-National-Anthem-Seed-Melody.mid", "Custom MIDI", "Guided", -1, 1, 0.9],
|
| 509 |
+
["Sparks-Fly-Seed-Melody.mid", "Custom MIDI", "Guided", -1, 1, 0.9]
|
|
|
|
| 510 |
],
|
| 511 |
+
[input_midi,
|
| 512 |
+
input_melody,
|
| 513 |
generation_type,
|
| 514 |
melody_patch,
|
| 515 |
use_nth_note,
|