asigalov61 commited on
Commit
8c321c5
·
verified ·
1 Parent(s): 30ed745

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -56
app.py CHANGED
@@ -59,7 +59,7 @@ for m in tqdm.tqdm(melody_chords_f):
59
  for tv in range(-3, 3):
60
 
61
  section = str_strip(m[2])
62
- section_tok = sections_dict.index(part)
63
 
64
  score = [t+tv if 256 < t < 512 else t for t in m[5]]
65
 
@@ -149,32 +149,32 @@ def Generate_POP_Section(input_parsons_code,
149
 
150
  print('Generating melody...')
151
 
152
- song = []
153
-
154
- song.append(389)
155
- song.extend(pcode)
156
- song.append(390)
157
-
158
- song.extend([388, 0, 10+128, 66+256])
159
-
160
- for i in tqdm.tqdm(range(1, len(td_str[:64]))):
161
 
162
- song.append(pcode[i])
 
 
 
163
 
164
- x = torch.tensor(song, dtype=torch.long, device='cpu')
165
 
166
- with ctx:
167
- out = model.generate(x,
168
- 3,
169
- filter_logits_fn=top_k,
170
- filter_kwargs={'k': 1},
171
- temperature=1.0,
172
- return_prime=False,
173
- verbose=False)
174
 
175
- y = out.tolist()[0]
176
 
177
- song.extend(y)
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  print('Done!')
180
  print('=' * 70)
@@ -287,49 +287,52 @@ if __name__ == "__main__":
287
  "Check out [popular-hook](https://huggingface.co/datasets/NEXTLab-ZJU/popular-hook) on Hugging Face!\n\n"
288
  )
289
 
290
- gr.Markdown("## Select generation options:")
291
-
292
- input_parsons_code = gr.Textbox(label="Parsons code",
293
- info="Make sure your Parsons code starts with *",
294
- lines=1,
295
- value="*"
296
- )
297
 
298
  gr.Markdown("## Select generation options:")
299
-
300
- input_first_note_duration = gr.Slider(1, 127, value=15, step=1, label="First note duration value")
301
- iinput_first_note_MIDI_pitch = gr.Slider(1, 127, value=60, step=1, label="First note MIDI pitch")
302
-
303
- run_btn = gr.Button("Generate melody", variant="primary")
 
304
 
305
  gr.Markdown("## Output results")
306
 
307
  output_midi_title = gr.Textbox(label="Output MIDI title")
 
308
  output_audio = gr.Audio(label="Output MIDI audio", format="mp3", elem_id="midi_audio")
309
  output_plot = gr.Plot(label="Output MIDI score plot")
310
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
311
 
312
- run_event = run_btn.click(Generate_Melody, [input_parsons_code,
313
- input_first_note_duration,
314
- iinput_first_note_MIDI_pitch
315
- ],
316
- [output_midi_title, output_midi, output_audio, output_plot])
317
-
318
- gr.Examples(
319
- [["*UUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUUDDDDDDDUUUUUUU", 15, 60],
320
- ["*UDDDUDDDUDRURUDUUDRDDUDDRUDUDURUDRUDUDDDUDDDRDUURUDUUDDDUDRRUUD", 15, 60],
321
- ["*DUDDDUUDDUUDDUDUDDDUUUUUDDDDUDDDUUDDUUDDUUDUDDUDDDUUDDUUDDUDUDD", 15, 60],
322
- ["*DUUDDRDDUURUDUDDDUDDDDDURDDUDRDURUURUURDDDUURDUURUDUUDURDUDUDRD", 15, 60],
323
- ["*UUUDDUUUDDDDDUDDUUDDDDUUDDUDDDDDUUUDDDDDUDDUUUDDDURDUDUUUDDUUUD", 15, 60],
324
- ["*UDUUDRUDDUDRURUURUUUUUDUDDUDDUDDUDRUDDUDRUDDDUDUUDRUDDUDRURUURU", 15, 60],
325
- ],
326
- [input_parsons_code,
327
- input_first_note_duration,
328
- iinput_first_note_MIDI_pitch
329
- ],
330
- [output_midi_title, output_midi, output_audio, output_plot],
331
- Generate_Melody,
332
- cache_examples=True,
333
- )
 
 
 
 
 
