PierreHanna commited on
Commit
7761659
Β·
1 Parent(s): 365609b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
app.py CHANGED
@@ -52,22 +52,31 @@ def process_file(input_path):
52
  return process(input_path, '')
53
 
54
  def process(audio_file, embed_html_all):
55
- model = openl3.models.load_audio_embedding_model(input_repr="linear", content_type="music",embedding_size=512)
56
- audio, sr = librosa.load(audio_file, mono=True)
57
- emb, ts = openl3.get_audio_embedding(audio, sr, model=model)
58
- emb = np.mean(emb, axis=0)
59
- print("SHAPE ", emb.shape)
 
 
 
 
 
 
60
 
61
- ind = faiss.read_index("index.index")
62
- ind_filenames = pickle.load(open('index.filenames','rb'))
63
- dict_bmg = pickle.load(open('dict_bmg.pickle','rb')) # filename to url
64
- D, I = ind.search(emb.reshape((1,512)), 5)
65
-
66
- top1 = dict_bmg[ind_filenames[I[0][0]]]
67
- top2 = dict_bmg[ind_filenames[I[0][1]]]
68
- top3 = dict_bmg[ind_filenames[I[0][2]]]
69
- top4 = dict_bmg[ind_filenames[I[0][3]]]
70
- top5 = dict_bmg[ind_filenames[I[0][4]]]
 
 
 
71
 
72
  return top1, top2, top3, top4, top5
73
 
 
52
  return process(input_path, '')
53
 
54
  def process(audio_file, embed_html_all):
55
+ #model = openl3.models.load_audio_embedding_model(input_repr="linear", content_type="music",embedding_size=512)
56
+ #audio, sr = librosa.load(audio_file, mono=True)
57
+ #emb, ts = openl3.get_audio_embedding(audio, sr, model=model)
58
+ #emb = np.mean(emb, axis=0)
59
+ #print("SHAPE ", emb.shape)
60
+
61
+ emb, ts = get_embed(audio_file)
62
+
63
+ #ind = faiss.read_index("index.index")
64
+ #ind_filenames = pickle.load(open('index.filenames','rb'))
65
+ ind, ind_filenames = load_index()
66
 
67
+ #dict_bmg = pickle.load(open('dict_bmg.pickle','rb')) # filename to url
68
+ catalog = load_catalog()
69
+
70
+ D, I = do_search(embed, ind)
71
+ #D, I = ind.search(emb.reshape((1,512)), 5)
72
+
73
+ #top1 = dict_bmg[ind_filenames[I[0][0]]]
74
+ #top2 = dict_bmg[ind_filenames[I[0][1]]]
75
+ #top3 = dict_bmg[ind_filenames[I[0][2]]]
76
+ #top4 = dict_bmg[ind_filenames[I[0][3]]]
77
+ #top5 = dict_bmg[ind_filenames[I[0][4]]]
78
+
79
+ top1, top2, top3, top4, top5 = get_top(I, ind_filenames, catalog)
80
 
81
  return top1, top2, top3, top4, top5
82