asigalov61 commited on
Commit
9800628
·
verified ·
1 Parent(s): 9cd9af8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -14
app.py CHANGED
@@ -111,28 +111,82 @@ def Generate_Melody(input_parsons_code,
111
  else:
112
  mult_code = '*UUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUU'
113
 
 
 
114
  print('Done!')
115
  print('=' * 70)
116
 
117
  #===============================================================================
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
 
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  #===============================================================================
122
  print('Rendering results...')
123
 
124
  print('=' * 70)
125
- print('Sample INTs', mixed_song[:5])
126
  print('=' * 70)
127
-
128
- output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(mixed_song)
129
 
130
- detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(output_score,
131
- output_signature = 'Harmonic Melody MIDI Mixer',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  output_file_name = fn1,
133
- track_name='Project Los Angeles',
134
- list_of_MIDI_patches=patches,
135
- timings_multiplier=16
136
  )
137
 
138
  new_fn = fn1+'.mid'
@@ -151,7 +205,6 @@ def Generate_Melody(input_parsons_code,
151
  #========================================================
152
 
153
  output_midi_title = str(fn1)
154
- output_midi_summary = str(MIDI_Summary)
155
  output_midi = str(new_fn)
156
  output_audio = (16000, audio)
157
 
@@ -163,7 +216,6 @@ def Generate_Melody(input_parsons_code,
163
 
164
  print('Output MIDI file name:', output_midi)
165
  print('Output MIDI title:', output_midi_title)
166
- print('Output MIDI summary:', MIDI_Summary)
167
  print('=' * 70)
168
 
169
 
@@ -174,7 +226,7 @@ def Generate_Melody(input_parsons_code,
174
  print('-' * 70)
175
  print('Req execution time:', (reqtime.time() - start_time), 'sec')
176
 
177
- return output_midi_title, output_midi_summary, output_midi, output_audio, output_plot
178
 
179
  # =================================================================================================
180
 
@@ -219,7 +271,6 @@ if __name__ == "__main__":
219
  gr.Markdown("## Output results")
220
 
221
  output_midi_title = gr.Textbox(label="Output MIDI title")
222
- output_midi_summary = gr.Textbox(label="Output MIDI summary")
223
  output_audio = gr.Audio(label="Output MIDI audio", format="mp3", elem_id="midi_audio")
224
  output_plot = gr.Plot(label="Output MIDI score plot")
225
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
@@ -228,7 +279,7 @@ if __name__ == "__main__":
228
  input_first_note_duration,
229
  iinput_first_note_MIDI_pitch,
230
  ],
231
- [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
232
 
233
  gr.Examples(
234
  [["*UUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUU", 15, 60],
@@ -237,7 +288,7 @@ if __name__ == "__main__":
237
  input_first_note_duration,
238
  iinput_first_note_MIDI_pitch,
239
  ],
240
- [output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
241
  Generate_Melody,
242
  cache_examples=True,
243
  )
 
111
  else:
112
  mult_code = '*UUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUU'
113
 
114
+ pcode = parsons_code_to_tokens(mult_code)
115
+
116
  print('Done!')
117
  print('=' * 70)
118
 
119
  #===============================================================================
120
 
121
+ print('Generating melody...')
122
+
123
+ song = []
124
+
125
+ song.append(389)
126
+ song.extend(pcode)
127
+ song.append(390)
128
+
129
+ song.extend([388, 0, 10+128, 66+256])
130
+
131
+ for i in tqdm.tqdm(range(1, len(td_str[:64]))):
132
+
133
+ song.append(pcode[i])
134
 
135
+ x = torch.tensor(song, dtype=torch.long, device='cpu')
136
 
137
+ with ctx:
138
+ out = model.generate(x,
139
+ 3,
140
+ filter_logits_fn=top_k,
141
+ filter_kwargs={'k': 1},
142
+ temperature=1.0,
143
+ return_prime=False,
144
+ verbose=False)
145
+
146
+ y = out.tolist()[0]
147
+
148
+ song.extend(y)
149
+
150
+ print('Done!')
151
+ print('=' * 70)
152
+
153
  #===============================================================================
154
  print('Rendering results...')
155
 
156
  print('=' * 70)
157
+ print('Sample INTs', song[:5])
158
  print('=' * 70)
 
 
159
 
160
+ song_f = []
161
+
162
+ time = 0
163
+ dur = 4
164
+ vel = 90
165
+ pitch = 60
166
+ channel = 0
167
+
168
+ for ss in song:
169
+
170
+ if 0 <= ss < 128:
171
+
172
+ time += ss * 32
173
+
174
+ if 128 <= ss < 256:
175
+
176
+ dur = (ss-128) * 32
177
+
178
+ if 256 <= ss < 384:
179
+
180
+ pitch = ss-256
181
+
182
+ song_f.append(['note', time, dur, channel, pitch, vel, 0])
183
+
184
+ fn1 = 'Parsons-Code-Melody-Transformer-Composition'
185
+
186
+ detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
187
+ output_signature = 'Parsons Code Melody Transformer',
188
  output_file_name = fn1,
189
+ track_name='Project Los Angeles'
 
 
190
  )
191
 
192
  new_fn = fn1+'.mid'
 
205
  #========================================================
206
 
207
  output_midi_title = str(fn1)
 
208
  output_midi = str(new_fn)
209
  output_audio = (16000, audio)
210
 
 
216
 
217
  print('Output MIDI file name:', output_midi)
218
  print('Output MIDI title:', output_midi_title)
 
219
  print('=' * 70)
220
 
221
 
 
226
  print('-' * 70)
227
  print('Req execution time:', (reqtime.time() - start_time), 'sec')
228
 
229
+ return output_midi_title, output_midi, output_audio, output_plot
230
 
231
  # =================================================================================================
232
 
 
271
  gr.Markdown("## Output results")
272
 
273
  output_midi_title = gr.Textbox(label="Output MIDI title")
 
274
  output_audio = gr.Audio(label="Output MIDI audio", format="mp3", elem_id="midi_audio")
275
  output_plot = gr.Plot(label="Output MIDI score plot")
276
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
 
279
  input_first_note_duration,
280
  iinput_first_note_MIDI_pitch,
281
  ],
282
+ [output_midi_title, output_midi, output_audio, output_plot])
283
 
284
  gr.Examples(
285
  [["*UUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUU", 15, 60],
 
288
  input_first_note_duration,
289
  iinput_first_note_MIDI_pitch,
290
  ],
291
+ [output_midi_title, output_midi, output_audio, output_plot],
292
  Generate_Melody,
293
  cache_examples=True,
294
  )