Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ import time as reqtime
|
|
| 7 |
import datetime
|
| 8 |
from pytz import timezone
|
| 9 |
|
|
|
|
|
|
|
| 10 |
import spaces
|
| 11 |
import gradio as gr
|
| 12 |
|
|
@@ -27,6 +29,8 @@ def Generate_Rock_Song(input_midi,
|
|
| 27 |
input_use_original_durations,
|
| 28 |
input_match_original_pitches_counts
|
| 29 |
):
|
|
|
|
|
|
|
| 30 |
|
| 31 |
print('=' * 70)
|
| 32 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
|
@@ -46,6 +50,8 @@ def Generate_Rock_Song(input_midi,
|
|
| 46 |
print('Match original pitches counts:', input_match_original_pitches_counts)
|
| 47 |
print('=' * 70)
|
| 48 |
|
|
|
|
|
|
|
| 49 |
print('Loading model...')
|
| 50 |
|
| 51 |
SEQ_LEN = 4096
|
|
@@ -83,6 +89,10 @@ def Generate_Rock_Song(input_midi,
|
|
| 83 |
|
| 84 |
print('Done!')
|
| 85 |
print('=' * 70)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
#===============================================================================
|
| 88 |
# Raw single-track ms score
|
|
@@ -169,12 +179,10 @@ def Generate_Rock_Song(input_midi,
|
|
| 169 |
control_toks.append(ctoks)
|
| 170 |
prime_toks.append(ptoks)
|
| 171 |
|
| 172 |
-
print('
|
| 173 |
-
print('
|
| 174 |
|
| 175 |
#==================================================================
|
| 176 |
-
|
| 177 |
-
print('=' * 70)
|
| 178 |
|
| 179 |
print('Sample output events', prime_toks[:16])
|
| 180 |
print('=' * 70)
|
|
@@ -235,28 +243,34 @@ def Generate_Rock_Song(input_midi,
|
|
| 235 |
|
| 236 |
#==================================================================
|
| 237 |
|
| 238 |
-
num_prime_chords = 128
|
| 239 |
-
pass_chan_dur_tok = False
|
| 240 |
-
match_ptcs_counts = False
|
| 241 |
-
|
| 242 |
song = []
|
| 243 |
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
| 260 |
|
| 261 |
#==================================================================
|
| 262 |
|
|
|
|
| 7 |
import datetime
|
| 8 |
from pytz import timezone
|
| 9 |
|
| 10 |
+
import tqdm
|
| 11 |
+
|
| 12 |
import spaces
|
| 13 |
import gradio as gr
|
| 14 |
|
|
|
|
| 29 |
input_use_original_durations,
|
| 30 |
input_match_original_pitches_counts
|
| 31 |
):
|
| 32 |
+
|
| 33 |
+
#===============================================================================
|
| 34 |
|
| 35 |
print('=' * 70)
|
| 36 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
|
|
|
| 50 |
print('Match original pitches counts:', input_match_original_pitches_counts)
|
| 51 |
print('=' * 70)
|
| 52 |
|
| 53 |
+
#===============================================================================
|
| 54 |
+
|
| 55 |
print('Loading model...')
|
| 56 |
|
| 57 |
SEQ_LEN = 4096
|
|
|
|
| 89 |
|
| 90 |
print('Done!')
|
| 91 |
print('=' * 70)
|
| 92 |
+
|
| 93 |
+
#===============================================================================
|
| 94 |
+
|
| 95 |
+
print('Loading MIDI...')
|
| 96 |
|
| 97 |
#===============================================================================
|
| 98 |
# Raw single-track ms score
|
|
|
|
| 179 |
control_toks.append(ctoks)
|
| 180 |
prime_toks.append(ptoks)
|
| 181 |
|
| 182 |
+
print('Done!')
|
| 183 |
+
print('=' * 70)
|
| 184 |
|
| 185 |
#==================================================================
|
|
|
|
|
|
|
| 186 |
|
| 187 |
print('Sample output events', prime_toks[:16])
|
| 188 |
print('=' * 70)
|
|
|
|
| 243 |
|
| 244 |
#==================================================================
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
song = []
|
| 247 |
|
| 248 |
+
if input_freestyle_continuation:
|
| 249 |
+
output = generate_continuation(512, 1024)
|
| 250 |
+
song.extend(output)
|
| 251 |
+
|
| 252 |
+
else:
|
| 253 |
+
|
| 254 |
+
for i in range(input_number_prime_chords):
|
| 255 |
+
song.extend(prime_toks[i])
|
| 256 |
+
|
| 257 |
+
for i in tqdm.tqdm(range(input_number_prime_chords, len(score_toks))):
|
| 258 |
+
|
| 259 |
+
song.extend(score_toks[i])
|
| 260 |
|
| 261 |
+
if control_toks[i]:
|
| 262 |
+
for ct in control_toks[i]:
|
| 263 |
+
|
| 264 |
+
if input_use_original_durations:
|
| 265 |
+
song.append(ct[0])
|
| 266 |
+
|
| 267 |
+
if input_match_original_pitches_counts:
|
| 268 |
+
out_seq = generate_tokens(song, ct[1])
|
| 269 |
+
|
| 270 |
+
else:
|
| 271 |
+
out_seq = generate_tokens(song)
|
| 272 |
+
|
| 273 |
+
song.extend(out_seq)
|
| 274 |
|
| 275 |
#==================================================================
|
| 276 |
|