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