skytnt commited on
Commit
c0d7f61
1 Parent(s): 8fdb145

queue and duration

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -95,7 +95,16 @@ def create_msg(name, data):
95
  def send_msgs(msgs):
96
  return json.dumps(msgs)
97
 
98
- @spaces.GPU()
 
 
 
 
 
 
 
 
 
99
  def run(model_name, tab, mid_seq, continuation_state, instruments, drum_kit, bpm, time_sig, key_sig, mid, midi_events,
100
  reduce_cc_st, remap_track_channel, add_default_instr, remove_empty_channels, seed, seed_rand,
101
  gen_events, temp, top_p, top_k, allow_cc):
@@ -410,10 +419,10 @@ if __name__ == "__main__":
410
  input_top_k, input_allow_cc],
411
  [output_midi_seq, output_continuation_state,
412
  output_midi, output_audio, input_seed, js_msg],
413
- concurrency_limit=3)
414
  stop_btn.click(cancel_run, [input_model, output_midi_seq],
415
  [output_midi, output_audio, js_msg],
416
  cancels=run_event, queue=False)
417
  undo_btn.click(undo_continuation, [input_model, output_midi_seq, output_continuation_state],
418
  [output_midi_seq, output_continuation_state, js_msg], queue=False)
419
- app.launch(server_port=opt.port, share=opt.share, inbrowser=True)
 
95
  def send_msgs(msgs):
96
  return json.dumps(msgs)
97
 
98
+ def get_duration(model_name, tab, mid_seq, continuation_state, instruments, drum_kit, bpm, time_sig,
99
+ key_sig, mid, midi_events, reduce_cc_st, remap_track_channel, add_default_instr,
100
+ remove_empty_channels, seed, seed_rand, gen_events, temp, top_p, top_k, allow_cc):
101
+ if "large" in model_name:
102
+ return gen_events // 10
103
+ else:
104
+ return gen_events // 20
105
+
106
+
107
+ @spaces.GPU(duration=get_duration)
108
  def run(model_name, tab, mid_seq, continuation_state, instruments, drum_kit, bpm, time_sig, key_sig, mid, midi_events,
109
  reduce_cc_st, remap_track_channel, add_default_instr, remove_empty_channels, seed, seed_rand,
110
  gen_events, temp, top_p, top_k, allow_cc):
 
419
  input_top_k, input_allow_cc],
420
  [output_midi_seq, output_continuation_state,
421
  output_midi, output_audio, input_seed, js_msg],
422
+ concurrency_limit=10)
423
  stop_btn.click(cancel_run, [input_model, output_midi_seq],
424
  [output_midi, output_audio, js_msg],
425
  cancels=run_event, queue=False)
426
  undo_btn.click(undo_continuation, [input_model, output_midi_seq, output_continuation_state],
427
  [output_midi_seq, output_continuation_state, js_msg], queue=False)
428
+ app.queue().launch(server_port=opt.port, share=opt.share, inbrowser=True)