334
 
335
  app.queue().launch()
 
59
  for tv in range(-3, 3):
60
 
61
  section = str_strip(m[2])
62
+ section_tok = sections_dict.index(section)
63
 
64
  score = [t+tv if 256 < t < 512 else t for t in m[5]]
65
 
 
149
 
150
  print('Generating melody...')
151
 
152
+ # seq = [916] + [part_tok+512, mode_time(score)+532, mode_dur(score)+660, mode_pitch(score)+788]
 
 
 
 
 
 
 
 
153
 
154
+ part = 'chorus'
155
+ mode_time = 10
156
+ mode_dur = 10
157
+ mode_pitch = 66
158
 
159
+ #seq = [916] + [parts_dict.index(part)+512, mode_time+532, mode_dur+660, mode_pitch+788]
160
 
161
+ #seq = random.choice(train_data)[:128]
 
 
 
 
 
 
 
162
 
163
+ x = torch.LongTensor(seq).cuda()
164
 
165
+ with ctx:
166
+ out = model.generate(x,
167
+ 512,
168
+ temperature=0.9,
169
+ #filter_logits_fn=top_p,
170
+ #filter_kwargs={'thres': 0.96},
171
+ eos_token=917,
172
+ return_prime=True,
173
+ verbose=True)
174
+
175
+ y = out.tolist()[0]
176
+
177
+ song.extend(y)
178
 
179
  print('Done!')
180
  print('=' * 70)
 
287
  "Check out [popular-hook](https://huggingface.co/datasets/NEXTLab-ZJU/popular-hook) on Hugging Face!\n\n"
288
  )
289
 
290
+ gr.Markdown("## Select POP composition section to generate:")
291
+
292
+ input_comp_section = gr.Dropdown(sections_dict + ['random'], label="Composition section", value='intro')
 
 
 
 
293
 
294
  gr.Markdown("## Select generation options:")
295
+
296
+ input_mode_time = gr.Slider(0, 127, value=10, step=1, label="Composition mode time")
297
+ input_mode_dur = gr.Slider(0, 127, value=15, step=1, label="Composition mode dur")
298
+ input_mode_ptc = gr.Slider(0, 127, value=60, step=1, label="Composition mode pitch")
299
+
300
+ run_btn = gr.Button("Generate", variant="primary")
301
 
302
  gr.Markdown("## Output results")
303
 
304
  output_midi_title = gr.Textbox(label="Output MIDI title")
305
+ output_midi_summary = gr.Textbox(label="Output MIDI summary")
306
  output_audio = gr.Audio(label="Output MIDI audio", format="mp3", elem_id="midi_audio")
307
  output_plot = gr.Plot(label="Output MIDI score plot")
308
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
309
 
310
+ run_event = run_btn.click(Generate_POP_Section, [input_comp_section,
311
+ input_mode_time,
312
+ input_mode_dur,
313
+ input_mode_ptc
314
+ ],
315
+ [output_midi_title,
316
+ output_midi_summary,
317
+ output_midi,
318
+ output_audio,
319
+ output_plot]
320
+ )
321
+
322
+ gr.Examples([["intro", 10, 15, 60],
323
+ ],
324
+ [input_comp_section,
325
+ input_mode_time,
326
+ input_mode_dur,
327
+ input_mode_ptc
328
+ ],
329
+ [output_midi_title,
330
+ output_midi_summary,
331
+ output_midi,
332
+ output_audio,
333
+ output_plot],
334
+ Generate_POP_Section,
335
+ cache_examples=True,
336
+ )
337
 
338
  app.queue().launch()