asigalov61
commited on
Commit
•
bd71b6f
1
Parent(s):
77c722a
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# https://huggingface.co/spaces/asigalov61/MIDI-Search
|
2 |
|
3 |
import os
|
4 |
|
@@ -36,21 +36,12 @@ def find_midi(input_search_string):
|
|
36 |
start_time = reqtime.time()
|
37 |
|
38 |
print('-' * 70)
|
39 |
-
print('Req
|
40 |
-
print('Req artist:', artist)
|
41 |
print('-' * 70)
|
42 |
-
|
43 |
-
|
44 |
-
input_text = ''
|
45 |
-
|
46 |
-
if title != '':
|
47 |
-
input_text += title
|
48 |
-
if artist != '':
|
49 |
-
input_text += ' by ' + artist
|
50 |
|
51 |
print('Searching...')
|
52 |
|
53 |
-
query_embedding = model.encode([
|
54 |
|
55 |
# Compute cosine similarity between query and each sentence in the corpus
|
56 |
similarities = util.cos_sim(query_embedding, corpus_embeddings)
|
@@ -59,7 +50,7 @@ def find_midi(input_search_string):
|
|
59 |
|
60 |
# Find the index of the most similar sentence
|
61 |
closest_index = np.argmax(similarities)
|
62 |
-
closest_index_match_ratio = max(similarities[0]
|
63 |
|
64 |
best_corpus_match = all_MIDI_files_names[closest_index]
|
65 |
|
@@ -227,11 +218,13 @@ if __name__ == "__main__":
|
|
227 |
print('Loading MidiCaps dataset...')
|
228 |
|
229 |
mc_dataset = load_dataset("amaai-lab/MidiCaps")
|
|
|
230 |
print('=' * 70)
|
231 |
|
232 |
print('Loading files list...')
|
233 |
|
234 |
all_MIDI_files_names = TMIDIX.Tegridy_Any_Pickle_File_Reader('LAKH_all_files_names')
|
|
|
235 |
print('=' * 70)
|
236 |
|
237 |
print('Loading MIDI corpus embeddings...')
|
|
|
1 |
+
# https://huggingface.co/spaces/asigalov61/LAKH-MIDI-Dataset-Search
|
2 |
|
3 |
import os
|
4 |
|
|
|
36 |
start_time = reqtime.time()
|
37 |
|
38 |
print('-' * 70)
|
39 |
+
print('Req search str:', input_search_string)
|
|
|
40 |
print('-' * 70)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
print('Searching...')
|
43 |
|
44 |
+
query_embedding = model.encode([input_search_string])
|
45 |
|
46 |
# Compute cosine similarity between query and each sentence in the corpus
|
47 |
similarities = util.cos_sim(query_embedding, corpus_embeddings)
|
|
|
50 |
|
51 |
# Find the index of the most similar sentence
|
52 |
closest_index = np.argmax(similarities)
|
53 |
+
closest_index_match_ratio = max(similarities[0].tolist())
|
54 |
|
55 |
best_corpus_match = all_MIDI_files_names[closest_index]
|
56 |
|
|
|
218 |
print('Loading MidiCaps dataset...')
|
219 |
|
220 |
mc_dataset = load_dataset("amaai-lab/MidiCaps")
|
221 |
+
mc_fnames = [f['location'].split('/')[-1].split('.mid')[0] for f in mc_dataset['train']]
|
222 |
print('=' * 70)
|
223 |
|
224 |
print('Loading files list...')
|
225 |
|
226 |
all_MIDI_files_names = TMIDIX.Tegridy_Any_Pickle_File_Reader('LAKH_all_files_names')
|
227 |
+
MIDI_files_names = [f[0] for f in all_MIDI_files_names]
|
228 |
print('=' * 70)
|
229 |
|
230 |
print('Loading MIDI corpus embeddings...')
|