Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,16 +9,30 @@ from pytz import timezone
|
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
|
|
|
|
|
|
|
| 12 |
from musicpy import algorithms, scale, write
|
| 13 |
|
| 14 |
# =================================================================================================
|
| 15 |
|
| 16 |
-
def Generate_POP(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
print('=' * 70)
|
| 19 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
| 20 |
start_time = reqtime.time()
|
| 21 |
print('=' * 70)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
#==================================================================
|
| 24 |
|
|
@@ -30,10 +44,35 @@ def Generate_POP():
|
|
| 30 |
|
| 31 |
pop_piece = algorithms.write_pop(scale('C', 'Major'))
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
#========================================================
|
| 38 |
|
| 39 |
print('Done!')
|
|
@@ -73,14 +112,26 @@ if __name__ == "__main__":
|
|
| 73 |
</p>
|
| 74 |
""")
|
| 75 |
|
| 76 |
-
gr.Markdown("##
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
run_btn = gr.Button("generate", variant="primary")
|
| 79 |
|
| 80 |
gr.Markdown("## Generation results")
|
| 81 |
|
| 82 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
| 83 |
|
| 84 |
-
run_event = run_btn.click(Generate_POP, [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
app.queue().launch()
|
|
|
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
+
import TMIDIX
|
| 13 |
+
|
| 14 |
from musicpy import algorithms, scale, write
|
| 15 |
|
| 16 |
# =================================================================================================
|
| 17 |
|
| 18 |
+
def Generate_POP(song_length,
|
| 19 |
+
song_semitone_key,
|
| 20 |
+
song_scale,
|
| 21 |
+
output_as_solo_piano
|
| 22 |
+
):
|
| 23 |
|
| 24 |
print('=' * 70)
|
| 25 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
| 26 |
start_time = reqtime.time()
|
| 27 |
print('=' * 70)
|
| 28 |
+
|
| 29 |
+
print('Requested settings:')
|
| 30 |
+
print('-' * 70)
|
| 31 |
+
print('Song length:', song_length)
|
| 32 |
+
print('Song semitone key:', song_semitone_key)
|
| 33 |
+
print('Song scale (1) Major / (0) Minor:', song_scale)
|
| 34 |
+
print('Output as solo Piano:', output_as_solo_piano)
|
| 35 |
+
print('-' * 70)
|
| 36 |
|
| 37 |
#==================================================================
|
| 38 |
|
|
|
|
| 44 |
|
| 45 |
pop_piece = algorithms.write_pop(scale('C', 'Major'))
|
| 46 |
|
| 47 |
+
midi_data = write(pop_piece, save_as_file=False)
|
| 48 |
+
|
| 49 |
+
midi_data.seek(0)
|
| 50 |
+
|
| 51 |
+
raw_score = TMIDIX.midi2single_track_ms_score(midi_data.read())
|
| 52 |
+
|
| 53 |
+
escore = TMIDIX.advanced_score_processor(raw_score,
|
| 54 |
+
return_enhanced_score_notes=True,
|
| 55 |
+
apply_sustain=True
|
| 56 |
+
)[0]
|
| 57 |
+
|
| 58 |
+
output_score = TMIDIX.recalculate_score_timings(escore)
|
| 59 |
|
| 60 |
+
if output_as_solo_piano:
|
| 61 |
+
output_score = TMIDIX.solo_piano_escore_notes(output_score)
|
| 62 |
+
|
| 63 |
+
output_midi = 'MuseCraft-AlgoPOP-Composition'
|
| 64 |
+
|
| 65 |
+
SONG, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(output_score)
|
| 66 |
+
|
| 67 |
+
detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(SONG,
|
| 68 |
+
output_signature = 'MuseCraft AlgoPOP',
|
| 69 |
+
output_file_name = output_midi,
|
| 70 |
+
track_name='Project Los Angeles',
|
| 71 |
+
list_of_MIDI_patches=patches
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
output_midi = output_midi + '.mid'
|
| 75 |
+
|
| 76 |
#========================================================
|
| 77 |
|
| 78 |
print('Done!')
|
|
|
|
| 112 |
</p>
|
| 113 |
""")
|
| 114 |
|
| 115 |
+
gr.Markdown("## Select generation options")
|
| 116 |
+
|
| 117 |
+
song_length = gr.Slider(10, 100, value=30, step=1, label="Song length")
|
| 118 |
+
song_semitone_key = gr.Slider(0, 11, value=0, step=1, label="Song semitone key")
|
| 119 |
+
song_scale = gr.Slider(0, 1, value=1, step=1, label="Song scale as (1) Major or as (0) Minor")
|
| 120 |
+
output_as_solo_piano = gr.Checkbox(value=False, label="Output as solo Piano")
|
| 121 |
+
|
| 122 |
run_btn = gr.Button("generate", variant="primary")
|
| 123 |
|
| 124 |
gr.Markdown("## Generation results")
|
| 125 |
|
| 126 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
| 127 |
|
| 128 |
+
run_event = run_btn.click(Generate_POP, [
|
| 129 |
+
song_length,
|
| 130 |
+
song_semitone_key,
|
| 131 |
+
song_scale,
|
| 132 |
+
output_as_solo_piano
|
| 133 |
+
],
|
| 134 |
+
[output_midi]
|
| 135 |
+
)
|
| 136 |
|
| 137 |
app.queue().launch()
|