skytnt commited on
Commit
3fe9868
1 Parent(s): 0ede4e4

add asigalov61/Music-Llama-Medium

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -183,8 +183,8 @@ def run(model_name, tab, mid_seq, instruments, drum_kit, bpm, mid, midi_events,
183
  yield mid_seq, None, None, seed, send_msgs(init_msgs)
184
  t = time.time() + 1
185
  midi_generator = generate(model, mid, max_len=max_len, temp=temp, top_p=top_p, top_k=top_k,
186
- disable_patch_change=disable_patch_change, disable_control_change=not allow_cc,
187
- disable_channels=disable_channels, generator=generator)
188
  events = []
189
  for i, token_seq in enumerate(midi_generator):
190
  token_seq = token_seq.tolist()
@@ -192,7 +192,8 @@ def run(model_name, tab, mid_seq, instruments, drum_kit, bpm, mid, midi_events,
192
  events.append(tokenizer.tokens2event(token_seq))
193
  ct = time.time()
194
  if ct - t > 0.5:
195
- yield mid_seq, None, None, seed, send_msgs([create_msg("visualizer_append", events), create_msg("progress", [i + 1, gen_events])])
 
196
  t = ct
197
  events = []
198
 
@@ -247,6 +248,7 @@ def hf_hub_download_retry(repo_id, filename):
247
  if err:
248
  raise err
249
 
 
250
  def get_tokenizer(config_name):
251
  tv, size = config_name.split("-")
252
  tv = tv[1:]
@@ -261,6 +263,7 @@ def get_tokenizer(config_name):
261
  tokenizer.set_optimise_midi(o)
262
  return tokenizer
263
 
 
264
  number2drum_kits = {-1: "None", 0: "Standard", 8: "Room", 16: "Power", 24: "Electric", 25: "TR-808", 32: "Jazz",
265
  40: "Blush", 48: "Orchestra"}
266
  patch2number = {v: k for k, v in MIDI.Number2patch.items()}
@@ -273,10 +276,11 @@ if __name__ == "__main__":
273
  parser.add_argument("--max-gen", type=int, default=1024, help="max")
274
  opt = parser.parse_args()
275
  soundfont_path = hf_hub_download_retry(repo_id="skytnt/midi-model", filename="soundfont.sf2")
276
- models_info = {"generic pretrain model (tv2o-large)": ["asigalov61/Music-Llama", "", "tv2o-large"],
277
- "generic pretrain model (tv1-medium)": ["skytnt/midi-model", "", "tv1-medium"],
278
- "j-pop finetune model (tv1-medium)": ["skytnt/midi-model-ft", "jpop/", "tv1-medium"],
279
- "touhou finetune model (tv1-medium)": ["skytnt/midi-model-ft", "touhou/", "tv1-medium"],
 
280
  }
281
  models = {}
282
  providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
@@ -318,8 +322,8 @@ if __name__ == "__main__":
318
  input_drum_kit = gr.Dropdown(label="🥁drum kit", choices=list(drum_kits2number.keys()), type="value",
319
  value="None")
320
  input_bpm = gr.Slider(label="BPM (beats per minute, auto if 0)", minimum=0, maximum=255,
321
- step=1,
322
- value=0)
323
  example1 = gr.Examples([
324
  [[], "None"],
325
  [["Acoustic Grand"], "None"],
@@ -340,8 +344,10 @@ if __name__ == "__main__":
340
  step=1,
341
  value=128)
342
  input_reduce_cc_st = gr.Checkbox(label="reduce control_change and set_tempo events", value=True)
343
- input_remap_track_channel = gr.Checkbox(label="remap tracks and channels so each track has only one channel and in order", value=True)
344
- input_add_default_instr = gr.Checkbox(label="add a default instrument to channels that don't have an instrument", value=True)
 
 
345
  input_remove_empty_channels = gr.Checkbox(label="remove channels without notes", value=False)
346
  example2 = gr.Examples([[file, 128] for file in glob.glob("example/*.mid")],
347
  [input_midi, input_midi_events])
@@ -375,7 +381,7 @@ if __name__ == "__main__":
375
  input_top_k, input_allow_cc],
376
  [output_midi_seq, output_midi, output_audio, input_seed, js_msg],
377
  concurrency_limit=3)
378
- stop_btn.click(cancel_run, [input_model,output_midi_seq],
379
  [output_midi, output_audio, js_msg],
380
  cancels=run_event, queue=False)
381
- app.launch(server_port=opt.port, share=opt.share, inbrowser=True)
 
183
  yield mid_seq, None, None, seed, send_msgs(init_msgs)
184
  t = time.time() + 1
185
  midi_generator = generate(model, mid, max_len=max_len, temp=temp, top_p=top_p, top_k=top_k,
186
+ disable_patch_change=disable_patch_change, disable_control_change=not allow_cc,
187
+ disable_channels=disable_channels, generator=generator)
188
  events = []
189
  for i, token_seq in enumerate(midi_generator):
190
  token_seq = token_seq.tolist()
 
192
  events.append(tokenizer.tokens2event(token_seq))
193
  ct = time.time()
194
  if ct - t > 0.5:
195
+ yield mid_seq, None, None, seed, send_msgs(
196
+ [create_msg("visualizer_append", events), create_msg("progress", [i + 1, gen_events])])
197
  t = ct
198
  events = []
199
 
 
248
  if err:
249
  raise err
250
 
251
+
252
  def get_tokenizer(config_name):
253
  tv, size = config_name.split("-")
254
  tv = tv[1:]
 
263
  tokenizer.set_optimise_midi(o)
264
  return tokenizer
265
 
266
+
267
  number2drum_kits = {-1: "None", 0: "Standard", 8: "Room", 16: "Power", 24: "Electric", 25: "TR-808", 32: "Jazz",
268
  40: "Blush", 48: "Orchestra"}
269
  patch2number = {v: k for k, v in MIDI.Number2patch.items()}
 
276
  parser.add_argument("--max-gen", type=int, default=1024, help="max")
277
  opt = parser.parse_args()
278
  soundfont_path = hf_hub_download_retry(repo_id="skytnt/midi-model", filename="soundfont.sf2")
279
+ models_info = {"generic pretrain model (tv2o-large) by asigalov61": ["asigalov61/Music-Llama", "", "tv2o-large"],
280
+ "generic pretrain model (tv2o-medium) by asigalov61": ["asigalov61/Music-Llama-Medium", "", "tv2o-medium"],
281
+ "generic pretrain model (tv1-medium) by skytnt": ["skytnt/midi-model", "", "tv1-medium"],
282
+ "j-pop finetune model (tv1-medium) by skytnt": ["skytnt/midi-model-ft", "jpop/", "tv1-medium"],
283
+ "touhou finetune model (tv1-medium) by skytnt": ["skytnt/midi-model-ft", "touhou/", "tv1-medium"],
284
  }
285
  models = {}
286
  providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
 
322
  input_drum_kit = gr.Dropdown(label="🥁drum kit", choices=list(drum_kits2number.keys()), type="value",
323
  value="None")
324
  input_bpm = gr.Slider(label="BPM (beats per minute, auto if 0)", minimum=0, maximum=255,
325
+ step=1,
326
+ value=0)
327
  example1 = gr.Examples([
328
  [[], "None"],
329
  [["Acoustic Grand"], "None"],
 
344
  step=1,
345
  value=128)
346
  input_reduce_cc_st = gr.Checkbox(label="reduce control_change and set_tempo events", value=True)
347
+ input_remap_track_channel = gr.Checkbox(
348
+ label="remap tracks and channels so each track has only one channel and in order", value=True)
349
+ input_add_default_instr = gr.Checkbox(
350
+ label="add a default instrument to channels that don't have an instrument", value=True)
351
  input_remove_empty_channels = gr.Checkbox(label="remove channels without notes", value=False)
352
  example2 = gr.Examples([[file, 128] for file in glob.glob("example/*.mid")],
353
  [input_midi, input_midi_events])
 
381
  input_top_k, input_allow_cc],
382
  [output_midi_seq, output_midi, output_audio, input_seed, js_msg],
383
  concurrency_limit=3)
384
+ stop_btn.click(cancel_run, [input_model, output_midi_seq],
385
  [output_midi, output_audio, js_msg],
386
  cancels=run_event, queue=False)
387
+ app.launch(server_port=opt.port, share=opt.share, inbrowser=True)