Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,8 @@ print('Loading main MIDI Remixer modules...')
|
|
| 25 |
|
| 26 |
import TMIDIX
|
| 27 |
|
|
|
|
|
|
|
| 28 |
from midi_to_colab_audio import midi_to_colab_audio
|
| 29 |
|
| 30 |
from huggingface_hub import hf_hub_download
|
|
@@ -48,8 +50,25 @@ SOUDFONT_PATH = 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2'
|
|
| 48 |
|
| 49 |
#==================================================================================
|
| 50 |
|
|
|
|
|
|
|
| 51 |
midi_cores_dataset = load_dataset("asigalov61/MIDI-Cores")
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
#==================================================================================
|
| 54 |
|
| 55 |
def load_midi(midi_file):
|
|
@@ -92,10 +111,31 @@ def load_midi(midi_file):
|
|
| 92 |
|
| 93 |
#==================================================================================
|
| 94 |
|
| 95 |
-
def
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
#===============================================================================
|
| 101 |
|
|
@@ -334,7 +374,7 @@ with gr.Blocks() as demo:
|
|
| 334 |
output_plot = gr.Plot(label="MIDI score plot")
|
| 335 |
output_midi = gr.File(label="MIDI file", file_types=[".mid"])
|
| 336 |
|
| 337 |
-
mix_btn.click(
|
| 338 |
[input_midi,
|
| 339 |
chords_chunks_len,
|
| 340 |
num_mix_chunks
|
|
|
|
| 25 |
|
| 26 |
import TMIDIX
|
| 27 |
|
| 28 |
+
import numpy as np
|
| 29 |
+
|
| 30 |
from midi_to_colab_audio import midi_to_colab_audio
|
| 31 |
|
| 32 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 50 |
|
| 51 |
#==================================================================================
|
| 52 |
|
| 53 |
+
print('=' * 70)
|
| 54 |
+
|
| 55 |
midi_cores_dataset = load_dataset("asigalov61/MIDI-Cores")
|
| 56 |
|
| 57 |
+
print('=' * 70)
|
| 58 |
+
print('Prepping MIDI cores data...')
|
| 59 |
+
print('=' * 70)
|
| 60 |
+
|
| 61 |
+
all_core_chords = []
|
| 62 |
+
|
| 63 |
+
for entry in tqdm.tqdm(midi_cores_dataset['train']):
|
| 64 |
+
all_core_chords.append(entry['core_chords'])
|
| 65 |
+
|
| 66 |
+
all_core_chords = np.array(all_core_chords)
|
| 67 |
+
|
| 68 |
+
print('=' * 70)
|
| 69 |
+
print('Done!')
|
| 70 |
+
print('=' * 70)
|
| 71 |
+
|
| 72 |
#==================================================================================
|
| 73 |
|
| 74 |
def load_midi(midi_file):
|
|
|
|
| 111 |
|
| 112 |
#==================================================================================
|
| 113 |
|
| 114 |
+
def find_max_exact_match(src, trg):
|
| 115 |
+
"""
|
| 116 |
+
Find the row in the 2D trg array that has the maximum number of exact element matches with the 1D src array.
|
| 117 |
+
|
| 118 |
+
Parameters:
|
| 119 |
+
src (numpy.ndarray): 1D source array.
|
| 120 |
+
trg (numpy.ndarray): 2D target array.
|
| 121 |
+
|
| 122 |
+
Returns:
|
| 123 |
+
int: Index of the row in trg that has the maximum number of exact matches with src.
|
| 124 |
+
"""
|
| 125 |
+
# Compare src with each row in trg and count exact matches
|
| 126 |
+
match_counts = np.sum(trg == src, axis=1)
|
| 127 |
+
|
| 128 |
+
# Find the index of the row with the maximum number of matches
|
| 129 |
+
max_match_idx = np.argmax(match_counts)
|
| 130 |
+
|
| 131 |
+
return max_match_idx
|
| 132 |
+
|
| 133 |
+
#==================================================================================
|
| 134 |
+
|
| 135 |
+
def Match_Cores(input_midi,
|
| 136 |
+
chords_chunks_len,
|
| 137 |
+
num_mix_chunks
|
| 138 |
+
):
|
| 139 |
|
| 140 |
#===============================================================================
|
| 141 |
|
|
|
|
| 374 |
output_plot = gr.Plot(label="MIDI score plot")
|
| 375 |
output_midi = gr.File(label="MIDI file", file_types=[".mid"])
|
| 376 |
|
| 377 |
+
mix_btn.click(Match_Cores,
|
| 378 |
[input_midi,
|
| 379 |
chords_chunks_len,
|
| 380 |
num_mix_chunks
|