Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -74,7 +74,7 @@ def build_faiss_index(dataset: pd.DataFrame) -> Tuple[faiss.IndexFlatIP, np.ndar
|
|
74 |
return index
|
75 |
|
76 |
|
77 |
-
def compute_correlations_faiss(index
|
78 |
target_book, ) -> pd.DataFrame:
|
79 |
print(target_book, type(target_book))
|
80 |
emb = create_embedding([target_book[0]])
|
@@ -84,6 +84,7 @@ def compute_correlations_faiss(index: faiss.IndexFlatIP, book_titles: List[str],
|
|
84 |
# Perform the search
|
85 |
k = len(book_titles) # 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)
|
@@ -142,7 +143,7 @@ def recommend_books(target_book: str, num_recommendations: int = 10) -> str:
|
|
142 |
closest_match = process.extractOne(target_book, book_titles)
|
143 |
|
144 |
|
145 |
-
correlations = compute_correlations_faiss(faiss_index,
|
146 |
|
147 |
recommendations = correlations[correlations['book'] != target_book].head(num_recommendations)
|
148 |
|
|
|
74 |
return index
|
75 |
|
76 |
|
77 |
+
def compute_correlations_faiss(index, book_titles: List[str],
|
78 |
target_book, ) -> pd.DataFrame:
|
79 |
print(target_book, type(target_book))
|
80 |
emb = create_embedding([target_book[0]])
|
|
|
84 |
# Perform the search
|
85 |
k = len(book_titles) # Search for all books
|
86 |
similarities, I = index.search(emb.astype('float16'), k)
|
87 |
+
print(similarities, I)
|
88 |
|
89 |
# # Reduce database and query vectors to 2D for visualization
|
90 |
# pca = PCA(n_components=2)
|
|
|
143 |
closest_match = process.extractOne(target_book, book_titles)
|
144 |
|
145 |
|
146 |
+
correlations = compute_correlations_faiss(faiss_index, list(dataset["Book-Title"]), closest_match)
|
147 |
|
148 |
recommendations = correlations[correlations['book'] != target_book].head(num_recommendations)
|
149 |
|