Spaces:
Running
on
Zero
Running
on
Zero
add optimise midi
Browse files- app.py +6 -4
- requirements.txt +1 -1
app.py
CHANGED
@@ -121,7 +121,7 @@ def send_msgs(msgs):
|
|
121 |
return json.dumps(msgs)
|
122 |
|
123 |
|
124 |
-
def run(model_name, tab, instruments, drum_kit, bpm, mid, midi_events, seed, seed_rand,
|
125 |
gen_events, temp, top_p, top_k, allow_cc):
|
126 |
mid_seq = []
|
127 |
bpm = int(bpm)
|
@@ -153,7 +153,8 @@ def run(model_name, tab, instruments, drum_kit, bpm, mid, midi_events, seed, see
|
|
153 |
disable_patch_change = True
|
154 |
disable_channels = [i for i in range(16) if i not in patches]
|
155 |
elif mid is not None:
|
156 |
-
|
|
|
157 |
mid = np.asarray(mid, dtype=np.int64)
|
158 |
mid = mid[:int(midi_events)]
|
159 |
for token_seq in mid:
|
@@ -305,6 +306,7 @@ if __name__ == "__main__":
|
|
305 |
input_midi_events = gr.Slider(label="use first n midi events as prompt", minimum=1, maximum=512,
|
306 |
step=1,
|
307 |
value=128)
|
|
|
308 |
example2 = gr.Examples([[file, 128] for file in glob.glob("example/*.mid")],
|
309 |
[input_midi, input_midi_events])
|
310 |
|
@@ -328,8 +330,8 @@ if __name__ == "__main__":
|
|
328 |
output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
|
329 |
output_midi = gr.File(label="output midi", file_types=[".mid"])
|
330 |
run_event = run_btn.click(run, [input_model, tab_select, input_instruments, input_drum_kit, input_bpm,
|
331 |
-
input_midi, input_midi_events, input_seed, input_seed_rand,
|
332 |
-
input_temp, input_top_p, input_top_k, input_allow_cc],
|
333 |
[output_midi_seq, output_midi, output_audio, input_seed, js_msg],
|
334 |
concurrency_limit=3)
|
335 |
stop_btn.click(cancel_run, [output_midi_seq], [output_midi, output_audio, js_msg], cancels=run_event, queue=False)
|
|
|
121 |
return json.dumps(msgs)
|
122 |
|
123 |
|
124 |
+
def run(model_name, tab, instruments, drum_kit, bpm, mid, midi_events, midi_opt, seed, seed_rand,
|
125 |
gen_events, temp, top_p, top_k, allow_cc):
|
126 |
mid_seq = []
|
127 |
bpm = int(bpm)
|
|
|
153 |
disable_patch_change = True
|
154 |
disable_channels = [i for i in range(16) if i not in patches]
|
155 |
elif mid is not None:
|
156 |
+
eps = 4 if midi_opt else 0
|
157 |
+
mid = tokenizer.tokenize(MIDI.midi2score(mid), cc_eps=eps, tempo_eps=eps)
|
158 |
mid = np.asarray(mid, dtype=np.int64)
|
159 |
mid = mid[:int(midi_events)]
|
160 |
for token_seq in mid:
|
|
|
306 |
input_midi_events = gr.Slider(label="use first n midi events as prompt", minimum=1, maximum=512,
|
307 |
step=1,
|
308 |
value=128)
|
309 |
+
input_midi_opt = gr.Checkbox(label="optimise midi", value=True)
|
310 |
example2 = gr.Examples([[file, 128] for file in glob.glob("example/*.mid")],
|
311 |
[input_midi, input_midi_events])
|
312 |
|
|
|
330 |
output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
|
331 |
output_midi = gr.File(label="output midi", file_types=[".mid"])
|
332 |
run_event = run_btn.click(run, [input_model, tab_select, input_instruments, input_drum_kit, input_bpm,
|
333 |
+
input_midi, input_midi_events, input_midi_opt, input_seed, input_seed_rand,
|
334 |
+
input_gen_events, input_temp, input_top_p, input_top_k, input_allow_cc],
|
335 |
[output_midi_seq, output_midi, output_audio, input_seed, js_msg],
|
336 |
concurrency_limit=3)
|
337 |
stop_btn.click(cancel_run, [output_midi_seq], [output_midi, output_audio, js_msg], cancels=run_event, queue=False)
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
Pillow
|
2 |
numpy
|
3 |
onnxruntime-gpu
|
4 |
-
gradio==4.
|
5 |
pyfluidsynth
|
|
|
1 |
Pillow
|
2 |
numpy
|
3 |
onnxruntime-gpu
|
4 |
+
gradio==4.43.0
|
5 |
pyfluidsynth
|