Spaces:
Running
Running
Commit
·
497670e
1
Parent(s):
cc38963
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,46 +24,6 @@ in_space = os.getenv("SYSTEM") == "spaces"
|
|
| 24 |
|
| 25 |
#==========================================================================================================
|
| 26 |
|
| 27 |
-
def run(midi, progress=gr.Progress()):
|
| 28 |
-
|
| 29 |
-
mid_seq = MIDI.midi2score(midi)
|
| 30 |
-
|
| 31 |
-
for m in progress.tqdm(meta_data):
|
| 32 |
-
mid_seq = m[1][17:-1]
|
| 33 |
-
mid_seq_ticks = m[1][16][1]
|
| 34 |
-
mdata = m[1][:16]
|
| 35 |
-
break
|
| 36 |
-
|
| 37 |
-
x = []
|
| 38 |
-
y = []
|
| 39 |
-
c = []
|
| 40 |
-
|
| 41 |
-
colors = ['red', 'yellow', 'green', 'cyan',
|
| 42 |
-
'blue', 'pink', 'orange', 'purple',
|
| 43 |
-
'gray', 'white', 'gold', 'silver',
|
| 44 |
-
'lightgreen', 'indigo', 'maroon', 'turquoise']
|
| 45 |
-
|
| 46 |
-
for s in [m for m in mid_seq if m[0] == 'note']:
|
| 47 |
-
x.append(s[1])
|
| 48 |
-
y.append(s[4])
|
| 49 |
-
c.append(colors[s[3]])
|
| 50 |
-
|
| 51 |
-
plt.close()
|
| 52 |
-
plt.figure(figsize=(14,5))
|
| 53 |
-
ax=plt.axes(title='MIDI Search Plot')
|
| 54 |
-
ax.set_facecolor('black')
|
| 55 |
-
|
| 56 |
-
plt.scatter(x,y, c=c)
|
| 57 |
-
plt.xlabel("Time")
|
| 58 |
-
plt.ylabel("Pitch")
|
| 59 |
-
|
| 60 |
-
with open(f"output.mid", 'wb') as f:
|
| 61 |
-
f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
|
| 62 |
-
audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
|
| 63 |
-
yield mdata, "output.mid", (44100, audio), plt
|
| 64 |
-
|
| 65 |
-
#==========================================================================================================
|
| 66 |
-
|
| 67 |
def match_midi(midi, progress=gr.Progress()):
|
| 68 |
|
| 69 |
print('=' * 70)
|
|
@@ -378,6 +338,12 @@ def match_midi(midi, progress=gr.Progress()):
|
|
| 378 |
mid_seq_ticks = md[1][16][1]
|
| 379 |
mdata = md[1][:16]
|
| 380 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
x = []
|
| 382 |
y = []
|
| 383 |
c = []
|
|
@@ -404,7 +370,7 @@ def match_midi(midi, progress=gr.Progress()):
|
|
| 404 |
with open(f"output.mid", 'wb') as f:
|
| 405 |
f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
|
| 406 |
audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
|
| 407 |
-
yield
|
| 408 |
|
| 409 |
#==========================================================================================================
|
| 410 |
|
|
@@ -438,10 +404,10 @@ if __name__ == "__main__":
|
|
| 438 |
|
| 439 |
input_midi = gr.File(label="input midi", file_types=[".midi", ".mid"], type="binary")
|
| 440 |
|
|
|
|
| 441 |
output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
|
| 442 |
output_midi = gr.File(label="output midi", file_types=[".mid"])
|
| 443 |
output_midi_seq = gr.Textbox(label="output midi metadata")
|
| 444 |
-
output_plot = gr.Plot(label="output midi plot")
|
| 445 |
|
| 446 |
run_event = input_midi.upload(match_midi, [input_midi],
|
| 447 |
[output_midi_seq, output_midi, output_audio, output_plot])
|
|
|
|
| 24 |
|
| 25 |
#==========================================================================================================
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def match_midi(midi, progress=gr.Progress()):
|
| 28 |
|
| 29 |
print('=' * 70)
|
|
|
|
| 338 |
mid_seq_ticks = md[1][16][1]
|
| 339 |
mdata = md[1][:16]
|
| 340 |
|
| 341 |
+
txt_mdata = ''
|
| 342 |
+
|
| 343 |
+
for m in mdata:
|
| 344 |
+
txt_mdata += str(m)
|
| 345 |
+
txt_mdata += chr(10)
|
| 346 |
+
|
| 347 |
x = []
|
| 348 |
y = []
|
| 349 |
c = []
|
|
|
|
| 370 |
with open(f"output.mid", 'wb') as f:
|
| 371 |
f.write(MIDI.score2midi([mid_seq_ticks, mid_seq]))
|
| 372 |
audio = synthesis(MIDI.score2opus([mid_seq_ticks, mid_seq]), soundfont_path)
|
| 373 |
+
yield txt_mdata, "output.mid", (44100, audio), plt
|
| 374 |
|
| 375 |
#==========================================================================================================
|
| 376 |
|
|
|
|
| 404 |
|
| 405 |
input_midi = gr.File(label="input midi", file_types=[".midi", ".mid"], type="binary")
|
| 406 |
|
| 407 |
+
output_plot = gr.Plot(label="output midi plot")
|
| 408 |
output_audio = gr.Audio(label="output audio", format="mp3", elem_id="midi_audio")
|
| 409 |
output_midi = gr.File(label="output midi", file_types=[".mid"])
|
| 410 |
output_midi_seq = gr.Textbox(label="output midi metadata")
|
|
|
|
| 411 |
|
| 412 |
run_event = input_midi.upload(match_midi, [input_midi],
|
| 413 |
[output_midi_seq, output_midi, output_audio, output_plot])
|