Spaces:
Sleeping
Sleeping
Add models and gitignore
Browse files- .gitignore +1 -0
- app.py +51 -52
- artifacts/book_names.pkl +3 -0
- artifacts/book_pivot.pkl +3 -0
- artifacts/final_ratings.pkl +3 -0
- artifacts/model.pkl +3 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.DS_Store
|
app.py
CHANGED
@@ -2,79 +2,78 @@ import pickle
|
|
2 |
import streamlit as st
|
3 |
import numpy as np
|
4 |
|
5 |
-
|
6 |
st.header("Book Recommender System")
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
2 |
import streamlit as st
|
3 |
import numpy as np
|
4 |
|
|
|
5 |
st.header("Book Recommender System")
|
6 |
|
7 |
+
model = pickle.load(open("artifacts/model.pkl", "rb"))
|
8 |
+
book_names = pickle.load(open("artifacts/book_names.pkl", "rb"))
|
9 |
+
final_ratings = pickle.load(open("artifacts/final_ratings.pkl", "rb"))
|
10 |
+
book_pivot = pickle.load(open("artifacts/book_pivot.pkl", "rb"))
|
11 |
|
12 |
+
def fetch_poster(suggestion):
|
13 |
+
bookNames = []
|
14 |
+
idsIndex = []
|
15 |
+
posterUrl = []
|
16 |
|
17 |
+
for bookId in suggestion[0]:
|
18 |
+
name = book_pivot.index[bookId]
|
19 |
|
20 |
+
bookNames.append(book_pivot.index[bookId])
|
21 |
|
22 |
+
for name in bookNames:
|
23 |
+
ids = np.where(final_ratings['title'] == name)[0][0]
|
24 |
+
idsIndex.append(ids)
|
25 |
|
26 |
+
for idx in idsIndex:
|
27 |
+
row = final_ratings.iloc[idx]
|
28 |
+
url = row['img_url']
|
29 |
+
posterUrl.append(url)
|
30 |
|
31 |
+
return posterUrl
|
32 |
|
33 |
+
def recommend_book(bookName):
|
34 |
+
bookList = []
|
35 |
|
36 |
+
book_id = np.where(book_pivot.index == bookName)[0][0]
|
37 |
|
38 |
+
distance, suggestion = model.kneighbors(book_pivot.iloc[book_id,:].values.reshape(1, -1), n_neighbors=5)
|
39 |
|
40 |
+
poster_url = fetch_poster(suggestion)
|
41 |
|
42 |
+
for i in range(len(suggestion)):
|
43 |
+
books = book_pivot.index[suggestion[i]]
|
44 |
|
45 |
+
for j in books:
|
46 |
+
bookList.append(j)
|
47 |
|
48 |
+
return bookList, poster_url
|
49 |
|
50 |
+
selected_books = st.selectbox(
|
51 |
+
"Select a book",
|
52 |
+
book_names
|
53 |
+
)
|
54 |
|
55 |
+
if st.button("Show Recommendations"):
|
56 |
+
recommendations, posterUrls = recommend_book(selected_books)
|
57 |
|
58 |
+
st.subheader("Recommendations")
|
59 |
|
60 |
+
col1, col2, col3, col4 = st.columns(4)
|
61 |
|
62 |
+
for url in posterUrls:
|
63 |
+
print(url)
|
64 |
|
65 |
+
with col1:
|
66 |
+
st.text(recommendations[1])
|
67 |
+
st.image(posterUrls[1])
|
68 |
|
69 |
+
with col2:
|
70 |
+
st.text(recommendations[2])
|
71 |
+
st.image(posterUrls[2])
|
72 |
|
73 |
+
with col3:
|
74 |
+
st.text(recommendations[3])
|
75 |
+
st.image(posterUrls[3])
|
76 |
|
77 |
+
with col4:
|
78 |
+
st.text(recommendations[4])
|
79 |
+
st.image(posterUrls[4])
|
artifacts/book_names.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:794d08c3eb7ee65bf95008096b99fdcba5376e3794e313ade38d5781451e46a2
|
3 |
+
size 20131
|
artifacts/book_pivot.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a84ce7b17434dc9cf1740e636e9c2a795f5c87f19b7b7e7414b3e8b2da5c97c0
|
3 |
+
size 5298853
|
artifacts/final_ratings.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f47e068289bf4cc38a6240dda847abcb487c5ecd5f8ce1924fc2149692f56ab6
|
3 |
+
size 3811459
|
artifacts/model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1aa3452bce5d5c6bee719a6aac3490a2cf39c0f417388a31893ffdc0df6f3317
|
3 |
+
size 183212
|