Spaces:
Runtime error
Runtime error
asigalov61
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ in_space = os.getenv("SYSTEM") == "spaces"
|
|
23 |
# =================================================================================================
|
24 |
|
25 |
@spaces.GPU
|
26 |
-
def GenerateAccompaniment(input_midi, input_num_tokens,
|
27 |
print('=' * 70)
|
28 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
29 |
start_time = reqtime.time()
|
@@ -31,7 +31,7 @@ def GenerateAccompaniment(input_midi, input_num_tokens, input_acc_type):
|
|
31 |
print('Loading model...')
|
32 |
|
33 |
SEQ_LEN = 8192 # Models seq len
|
34 |
-
PAD_IDX =
|
35 |
DEVICE = 'cuda' # 'cuda'
|
36 |
|
37 |
# instantiate the model
|
@@ -50,7 +50,7 @@ def GenerateAccompaniment(input_midi, input_num_tokens, input_acc_type):
|
|
50 |
print('Loading model checkpoint...')
|
51 |
|
52 |
model.load_state_dict(
|
53 |
-
torch.load('
|
54 |
map_location=DEVICE))
|
55 |
print('=' * 70)
|
56 |
|
@@ -369,21 +369,21 @@ if __name__ == "__main__":
|
|
369 |
|
370 |
app = gr.Blocks()
|
371 |
with app:
|
372 |
-
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>
|
373 |
-
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>
|
374 |
gr.Markdown(
|
375 |
-
"![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.
|
376 |
-
"
|
377 |
-
"Check out [
|
378 |
"[Open In Colab]"
|
379 |
-
"(https://colab.research.google.com/github/asigalov61/
|
380 |
" for faster execution and endless generation"
|
381 |
)
|
382 |
gr.Markdown("## Upload your MIDI or select a sample example MIDI")
|
383 |
|
384 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
385 |
-
input_num_tokens = gr.Slider(4, 128, value=32, step=1, label="Number of composition chords to generate
|
386 |
-
|
387 |
|
388 |
run_btn = gr.Button("generate", variant="primary")
|
389 |
|
@@ -396,18 +396,24 @@ if __name__ == "__main__":
|
|
396 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
397 |
|
398 |
|
399 |
-
run_event = run_btn.click(GenerateAccompaniment, [input_midi, input_num_tokens,
|
400 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
401 |
|
402 |
gr.Examples(
|
403 |
-
[["
|
404 |
-
["
|
405 |
-
["
|
406 |
-
["
|
407 |
-
["
|
408 |
-
["
|
409 |
-
["
|
410 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
412 |
GenerateAccompaniment,
|
413 |
cache_examples=True,
|
|
|
23 |
# =================================================================================================
|
24 |
|
25 |
@spaces.GPU
|
26 |
+
def GenerateAccompaniment(input_midi, input_num_tokens, input_conditioning_type):
|
27 |
print('=' * 70)
|
28 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
29 |
start_time = reqtime.time()
|
|
|
31 |
print('Loading model...')
|
32 |
|
33 |
SEQ_LEN = 8192 # Models seq len
|
34 |
+
PAD_IDX = 707 # Models pad index
|
35 |
DEVICE = 'cuda' # 'cuda'
|
36 |
|
37 |
# instantiate the model
|
|
|
50 |
print('Loading model checkpoint...')
|
51 |
|
52 |
model.load_state_dict(
|
53 |
+
torch.load('Chords_Progressions_Transformer_Small_2048_Trained_Model_12947_steps_0.9316_loss_0.7386_acc.pth',
|
54 |
map_location=DEVICE))
|
55 |
print('=' * 70)
|
56 |
|
|
|
369 |
|
370 |
app = gr.Blocks()
|
371 |
with app:
|
372 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Chords Progressions Transformer</h1>")
|
373 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Chords-conditioned music transformer</h1>")
|
374 |
gr.Markdown(
|
375 |
+
"![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Chords-Progressions-Transformer&style=flat)\n\n"
|
376 |
+
"Generate music based on chords progressions\n\n"
|
377 |
+
"Check out [Chords Progressions Transformer](https://github.com/asigalov61/Chords-Progressions-Transformer) on GitHub!\n\n"
|
378 |
"[Open In Colab]"
|
379 |
+
"(https://colab.research.google.com/github/asigalov61/Chords-Progressions-Transformer/blob/main/Chords_Progressions_Transformer.ipynb)"
|
380 |
" for faster execution and endless generation"
|
381 |
)
|
382 |
gr.Markdown("## Upload your MIDI or select a sample example MIDI")
|
383 |
|
384 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
385 |
+
input_num_tokens = gr.Slider(4, 128, value=32, step=1, label="Number of composition chords to generate progression for")
|
386 |
+
input_conditioning_type = gr.Radio(["Chords", "Chords-Times", "Chords-Times-Durations"], label="Conditioning type")
|
387 |
|
388 |
run_btn = gr.Button("generate", variant="primary")
|
389 |
|
|
|
396 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
397 |
|
398 |
|
399 |
+
run_event = run_btn.click(GenerateAccompaniment, [input_midi, input_num_tokens, input_conditioning_type],
|
400 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
401 |
|
402 |
gr.Examples(
|
403 |
+
[["Chords-Progressions-Transformer-Piano-Seed-1.mid", 128, "Chords"],
|
404 |
+
["Chords-Progressions-Transformer-Piano-Seed-2.mid", 128, "Chords"],
|
405 |
+
["Chords-Progressions-Transformer-Piano-Seed-3.mid", 128, "Chords"],
|
406 |
+
["Chords-Progressions-Transformer-Piano-Seed-4.mid", 128, "Chords"],
|
407 |
+
["Chords-Progressions-Transformer-Piano-Seed-5.mid", 128, "Chords"],
|
408 |
+
["Chords-Progressions-Transformer-Piano-Seed-6.mid", 128, "Chords"],
|
409 |
+
["Chords-Progressions-Transformer-MI-Seed-1.mid", 128, "Chords"]
|
410 |
+
["Chords-Progressions-Transformer-MI-Seed-2.mid", 128, "Chords"]
|
411 |
+
["Chords-Progressions-Transformer-MI-Seed-3.mid", 128, "Chords"]
|
412 |
+
["Chords-Progressions-Transformer-MI-Seed-4.mid", 128, "Chords"]
|
413 |
+
["Chords-Progressions-Transformer-MI-Seed-5.mid", 128, "Chords"]
|
414 |
+
["Chords-Progressions-Transformer-MI-Seed-6.mid", 128, "Chords"]
|
415 |
+
],
|
416 |
+
[input_midi, input_num_tokens, input_conditioning_type],
|
417 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
418 |
GenerateAccompaniment,
|
419 |
cache_examples=True,
|