Spaces:
Running
Running
asigalov61
commited on
Commit
•
99fabfd
1
Parent(s):
f025921
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ in_space = os.getenv("SYSTEM") == "spaces"
|
|
28 |
|
29 |
#==========================================================================================================
|
30 |
|
31 |
-
def render_midi(input_midi, render_type):
|
32 |
|
33 |
print('*' * 70)
|
34 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
@@ -92,6 +92,13 @@ def render_midi(input_midi, render_type):
|
|
92 |
|
93 |
if e[4] < 60:
|
94 |
e[4] = (e[4] % 12) + 60
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
print('Done processing!')
|
97 |
print('=' * 70)
|
@@ -154,7 +161,7 @@ def render_midi(input_midi, render_type):
|
|
154 |
output_midi_summary = str(meta_data)
|
155 |
output_midi = str(new_fn)
|
156 |
output_audio = (16000, audio)
|
157 |
-
output_plot = TMIDIX.plot_ms_SONG(
|
158 |
|
159 |
print('Output MIDI file name:', output_midi)
|
160 |
print('Output MIDI title:', output_midi_title)
|
@@ -197,20 +204,24 @@ if __name__ == "__main__":
|
|
197 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Transform and render any MIDI</h1>")
|
198 |
|
199 |
gr.Markdown("![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Advanced-MIDI-Renderer&style=flat)\n\n"
|
200 |
-
"
|
201 |
-
"Please see [
|
202 |
-
"[Open In Colab]"
|
203 |
-
"(https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Los_Angeles_MIDI_Dataset_Search_and_Explore.ipynb)"
|
204 |
-
" for all features\n\n"
|
205 |
)
|
|
|
206 |
gr.Markdown("## Upload your MIDI")
|
207 |
|
208 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"], type="filepath")
|
209 |
|
210 |
-
gr.Markdown("## Select desired render
|
211 |
|
212 |
render_type = gr.Radio(["Render as-is", "Extract melody", "Transform"], label="Render type", value="Render as-is")
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
submit = gr.Button()
|
215 |
|
216 |
gr.Markdown("## Render results")
|
@@ -222,7 +233,7 @@ if __name__ == "__main__":
|
|
222 |
output_plot = gr.Plot(label="Output MIDI score plot")
|
223 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
224 |
|
225 |
-
run_event = submit.click(render_midi, [input_midi, render_type],
|
226 |
[output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
227 |
|
228 |
app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
|
|
|
28 |
|
29 |
#==========================================================================================================
|
30 |
|
31 |
+
def render_midi(input_midi, render_type, soundfont_bank, melody_patch):
|
32 |
|
33 |
print('*' * 70)
|
34 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
|
|
92 |
|
93 |
if e[4] < 60:
|
94 |
e[4] = (e[4] % 12) + 60
|
95 |
+
|
96 |
+
elif render_type == "Transform":
|
97 |
+
output_score = copy.deepcopy(escore)
|
98 |
+
|
99 |
+
for e in output_score:
|
100 |
+
if e[3] != 9:
|
101 |
+
e[4] = 127 - e[4]
|
102 |
|
103 |
print('Done processing!')
|
104 |
print('=' * 70)
|
|
|
161 |
output_midi_summary = str(meta_data)
|
162 |
output_midi = str(new_fn)
|
163 |
output_audio = (16000, audio)
|
164 |
+
output_plot = TMIDIX.plot_ms_SONG(output_score, plot_title=output_midi)
|
165 |
|
166 |
print('Output MIDI file name:', output_midi)
|
167 |
print('Output MIDI title:', output_midi_title)
|
|
|
204 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Transform and render any MIDI</h1>")
|
205 |
|
206 |
gr.Markdown("![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Advanced-MIDI-Renderer&style=flat)\n\n"
|
207 |
+
"This is a demo for tegridy-tools\n\n"
|
208 |
+
"Please see [tegridy-tools](https://github.com/asigalov61/tegridy-tools) GitHub repo for more information\n\n"
|
|
|
|
|
|
|
209 |
)
|
210 |
+
|
211 |
gr.Markdown("## Upload your MIDI")
|
212 |
|
213 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"], type="filepath")
|
214 |
|
215 |
+
gr.Markdown("## Select desired render type")
|
216 |
|
217 |
render_type = gr.Radio(["Render as-is", "Extract melody", "Transform"], label="Render type", value="Render as-is")
|
218 |
|
219 |
+
gr.Markdown("## Select desired render options")
|
220 |
+
|
221 |
+
soundfont_bank = gr.Radio(["General MIDI", "Nice strings plus orchestra", "Real choir"], label="SoundFont bank", value="General MIDI")
|
222 |
+
|
223 |
+
melody_patch = gr.Slider(0, 127, value=40, label="Melody MIDI Patch")
|
224 |
+
|
225 |
submit = gr.Button()
|
226 |
|
227 |
gr.Markdown("## Render results")
|
|
|
233 |
output_plot = gr.Plot(label="Output MIDI score plot")
|
234 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
235 |
|
236 |
+
run_event = submit.click(render_midi, [input_midi, render_type, soundfont_bank, melody_patch],
|
237 |
[output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
238 |
|
239 |
app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
|