danschnurp commited on
Commit
b8a58f7
·
verified ·
1 Parent(s): 2497bf3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -171,7 +171,23 @@ def recommend_books(target_book: str, num_recommendations: int = 10) -> str:
171
  for idx, (_, row) in enumerate(recommendations.iterrows(), 1) if dataset.loc[dataset['Book-Title'] == row['book'], 'ISBN'].values[0] not in dups
172
  ])
173
  # "ISBN";"Book-Title";"Book-Author";"Year-Of-Publication";"Publisher";"Image-URL-S"
174
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
 
177
  # Create Gradio interface
@@ -181,10 +197,14 @@ iface = gr.Interface(
181
  gr.Textbox(label="Enter a book title"),
182
  gr.Slider(minimum=1, maximum=20, step=1, label="Number of recommendations", value=10)
183
  ],
184
- outputs=gr.Textbox(label="Recommendations"),
 
 
 
185
  title="Book Recommender",
186
  description="Enter a book title to get recommendations based on user ratings and book similarities."
187
  )
188
 
 
189
  # Launch the app
190
  iface.launch()
 
171
  for idx, (_, row) in enumerate(recommendations.iterrows(), 1) if dataset.loc[dataset['Book-Title'] == row['book'], 'ISBN'].values[0] not in dups
172
  ])
173
  # "ISBN";"Book-Title";"Book-Author";"Year-Of-Publication";"Publisher";"Image-URL-S"
174
+
175
+ result_df = pd.DataFrame([
176
+ {
177
+ "Rank": idx,
178
+ "Title": dataset.loc[dataset['Book-Title'] == row['book'], 'Book-Title'].values[0],
179
+ "Author": dataset.loc[dataset['Book-Title'] == row['book'], 'Book-Author'].values[0],
180
+ "Year": dataset.loc[dataset['Book-Title'] == row['book'], 'Year-Of-Publication'].values[0],
181
+ "Publisher": dataset.loc[dataset['Book-Title'] == row['book'], 'Publisher'].values[0],
182
+ "ISBN": dataset.loc[dataset['Book-Title'] == row['book'], 'ISBN'].values[0],
183
+ "Rating": ratings_by_isbn.loc[
184
+ ratings_by_isbn['ISBN'] == dataset.loc[dataset['Book-Title'] == row['book'], 'ISBN'].values[
185
+ 0], 'Book-Rating'].values[0]
186
+ }
187
+ for idx, (_, row) in enumerate(recommendations.iterrows(), 1)
188
+ ])
189
+
190
+ return result_df
191
 
192
 
193
  # Create Gradio interface
 
197
  gr.Textbox(label="Enter a book title"),
198
  gr.Slider(minimum=1, maximum=20, step=1, label="Number of recommendations", value=10)
199
  ],
200
+ outputs=gr.Dataframe(
201
+ headers=["Rank", "Title", "Author", "Year", "Publisher", "ISBN", "Rating"],
202
+ type="pandas"
203
+ ),
204
  title="Book Recommender",
205
  description="Enter a book title to get recommendations based on user ratings and book similarities."
206
  )
207
 
208
+
209
  # Launch the app
210
  iface.launch()