new layout / download possible
Browse files- playground.py +59 -84
playground.py
CHANGED
@@ -48,9 +48,13 @@ def generator(
|
|
48 |
add_bars=False,
|
49 |
add_bar_count=1,
|
50 |
):
|
51 |
-
|
52 |
genesis = GenerateMidiText(model, tokenizer, piece_by_track)
|
53 |
-
track = {
|
|
|
|
|
|
|
|
|
|
|
54 |
inst = next(
|
55 |
(
|
56 |
inst
|
@@ -61,7 +65,7 @@ def generator(
|
|
61 |
)["family_number"]
|
62 |
|
63 |
inst_index = -1 # default to last generated
|
64 |
-
if
|
65 |
for index, instrum in enumerate(state):
|
66 |
if instrum["label"] == track["label"]:
|
67 |
inst_index = index # changing if exists
|
@@ -102,7 +106,7 @@ def generator(
|
|
102 |
piano_roll = plot_piano_roll(mixed_inst_midi)
|
103 |
track["text"] = inst_text
|
104 |
state.append(track)
|
105 |
-
|
106 |
return (
|
107 |
inst_text,
|
108 |
(44100, inst_audio),
|
@@ -111,6 +115,7 @@ def generator(
|
|
111 |
(44100, mixed_audio),
|
112 |
regenerate,
|
113 |
genesis.piece_by_track,
|
|
|
114 |
)
|
115 |
|
116 |
|
@@ -121,56 +126,36 @@ def generated_text_from_state(state):
|
|
121 |
return generated_text_from_state
|
122 |
|
123 |
|
124 |
-
def
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
value=default_inst,
|
151 |
-
label="Instrument",
|
152 |
-
)
|
153 |
-
temp = gr.Dropdown(
|
154 |
-
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1],
|
155 |
-
value=0.7,
|
156 |
-
label="Creativity",
|
157 |
-
)
|
158 |
-
density = gr.Dropdown([1, 2, 3], value=3, label="Note Density")
|
159 |
-
|
160 |
-
with gr.Column(scale=3):
|
161 |
-
output_txt = gr.Textbox(
|
162 |
-
label="output", lines=10, max_lines=10, show_label=False
|
163 |
-
)
|
164 |
-
with gr.Column(scale=1, min_width=100):
|
165 |
-
inst_audio = gr.Audio(label="TRACK Audio", show_label=True)
|
166 |
-
regenerate = gr.Checkbox(value=False, label="Regenerate", visible=False)
|
167 |
-
# add_bars = gr.Checkbox(value=False, label="Add Bars")
|
168 |
-
# add_bar_count = gr.Dropdown([1, 2, 4, 8], value=1, label="Add Bars")
|
169 |
-
gen_btn = gr.Button("Generate")
|
170 |
|
171 |
gen_btn.click(
|
172 |
fn=generator,
|
173 |
-
inputs=[
|
174 |
outputs=[
|
175 |
output_txt,
|
176 |
inst_audio,
|
@@ -179,6 +164,7 @@ def instrument_row(default_inst, row_id):
|
|
179 |
mixed_audio,
|
180 |
regenerate,
|
181 |
piece_by_track,
|
|
|
182 |
],
|
183 |
)
|
184 |
|
@@ -188,46 +174,35 @@ with gr.Blocks() as demo:
|
|
188 |
state = gr.State([])
|
189 |
title = gr.Markdown(
|
190 |
""" # Demo-App of The-Jam-Machine
|
191 |
-
A Generative AI trained on text transcription of MIDI music """
|
192 |
)
|
193 |
|
194 |
-
track1_md = gr.Markdown(""" ## Mixed Audio and Piano Roll """)
|
195 |
-
mixed_audio = gr.Audio(label="Mixed Audio")
|
196 |
-
piano_roll = gr.Plot(label="Piano Roll", show_label=False)
|
197 |
description = gr.Markdown(
|
198 |
"""
|
199 |
-
For each **TRACK**, choose your **instrument** along with **creativity** (temperature) and **note density**.
|
200 |
-
|
201 |
-
If you don't like the track, hit the generate button to regenerate it
|
|
|
|
|
202 |
"""
|
203 |
)
|
204 |
-
track1_md = gr.Markdown(""" ## TRACK 1 """)
|
205 |
-
instrument_row("Drums", 0)
|
206 |
-
track1_md = gr.Markdown(""" ## TRACK 2 """)
|
207 |
-
instrument_row("Synth Bass 1", 1)
|
208 |
-
track1_md = gr.Markdown(""" ## TRACK 3 """)
|
209 |
-
instrument_row("Synth Lead Square", 2)
|
210 |
-
# instrument_row("Piano")
|
211 |
-
#
|
212 |
-
# save = gr.Markdown(""" ## SAVE AS MIDI file - enter a valid path """)
|
213 |
-
# with gr.Row():
|
214 |
-
# # with gr.Column(scale=1, min_width=100):
|
215 |
-
# saving_path = gr.Textbox(
|
216 |
-
# value="/Users/ChatGPT/Downloads/TheJamMachine/",
|
217 |
-
# show_label=False,
|
218 |
-
# label="Saving Path",
|
219 |
-
# interactive=True,
|
220 |
-
# )
|
221 |
-
# # with gr.Column(scale=1, min_width=100):
|
222 |
-
# gen_btn = gr.Button("Save MIDI")
|
223 |
-
# # with gr.Column(scale=1, min_width=100):
|
224 |
-
# status = gr.Textbox(show_label=False)
|
225 |
-
|
226 |
-
# gen_btn.click(fn=save_midi_to_folder, inputs=[state, saving_path], outputs=status)
|
227 |
-
|
228 |
-
|
229 |
-
demo.launch(debug=True)
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
"""
|
232 |
TODO: add improvise button
|
233 |
TODO: cleanup input output of generator
|
|
|
48 |
add_bars=False,
|
49 |
add_bar_count=1,
|
50 |
):
|
|
|
51 |
genesis = GenerateMidiText(model, tokenizer, piece_by_track)
|
52 |
+
track = {
|
53 |
+
"label": label,
|
54 |
+
"instrument": instrument,
|
55 |
+
"temperature": temp,
|
56 |
+
"density": density,
|
57 |
+
}
|
58 |
inst = next(
|
59 |
(
|
60 |
inst
|
|
|
65 |
)["family_number"]
|
66 |
|
67 |
inst_index = -1 # default to last generated
|
68 |
+
if piece_by_track != []:
|
69 |
for index, instrum in enumerate(state):
|
70 |
if instrum["label"] == track["label"]:
|
71 |
inst_index = index # changing if exists
|
|
|
106 |
piano_roll = plot_piano_roll(mixed_inst_midi)
|
107 |
track["text"] = inst_text
|
108 |
state.append(track)
|
109 |
+
output_file = "./mixed.mid"
|
110 |
return (
|
111 |
inst_text,
|
112 |
(44100, inst_audio),
|
|
|
115 |
(44100, mixed_audio),
|
116 |
regenerate,
|
117 |
genesis.piece_by_track,
|
118 |
+
output_file,
|
119 |
)
|
120 |
|
121 |
|
|
|
126 |
return generated_text_from_state
|
127 |
|
128 |
|
129 |
+
def instrument_col(default_inst, col_id):
|
130 |
+
inst_label = gr.Variable(col_id)
|
131 |
+
with gr.Column(scale=1, min_width=100):
|
132 |
+
track_md = gr.Markdown(f"""## TRACK {col_id+1}""")
|
133 |
+
inst = gr.Dropdown(
|
134 |
+
sorted([inst["transfer_to"] for inst in INSTRUMENT_TRANSFER_CLASSES])
|
135 |
+
+ ["Drums"],
|
136 |
+
value=default_inst,
|
137 |
+
label="Instrument",
|
138 |
+
)
|
139 |
+
temp = gr.Dropdown(
|
140 |
+
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1],
|
141 |
+
value=0.7,
|
142 |
+
label="Creativity",
|
143 |
+
)
|
144 |
+
density = gr.Dropdown([1, 2, 3], value=3, label="Note Density")
|
145 |
+
regenerate = gr.State(
|
146 |
+
value=False
|
147 |
+
) # initial state should be to generate (not regenerate)
|
148 |
+
# add_bars = gr.Checkbox(value=False, label="Add Bars")
|
149 |
+
# add_bar_count = gr.Dropdown([1, 2, 4, 8], value=1, label="Add Bars")
|
150 |
+
gen_btn = gr.Button("Generate")
|
151 |
+
inst_audio = gr.Audio(label="TRACK Audio", show_label=True)
|
152 |
+
output_txt = gr.Textbox(
|
153 |
+
label="output", lines=10, max_lines=10, show_label=False, visible=False
|
154 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
gen_btn.click(
|
157 |
fn=generator,
|
158 |
+
inputs=[inst_label, regenerate, temp, density, inst, state, piece_by_track],
|
159 |
outputs=[
|
160 |
output_txt,
|
161 |
inst_audio,
|
|
|
164 |
mixed_audio,
|
165 |
regenerate,
|
166 |
piece_by_track,
|
167 |
+
output_file,
|
168 |
],
|
169 |
)
|
170 |
|
|
|
174 |
state = gr.State([])
|
175 |
title = gr.Markdown(
|
176 |
""" # Demo-App of The-Jam-Machine
|
177 |
+
## A Generative AI trained on text transcription of MIDI music """
|
178 |
)
|
179 |
|
|
|
|
|
|
|
180 |
description = gr.Markdown(
|
181 |
"""
|
182 |
+
For each **TRACK**, choose your **instrument** along with **creativity** (temperature) and **note density**.
|
183 |
+
Then, hit the **Generate** Button, and after a few seconds a track should have been generated.
|
184 |
+
Check the **piano roll** and listen to the TRACK! If you don't like the track, hit the generate button to regenerate it.
|
185 |
+
You can then generate more tracks and listen to the **mixed audio**! \n
|
186 |
+
Does it sound nice? Maybe a little robotic and laking some depth... Well, you can download the MIDI file and use it in the DAW of your choice to edit the instruments and add some effects of your choices!
|
187 |
"""
|
188 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
+
aud_md = gr.Markdown(f""" ## Mixed Audio, Piano Roll and MIDI Download """)
|
191 |
+
with gr.Row(equal_height=True, variant="default"):
|
192 |
+
mixed_audio = gr.Audio(label="Mixed Audio", show_label=False)
|
193 |
+
output_file = gr.File(
|
194 |
+
label="Download",
|
195 |
+
show_label=False,
|
196 |
+
)
|
197 |
+
with gr.Row(variant="compact"):
|
198 |
+
piano_roll = gr.Plot(label="Piano Roll", show_label=False)
|
199 |
+
|
200 |
+
with gr.Row(variant="default"):
|
201 |
+
instrument_col("Drums", 0)
|
202 |
+
instrument_col("Synth Bass 1", 1)
|
203 |
+
instrument_col("Synth Lead Square", 2)
|
204 |
+
|
205 |
+
demo.launch(debug=True, server_name="0.0.0.0", share=False)
|
206 |
"""
|
207 |
TODO: add improvise button
|
208 |
TODO: cleanup input output of generator
|