Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,8 @@ print('=' * 70)
|
|
72 |
|
73 |
def load_midi(midi_file)
|
74 |
|
|
|
|
|
75 |
raw_score = TMIDIX.midi2single_track_ms_score(midi_file)
|
76 |
|
77 |
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)
|
@@ -149,17 +151,13 @@ def load_midi(midi_file)
|
|
149 |
|
150 |
@spaces.GPU
|
151 |
def Convert_Score_to_Performance(input_midi,
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
input_num_memory_tokens,
|
160 |
-
input_model_temperature,
|
161 |
-
input_model_top_p
|
162 |
-
):
|
163 |
|
164 |
#===============================================================================
|
165 |
|
@@ -175,115 +173,22 @@ def Convert_Score_to_Performance(input_midi,
|
|
175 |
print('Requested settings:')
|
176 |
print('=' * 70)
|
177 |
print('Input MIDI file name:', fn)
|
178 |
-
print('
|
179 |
-
print('Number of prime
|
180 |
-
print('Number of
|
181 |
-
print('
|
182 |
-
print('
|
183 |
-
print('
|
184 |
-
|
185 |
-
print('Number of memory tokens:', input_num_memory_tokens)
|
186 |
-
print('Model temperature:', input_model_temperature)
|
187 |
-
print('Model sampling top p value:', input_model_top_p)
|
188 |
print('=' * 70)
|
189 |
|
|
|
190 |
|
191 |
-
|
192 |
-
#===============================================================================
|
193 |
-
|
194 |
-
print('Loading MIDI...')
|
195 |
-
|
196 |
-
#===============================================================================
|
197 |
-
# Raw single-track ms score
|
198 |
-
|
199 |
-
raw_score = TMIDIX.midi2single_track_ms_score(input_midi.name)
|
200 |
-
|
201 |
-
#===============================================================================
|
202 |
-
# Enhanced score notes
|
203 |
-
|
204 |
-
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)[0]
|
205 |
-
|
206 |
-
escore_notes = [e for e in escore_notes if e[6] < 72 or e[6] == 128]
|
207 |
-
|
208 |
-
#=======================================================
|
209 |
-
# PRE-PROCESSING
|
210 |
-
|
211 |
-
#===============================================================================
|
212 |
-
# Augmented enhanced score notes
|
213 |
-
|
214 |
-
escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes, timings_divider=32, legacy_timings=True)
|
215 |
-
|
216 |
-
#===============================================================================
|
217 |
-
|
218 |
-
dscore = TMIDIX.enhanced_delta_score_notes(escore_notes)
|
219 |
-
|
220 |
-
cscore = TMIDIX.chordify_score(dscore)
|
221 |
-
|
222 |
-
#===============================================================================
|
223 |
-
|
224 |
-
score_toks = []
|
225 |
-
control_toks = []
|
226 |
-
prime_toks = []
|
227 |
-
|
228 |
-
for c in cscore:
|
229 |
-
|
230 |
-
ctime = c[0][0]
|
231 |
-
|
232 |
-
#=================================================================
|
233 |
-
|
234 |
-
chord = sorted(c, key=lambda x: -x[5])
|
235 |
-
|
236 |
-
gnotes = []
|
237 |
-
gdrums = []
|
238 |
-
|
239 |
-
for k, v in groupby(chord, key=lambda x: x[5]):
|
240 |
-
if k == 128:
|
241 |
-
gdrums.extend(sorted(v, key=lambda x: x[3], reverse=True))
|
242 |
-
else:
|
243 |
-
gnotes.append(sorted(v, key=lambda x: x[3], reverse=True))
|
244 |
-
|
245 |
-
#=================================================================
|
246 |
-
|
247 |
-
chord_toks = []
|
248 |
-
ctoks = []
|
249 |
-
ptoks = []
|
250 |
-
|
251 |
-
chord_toks.append(ctime)
|
252 |
-
ptoks.append(ctime)
|
253 |
-
|
254 |
-
if gdrums:
|
255 |
-
chord_toks.extend([e[3]+128 for e in gdrums] + [128])
|
256 |
-
ptoks.extend([e[3]+128 for e in gdrums] + [128])
|
257 |
-
|
258 |
-
else:
|
259 |
-
chord_toks.append(128)
|
260 |
-
ptoks.append(128)
|
261 |
-
|
262 |
-
if gnotes:
|
263 |
-
for g in gnotes:
|
264 |
-
|
265 |
-
durs = [e[1] // 4 for e in g]
|
266 |
-
clipped_dur = max(1, min(31, min(durs)))
|
267 |
-
|
268 |
-
chan = max(0, min(8, g[0][5] // 8))
|
269 |
-
|
270 |
-
chan_dur_tok = ((chan * 32) + clipped_dur) + 256
|
271 |
-
|
272 |
-
ctoks.append([chan_dur_tok, len(g)])
|
273 |
-
|
274 |
-
ptoks.append(chan_dur_tok)
|
275 |
-
ptoks.extend([e[3]+544 for e in g])
|
276 |
-
|
277 |
-
score_toks.append(chord_toks)
|
278 |
-
control_toks.append(ctoks)
|
279 |
-
prime_toks.append(ptoks)
|
280 |
-
|
281 |
-
print('Done!')
|
282 |
-
print('=' * 70)
|
283 |
|
284 |
#==================================================================
|
285 |
|
286 |
-
print('Sample output events',
|
287 |
print('=' * 70)
|
288 |
print('Generating...')
|
289 |
|
|
|
72 |
|
73 |
def load_midi(midi_file)
|
74 |
|
75 |
+
print('Loading MIDI...')
|
76 |
+
|
77 |
raw_score = TMIDIX.midi2single_track_ms_score(midi_file)
|
78 |
|
79 |
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)
|
|
|
151 |
|
152 |
@spaces.GPU
|
153 |
def Convert_Score_to_Performance(input_midi,
|
154 |
+
input_conv_type,
|
155 |
+
input_number_prime_notes,
|
156 |
+
input_number_conv_notes,
|
157 |
+
input_model_dur_top_k,
|
158 |
+
input_model_dur_temperature,
|
159 |
+
input_model_vel_temperature
|
160 |
+
):
|
|
|
|
|
|
|
|
|
161 |
|
162 |
#===============================================================================
|
163 |
|
|
|
173 |
print('Requested settings:')
|
174 |
print('=' * 70)
|
175 |
print('Input MIDI file name:', fn)
|
176 |
+
print('Conversion type:', input_conv_type)
|
177 |
+
print('Number of prime notes:', input_number_prime_notes)
|
178 |
+
print('Number of notes to convert:', input_number_conv_notes)
|
179 |
+
print('Model durations sampling top value:', input_model_dur_top_k)
|
180 |
+
print('Model durations temperature:', input_model_dur_temperature)
|
181 |
+
print('Model velocities temperature:', input_model_vel_temperature)
|
182 |
+
|
|
|
|
|
|
|
183 |
print('=' * 70)
|
184 |
|
185 |
+
#==================================================================
|
186 |
|
187 |
+
melody_chords, src_melody_chords = load_midi(input_midi)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
#==================================================================
|
190 |
|
191 |
+
print('Sample output events', melody_chords[:16])
|
192 |
print('=' * 70)
|
193 |
print('Generating...')
|
194 |
|