danschnurp commited on
Commit
0711e1b
·
verified ·
1 Parent(s): 506f53d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -136,7 +136,10 @@ def recommend_books(target_book: str, num_recommendations: int = 10) -> str:
136
 
137
  if dataset is None or faiss_index is None or normalized_data is None or book_titles is None:
138
  load_and_prepare_data()
 
 
139
  dataset = dataset.drop_duplicates(subset=['ISBN'])
 
140
 
141
  target_book = target_book.lower()
142
  # Fuzzy match the input to the closest book title
@@ -147,6 +150,12 @@ def recommend_books(target_book: str, num_recommendations: int = 10) -> str:
147
 
148
  recommendations = correlations[correlations['book'] != target_book]
149
 
 
 
 
 
 
 
150
  recommendations = recommendations.head(num_recommendations)
151
 
152
  result = f"Top {num_recommendations} recommendations for '{target_book}':\n\n"
 
136
 
137
  if dataset is None or faiss_index is None or normalized_data is None or book_titles is None:
138
  load_and_prepare_data()
139
+ dataset['ISBN'] = dataset['ISBN'].str.strip()
140
+ print("Before dropping duplicates:", len(dataset))
141
  dataset = dataset.drop_duplicates(subset=['ISBN'])
142
+ print("After dropping duplicates:", len(dataset))
143
 
144
  target_book = target_book.lower()
145
  # Fuzzy match the input to the closest book title
 
150
 
151
  recommendations = correlations[correlations['book'] != target_book]
152
 
153
+ # Create a mask of unique ISBNs
154
+ unique_mask = dataset.duplicated(subset=['ISBN'], keep='first') == False
155
+
156
+ # Apply the mask
157
+ dataset = dataset[unique_mask]
158
+
159
  recommendations = recommendations.head(num_recommendations)
160
 
161
  result = f"Top {num_recommendations} recommendations for '{target_book}':\n\n"