Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -85,23 +85,9 @@ def compute_correlations_faiss(index: faiss.IndexFlatIP, dataset,
|
|
85 |
k = len(dataset) # Search for all books
|
86 |
similarities, I = index.search(emb.astype('float16'), k)
|
87 |
|
88 |
-
# # Reduce database and query vectors to 2D for visualization
|
89 |
-
# pca = PCA(n_components=2)
|
90 |
-
# reduced_db = pca.fit_transform(data)
|
91 |
-
# reduced_query = pca.transform(target_vector)
|
92 |
-
#
|
93 |
-
# # Scatter plot
|
94 |
-
# plt.scatter(reduced_db[:, 0], reduced_db[:, 1], label='Database Vectors', alpha=0.5)
|
95 |
-
# plt.scatter(reduced_query[:, 0], reduced_query[:, 1], label='Query Vectors', marker='X', color='red')
|
96 |
-
# plt.legend()
|
97 |
-
# plt.title("PCA Projection of IndexFlatIP Vectors")
|
98 |
-
# plt.show()
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
corr_df = pd.DataFrame({
|
103 |
-
'book': [dataset
|
104 |
-
'corr': similarities[0]
|
105 |
})
|
106 |
return corr_df.sort_values('corr', ascending=False)
|
107 |
|
|
|
85 |
k = len(dataset) # Search for all books
|
86 |
similarities, I = index.search(emb.astype('float16'), k)
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
corr_df = pd.DataFrame({
|
89 |
+
'book': [[dataset["Book-Title"][j] for j in list(dataset["Book-Title"])[i]] for i in I[0]],
|
90 |
+
'corr': similarities[0],
|
91 |
})
|
92 |
return corr_df.sort_values('corr', ascending=False)
|
93 |
|