Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from itertools import cycle
|
| 5 |
+
|
| 6 |
+
pt_table = pd.read_pickle('user book data.pkl')
|
| 7 |
+
book_details = pd.read_pickle('book details.pkl')
|
| 8 |
+
with open('similarity score.npy', 'rb') as f:
|
| 9 |
+
similarity_score = np.load(f)
|
| 10 |
+
book_names = pt_table.index.values.tolist()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def recommend(book_name):
|
| 14 |
+
book_index = np.where(pt_table.index == book_name)[0][0]
|
| 15 |
+
distances = similarity_score[book_index]
|
| 16 |
+
similar_items = sorted(list(enumerate(distances)),
|
| 17 |
+
key=lambda x: x[1], reverse=True)[1:7]
|
| 18 |
+
suggestion = []
|
| 19 |
+
for i in similar_items:
|
| 20 |
+
suggestion.append(pt_table.index[i[0]])
|
| 21 |
+
return suggestion
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
st.set_page_config(page_title="Book recommender system")
|
| 25 |
+
st.title("Book recommender system")
|
| 26 |
+
option = st.selectbox("Enter or select a book name", book_names, index=0)
|
| 27 |
+
if st.button("Recommend"):
|
| 28 |
+
recommendation = recommend(option)
|
| 29 |
+
cols = cycle(st.columns(3))
|
| 30 |
+
for recom in recommendation:
|
| 31 |
+
next(cols).image(book_details[book_details['Book-Title'] == recom]['Image-URL-M'].values[0],
|
| 32 |
+
f"{book_details[book_details['Book-Title']==recom]['Book-Title'].values[0]} by {book_details[book_details['Book-Title']==recom]['Book-Author'].values[0]}", width=150)
|
| 33 |
+
print(book_details[book_details['Book-Title']
|
| 34 |
+
== recom]['Image-URL-M'].values[0])
|