asigalov61 commited on
Commit
22f1ac4
1 Parent(s): 7455a77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -52,13 +52,20 @@ def find_midi(title, artist):
52
 
53
  # Compute cosine similarity between query and each sentence in the corpus
54
  similarities = util.cos_sim(query_embedding, corpus_embeddings)
55
-
 
 
56
  # Find the index of the most similar sentence
57
  closest_index = np.argmax(similarities)
58
  closest_index_match_ratio = max(similarities[0]).tolist()
59
 
60
  best_corpus_match = all_MIDI_files_names[closest_index]
61
 
 
 
 
 
 
62
  print('Done!')
63
  print('=' * 70)
64
 
@@ -89,6 +96,8 @@ def find_midi(title, artist):
89
 
90
  MIDI_score_data = scores_data[fnameidx][1]
91
 
 
 
92
  print('Sample INTs', MIDI_score_data[:12])
93
  print('=' * 70)
94
 
@@ -154,11 +163,6 @@ def find_midi(title, artist):
154
  print('=' * 70)
155
 
156
  #===============================================================================
157
- print('Rendering results...')
158
-
159
- print('=' * 70)
160
- print('Sample INTs', song_f[:3])
161
- print('=' * 70)
162
 
163
  output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(song_f)
164
 
@@ -166,8 +170,7 @@ def find_midi(title, artist):
166
  output_signature = 'Los Angeles MIDI Dataset Search',
167
  output_file_name = song_artist,
168
  track_name='Project Los Angeles',
169
- list_of_MIDI_patches=patches,
170
- timings_multiplier=16
171
  )
172
 
173
  new_fn = song_artist + '.mid'
@@ -185,7 +188,7 @@ def find_midi(title, artist):
185
  #========================================================
186
 
187
  output_midi_title = str(song_artist)
188
- output_midi_summary = str(song_f[:3])
189
  output_midi = str(new_fn)
190
  output_audio = (16000, audio)
191
 
@@ -253,7 +256,7 @@ if __name__ == "__main__":
253
  gr.Markdown("# Search results")
254
 
255
  output_midi_title = gr.Textbox(label="Output MIDI title")
256
- output_midi_summary = gr.Textbox(label="Output MIDI summary")
257
  output_audio = gr.Audio(label="Output MIDI audio", format="wav", elem_id="midi_audio")
258
  output_plot = gr.Plot(label="Output MIDI score plot")
259
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
 
52
 
53
  # Compute cosine similarity between query and each sentence in the corpus
54
  similarities = util.cos_sim(query_embedding, corpus_embeddings)
55
+
56
+ top_ten_matches_idxs = np.argsort(-similarities)[0][:10].tolist()
57
+
58
  # Find the index of the most similar sentence
59
  closest_index = np.argmax(similarities)
60
  closest_index_match_ratio = max(similarities[0]).tolist()
61
 
62
  best_corpus_match = all_MIDI_files_names[closest_index]
63
 
64
+ top_ten_matches = ''
65
+
66
+ for t in top_ten_matches_idxs:
67
+ top_ten_matches += all_MIDI_files_names[t][0] + '\n'
68
+
69
  print('Done!')
70
  print('=' * 70)
71
 
 
96
 
97
  MIDI_score_data = scores_data[fnameidx][1]
98
 
99
+ print('Rendering results...')
100
+ print('=' * 70)
101
  print('Sample INTs', MIDI_score_data[:12])
102
  print('=' * 70)
103
 
 
163
  print('=' * 70)
164
 
165
  #===============================================================================
 
 
 
 
 
166
 
167
  output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(song_f)
168
 
 
170
  output_signature = 'Los Angeles MIDI Dataset Search',
171
  output_file_name = song_artist,
172
  track_name='Project Los Angeles',
173
+ list_of_MIDI_patches=patches
 
174
  )
175
 
176
  new_fn = song_artist + '.mid'
 
188
  #========================================================
189
 
190
  output_midi_title = str(song_artist)
191
+ output_midi_summary = str(top_ten_matches)
192
  output_midi = str(new_fn)
193
  output_audio = (16000, audio)
194
 
 
256
  gr.Markdown("# Search results")
257
 
258
  output_midi_title = gr.Textbox(label="Output MIDI title")
259
+ output_midi_summary = gr.Textbox(label="Top ten MIDI matches")
260
  output_audio = gr.Audio(label="Output MIDI audio", format="wav", elem_id="midi_audio")
261
  output_plot = gr.Plot(label="Output MIDI score plot")
262
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])