asigalov61 commited on
Commit
573ea3b
·
verified ·
1 Parent(s): d052125

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -97,7 +97,9 @@ def find_max_exact_match(src, trg):
97
  trg (numpy.ndarray): 2D target array.
98
 
99
  Returns:
100
- int: Index of the row in trg that has the maximum number of exact matches with src.
 
 
101
  """
102
  # Compare src with each row in trg and count exact matches
103
  match_counts = np.sum(trg == src, axis=1)
@@ -105,7 +107,10 @@ def find_max_exact_match(src, trg):
105
  # Find the index of the row with the maximum number of matches
106
  max_match_idx = np.argmax(match_counts)
107
 
108
- return max_match_idx
 
 
 
109
 
110
  #==================================================================================
111
 
@@ -139,16 +144,13 @@ def Match_Cores(input_midi,
139
 
140
  #===============================================================================
141
 
142
- #==================================================================
143
-
144
  print('Matching MIDI cores...')
145
  print('=' * 70)
146
 
147
- match_idx = find_max_exact_match(src_core_chords, all_core_chords)
148
 
149
  print('MAX MATCH IDX', match_idx)
150
-
151
- #==================================================================
152
 
153
  print('=' * 70)
154
  print('Done!')
@@ -160,10 +162,6 @@ def Match_Cores(input_midi,
160
 
161
  final_core_score = midi_cores_dataset['train'][int(match_idx)]['core_score']
162
 
163
-
164
-
165
- #===============================================================================
166
-
167
  print('Done!')
168
  print('=' * 70)
169
 
@@ -280,15 +278,11 @@ with gr.Blocks() as demo:
280
  #==================================================================================
281
 
282
  gr.Markdown("## Upload source MIDI")
 
283
 
284
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
285
 
286
- gr.Markdown("## Mixing options")
287
-
288
- chords_chunks_len = gr.Slider(3, 7, value=4, step=1, label="Number of chords to match for each repeating chunk")
289
- num_mix_chunks = gr.Slider(4, 20, value=10, step=1, label="Number of repeating chunks to mix")
290
-
291
- mix_btn = gr.Button("Remix", variant="primary")
292
 
293
  gr.Markdown("## Mixing results")
294
 
 
97
  trg (numpy.ndarray): 2D target array.
98
 
99
  Returns:
100
+ tuple: A tuple containing:
101
+ - int: Index of the row in trg with the maximum number of exact matches.
102
+ - int: Number of matched elements in that row.
103
  """
104
  # Compare src with each row in trg and count exact matches
105
  match_counts = np.sum(trg == src, axis=1)
 
107
  # Find the index of the row with the maximum number of matches
108
  max_match_idx = np.argmax(match_counts)
109
 
110
+ # Get the number of matched elements in the best-matching row
111
+ num_matched_elements = match_counts[max_match_idx]
112
+
113
+ return max_match_idx, num_matched_elements
114
 
115
  #==================================================================================
116
 
 
144
 
145
  #===============================================================================
146
 
 
 
147
  print('Matching MIDI cores...')
148
  print('=' * 70)
149
 
150
+ match_idx, num_matches = find_max_exact_match(src_core_chords, all_core_chords)
151
 
152
  print('MAX MATCH IDX', match_idx)
153
+ print('NUM MATCHES', num_matches)
 
154
 
155
  print('=' * 70)
156
  print('Done!')
 
162
 
163
  final_core_score = midi_cores_dataset['train'][int(match_idx)]['core_score']
164
 
 
 
 
 
165
  print('Done!')
166
  print('=' * 70)
167
 
 
278
  #==================================================================================
279
 
280
  gr.Markdown("## Upload source MIDI")
281
+ gr.Markdown("### Source MIDI must have at least 128 chords")
282
 
283
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
284
 
285
+ mix_btn = gr.Button("Match", variant="primary")
 
 
 
 
 
286
 
287
  gr.Markdown("## Mixing results")
288