Commit
·
d0fbd88
1
Parent(s):
4f21aca
feat: add gradio interface
Browse files
Dockerfile
CHANGED
|
@@ -88,5 +88,6 @@ ENV PYTHONPATH=/app/python_lib
|
|
| 88 |
RUN rm -rf /build
|
| 89 |
RUN python3 -c "import midigpt; print('✅ midigpt built and importable')"
|
| 90 |
|
|
|
|
| 91 |
|
| 92 |
CMD ["/bin/bash"]
|
|
|
|
| 88 |
RUN rm -rf /build
|
| 89 |
RUN python3 -c "import midigpt; print('✅ midigpt built and importable')"
|
| 90 |
|
| 91 |
+
RUN python3 -m pip install --no-cache-dir gradio
|
| 92 |
|
| 93 |
CMD ["/bin/bash"]
|
python_scripts_for_testing/gradio_app.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Add the path to midigpt
|
| 7 |
+
sys.path.append(os.path.dirname(os.getcwd()) + "/python_lib")
|
| 8 |
+
import midigpt
|
| 9 |
+
|
| 10 |
+
def generate_midi(midi_input, ckpt, out, temperature, instrument, density, track_type, polyphony_hard_limit, shuffle, verbose, max_steps, batch_size, percentage, model_dim, mask_top_k, sampling_seed, autoregressive):
|
| 11 |
+
# Save uploaded MIDI file to a temp path
|
| 12 |
+
midi_input_path = midi_input.name
|
| 13 |
+
if out:
|
| 14 |
+
midi_dest = out
|
| 15 |
+
else:
|
| 16 |
+
midi_dest = os.path.join(os.path.split(midi_input_path)[0], 'midigpt_gen.mid')
|
| 17 |
+
e = midigpt.ExpressiveEncoder()
|
| 18 |
+
midi_json_input = json.loads(e.midi_to_json(midi_input_path))
|
| 19 |
+
valid_status = {'tracks': [
|
| 20 |
+
{
|
| 21 |
+
'track_id': 0,
|
| 22 |
+
'temperature': temperature,
|
| 23 |
+
'instrument': instrument,
|
| 24 |
+
'density': density,
|
| 25 |
+
'track_type': track_type,
|
| 26 |
+
'ignore': False,
|
| 27 |
+
'selected_bars': [False, False, True, False],
|
| 28 |
+
'min_polyphony_q': 'POLYPHONY_ANY',
|
| 29 |
+
'max_polyphony_q': 'POLYPHONY_ANY',
|
| 30 |
+
'autoregressive': autoregressive,
|
| 31 |
+
'polyphony_hard_limit': polyphony_hard_limit
|
| 32 |
+
}
|
| 33 |
+
]}
|
| 34 |
+
parami = {
|
| 35 |
+
'tracks_per_step': 1,
|
| 36 |
+
'bars_per_step': 1,
|
| 37 |
+
'model_dim': model_dim,
|
| 38 |
+
'percentage': percentage,
|
| 39 |
+
'batch_size': batch_size,
|
| 40 |
+
'temperature': temperature,
|
| 41 |
+
'max_steps': max_steps,
|
| 42 |
+
'polyphony_hard_limit': polyphony_hard_limit,
|
| 43 |
+
'shuffle': shuffle,
|
| 44 |
+
'verbose': verbose,
|
| 45 |
+
'ckpt': ckpt,
|
| 46 |
+
'sampling_seed': sampling_seed,
|
| 47 |
+
'mask_top_k': mask_top_k
|
| 48 |
+
}
|
| 49 |
+
piece = json.dumps(midi_json_input)
|
| 50 |
+
status = json.dumps(valid_status)
|
| 51 |
+
param = json.dumps(parami)
|
| 52 |
+
callbacks = midigpt.CallbackManager()
|
| 53 |
+
max_attempts = 3
|
| 54 |
+
midi_str = midigpt.sample_multi_step(piece, status, param, max_attempts, callbacks)[0]
|
| 55 |
+
e = midigpt.ExpressiveEncoder()
|
| 56 |
+
e.json_to_midi(midi_str, midi_dest)
|
| 57 |
+
return midi_dest
|
| 58 |
+
|
| 59 |
+
def main():
|
| 60 |
+
iface = gr.Interface(
|
| 61 |
+
fn=generate_midi,
|
| 62 |
+
inputs=[
|
| 63 |
+
gr.File(label="Input MIDI File"),
|
| 64 |
+
gr.Textbox(label="Checkpoint Path", value="../models/EXPRESSIVE_ENCODER_RES_1920_12_GIGAMIDI_CKPT_150K.pt"),
|
| 65 |
+
gr.Textbox(label="Output MIDI Path (optional)", value=""),
|
| 66 |
+
gr.Slider(0.0, 2.0, value=0.5, label="Temperature"),
|
| 67 |
+
gr.Textbox(label="Instrument", value="acoustic_grand_piano"),
|
| 68 |
+
gr.Slider(1, 20, value=10, step=1, label="Density"),
|
| 69 |
+
gr.Slider(0, 20, value=10, step=1, label="Track Type"),
|
| 70 |
+
gr.Slider(1, 16, value=9, step=1, label="Polyphony Hard Limit"),
|
| 71 |
+
gr.Checkbox(label="Shuffle", value=True),
|
| 72 |
+
gr.Checkbox(label="Verbose", value=True),
|
| 73 |
+
gr.Slider(1, 1000, value=200, step=1, label="Max Steps"),
|
| 74 |
+
gr.Slider(1, 32, value=1, step=1, label="Batch Size"),
|
| 75 |
+
gr.Slider(1, 100, value=100, step=1, label="Percentage"),
|
| 76 |
+
gr.Slider(1, 32, value=4, step=1, label="Model Dim"),
|
| 77 |
+
gr.Slider(0, 100, value=0, step=1, label="Mask Top K"),
|
| 78 |
+
gr.Number(label="Sampling Seed", value=-1),
|
| 79 |
+
gr.Checkbox(label="Autoregressive", value=False)
|
| 80 |
+
],
|
| 81 |
+
outputs=gr.File(label="Generated MIDI File"),
|
| 82 |
+
title="MIDI-GPT Generator",
|
| 83 |
+
description="Generate expressive MIDI using MIDI-GPT."
|
| 84 |
+
)
|
| 85 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
| 86 |
+
|
| 87 |
+
if __name__ == "__main__":
|
| 88 |
+
main()
|
python_scripts_for_testing/prova.mid
ADDED
|
Binary file (582 Bytes). View file
|
|
|