danschnurp commited on
Commit
fed580d
·
verified ·
1 Parent(s): 5f00df8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -75,14 +75,14 @@ def build_faiss_index(dataset: pd.DataFrame) -> Tuple[faiss.IndexFlatIP, np.ndar
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]])
81
  # target_vector = book_titles.index(emb)
82
 
83
 
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
 
@@ -143,9 +143,9 @@ def recommend_books(target_book: str, num_recommendations: int = 10) -> str:
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
 
150
  result = f"Top {num_recommendations} recommendations for '{target_book}':\n\n"
151
  for i, (_, row) in enumerate(recommendations.iterrows(), 1):
 
75
 
76
 
77
  def compute_correlations_faiss(index, book_titles: List[str],
78
+ target_book, num_recommendations) -> pd.DataFrame:
79
  print(target_book, type(target_book))
80
  emb = create_embedding([target_book[0]])
81
  # target_vector = book_titles.index(emb)
82
 
83
 
84
  # Perform the search
85
+ k = num_recommendations
86
  similarities, I = index.search(emb.astype('float16'), k)
87
  print(similarities, I)
88
 
 
143
  closest_match = process.extractOne(target_book, book_titles)
144
 
145
 
146
+ correlations = compute_correlations_faiss(faiss_index, list(dataset["Book-Title"]), closest_match, num_recommendations)
147
 
148
+ recommendations = dataset[dataset["Book-Title"] != target_book].head(num_recommendations)
149
 
150
  result = f"Top {num_recommendations} recommendations for '{target_book}':\n\n"
151
  for i, (_, row) in enumerate(recommendations.iterrows(), 1):