Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,263 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import numpy as np
|
4 |
-
import requests
|
5 |
-
|
6 |
-
|
7 |
-
df = pd.read_pickle('popular.pkl')
|
8 |
-
|
9 |
-
books = pd.read_pickle('books.pkl')
|
10 |
-
similarity_scores = pd.read_pickle('similarity.pkl')
|
11 |
-
pt = pd.read_pickle('pt.pkl')
|
12 |
-
final_books = pd.read_pickle("final.pkl")
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
def recommend_book(book_name):
|
17 |
-
# fetch index
|
18 |
-
index = np.where(pt.index==book_name)[0][0]
|
19 |
-
|
20 |
-
similar_items = sorted(list(enumerate(similarity_scores[index])),key=lambda x:x[1],reverse=True)[1:6]
|
21 |
-
|
22 |
-
data=[]
|
23 |
-
for i in similar_items:
|
24 |
-
item=[]
|
25 |
-
temp_df = books[books['Book-Title'] == pt.index[i[0]]]
|
26 |
-
item.extend(list(temp_df.drop_duplicates('Book-Title')['Book-Title'].values))
|
27 |
-
item.extend(list(temp_df.drop_duplicates('Book-Title')['Book-Author'].values))
|
28 |
-
item.extend(list(temp_df.drop_duplicates('Book-Title')['Image-URL-M'].values))
|
29 |
-
|
30 |
-
|
31 |
-
data.append(item)
|
32 |
-
return data
|
33 |
-
|
34 |
-
def fetch_book_details(book_name):
|
35 |
-
url = 'https://www.googleapis.com/books/v1/volumes?q={}'.format(book_name)
|
36 |
-
response=requests.get(url)
|
37 |
-
obj=response.json()
|
38 |
-
book_details=[]
|
39 |
-
ids = [id['id'] for id in obj['items']]
|
40 |
-
ids = ids[0]
|
41 |
-
title = obj['items'][0]['volumeInfo']['title']
|
42 |
-
author = obj['items'][0]['volumeInfo']['authors'][0]
|
43 |
-
publish_date= obj['items'][0]['volumeInfo']['publishedDate']
|
44 |
-
image = obj['items'][0]['volumeInfo']['imageLinks']['thumbnail']
|
45 |
-
preview_link = obj['items'][0]['volumeInfo']['previewLink']
|
46 |
-
info = obj['items'][0]['volumeInfo']['infoLink']
|
47 |
-
book_details.append(ids)
|
48 |
-
book_details.append(title)
|
49 |
-
|
50 |
-
book_details.append(author)
|
51 |
-
|
52 |
-
book_details.append(publish_date)
|
53 |
-
book_details.append(preview_link)
|
54 |
-
book_details.append(info)
|
55 |
-
book_details.append(image)
|
56 |
-
print(book_details)
|
57 |
-
return book_details
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
menu = ['top20','recommender','about']
|
62 |
-
|
63 |
-
option = st.sidebar.selectbox("Select One: ",menu)
|
64 |
-
|
65 |
-
if option == 'top20':
|
66 |
-
st.title("Top 20 Books")
|
67 |
-
st.text("")
|
68 |
-
col1,col2,col3,col4=st.columns(4)
|
69 |
-
with col1:
|
70 |
-
st.image(df['Image-URL-M'][0])
|
71 |
-
st.markdown(f"[{df['Book-Title'][0]}]({fetch_book_details(df['Book-Title'][0])[5]})")
|
72 |
-
|
73 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][0]}",unsafe_allow_html=True)
|
74 |
-
st.markdown(f"Votes - {df['num_ratings'][0]}")
|
75 |
-
st.markdown(f"rating - {round(df['avg_ratings'][0],2)}")
|
76 |
-
with col2:
|
77 |
-
st.image(df['Image-URL-M'][3])
|
78 |
-
st.markdown(f"[{df['Book-Title'][3]}]({fetch_book_details(df['Book-Title'][3])[5]})")
|
79 |
-
|
80 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][3]}",unsafe_allow_html=True)
|
81 |
-
st.markdown(f"Votes - {df['num_ratings'][3]}")
|
82 |
-
st.markdown(f"rating - {round(df['avg_ratings'][3],2)}")
|
83 |
-
with col3:
|
84 |
-
st.image(df['Image-URL-M'][5])
|
85 |
-
st.markdown(f"[{df['Book-Title'][5]}]({fetch_book_details(df['Book-Title'][5])[5]})")
|
86 |
-
|
87 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][5]}",unsafe_allow_html=True)
|
88 |
-
st.markdown(f"Votes - {df['num_ratings'][5]}")
|
89 |
-
st.markdown(f"rating - {round(df['avg_ratings'][5],2)}")
|
90 |
-
with col4:
|
91 |
-
st.image(df['Image-URL-M'][9])
|
92 |
-
st.markdown(f"[{df['Book-Title'][9]}]({fetch_book_details(df['Book-Title'][9])[5]})")
|
93 |
-
|
94 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][9]}",unsafe_allow_html=True)
|
95 |
-
st.markdown(f"Votes - {df['num_ratings'][9]}")
|
96 |
-
st.markdown(f"rating - {round(df['avg_ratings'][9],2)}")
|
97 |
-
|
98 |
-
st.text("")
|
99 |
-
col1,col2,col3,col4=st.columns(4)
|
100 |
-
with col1:
|
101 |
-
st.image(df['Image-URL-M'][13])
|
102 |
-
st.markdown(f"[{df['Book-Title'][13]}]({fetch_book_details(df['Book-Title'][13])[5]})")
|
103 |
-
st.markdown(df['Book-Title'][13][0:40])
|
104 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][13]}",unsafe_allow_html=True)
|
105 |
-
st.markdown(f"Votes - {df['num_ratings'][13]}")
|
106 |
-
st.markdown(f"rating - {round(df['avg_ratings'][13],2)}")
|
107 |
-
with col2:
|
108 |
-
st.image(df['Image-URL-M'][16])
|
109 |
-
st.markdown(f"[{df['Book-Title'][16]}]({fetch_book_details(df['Book-Title'][16])[5]})")
|
110 |
-
|
111 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][16]}",unsafe_allow_html=True)
|
112 |
-
st.markdown(f"Votes - {df['num_ratings'][16]}")
|
113 |
-
st.markdown(f"rating - {round(df['avg_ratings'][16],2)}")
|
114 |
-
with col3:
|
115 |
-
st.image(df['Image-URL-M'][17])
|
116 |
-
st.markdown(f"[{df['Book-Title'][17]}]({fetch_book_details(df['Book-Title'][17])[5]})")
|
117 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][17]}",unsafe_allow_html=True)
|
118 |
-
st.markdown(f"Votes - {df['num_ratings'][17]}")
|
119 |
-
st.markdown(f"rating - {round(df['avg_ratings'][17],2)}")
|
120 |
-
with col4:
|
121 |
-
st.image(df['Image-URL-M'][26])
|
122 |
-
st.markdown(f"[{df['Book-Title'][26]}]({fetch_book_details(df['Book-Title'][26])[5]})")
|
123 |
-
st.markdown(df['Book-Title'][26][0:40])
|
124 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][26]}",unsafe_allow_html=True)
|
125 |
-
st.markdown(f"Votes - {df['num_ratings'][26]}")
|
126 |
-
st.markdown(f"rating - {round(df['avg_ratings'][26],2)}")
|
127 |
-
|
128 |
-
st.text("")
|
129 |
-
col1,col2,col3,col4=st.columns(4)
|
130 |
-
with col1:
|
131 |
-
st.image(df['Image-URL-M'][28])
|
132 |
-
st.markdown(f"[{df['Book-Title'][17]}]({fetch_book_details(df['Book-Title'][17])[5]})")
|
133 |
-
|
134 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][28]}",unsafe_allow_html=True)
|
135 |
-
st.markdown(f"Votes - {df['num_ratings'][28]}")
|
136 |
-
st.markdown(f"rating - {round(df['avg_ratings'][28],2)}")
|
137 |
-
with col2:
|
138 |
-
st.image(df['Image-URL-M'][39])
|
139 |
-
st.markdown(f"[{df['Book-Title'][39]}]({fetch_book_details(df['Book-Title'][39])[5]})")
|
140 |
-
|
141 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][39]}",unsafe_allow_html=True)
|
142 |
-
st.markdown(f"Votes - {df['num_ratings'][39]}")
|
143 |
-
st.markdown(f"rating - {round(df['avg_ratings'][39],2)}")
|
144 |
-
with col3:
|
145 |
-
st.image(df['Image-URL-M'][47])
|
146 |
-
st.markdown(f"[{df['Book-Title'][47]}]({fetch_book_details(df['Book-Title'][47])[5]})")
|
147 |
-
|
148 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][47]}",unsafe_allow_html=True)
|
149 |
-
st.markdown(f"Votes - {df['num_ratings'][47]}")
|
150 |
-
st.markdown(f"rating - {round(df['avg_ratings'][47],2)}")
|
151 |
-
with col4:
|
152 |
-
st.image(df['Image-URL-M'][53])
|
153 |
-
st.markdown(f"[{df['Book-Title'][53]}]({fetch_book_details(df['Book-Title'][53])[5]})")
|
154 |
-
|
155 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][53]}",unsafe_allow_html=True)
|
156 |
-
st.markdown(f"Votes - {df['num_ratings'][53]}")
|
157 |
-
st.markdown(f"rating - {round(df['avg_ratings'][53],2)}")
|
158 |
-
|
159 |
-
st.text("")
|
160 |
-
col1,col2,col3,col4=st.columns(4)
|
161 |
-
with col1:
|
162 |
-
st.image(df['Image-URL-M'][55])
|
163 |
-
st.markdown(f"[{df['Book-Title'][55]}]({fetch_book_details(df['Book-Title'][55])[5]})")
|
164 |
-
|
165 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][55]}",unsafe_allow_html=True)
|
166 |
-
st.markdown(f"Votes - {df['num_ratings'][55]}")
|
167 |
-
st.markdown(f"rating - {round(df['avg_ratings'][55],2)}")
|
168 |
-
with col2:
|
169 |
-
st.image(df['Image-URL-M'][62])
|
170 |
-
st.markdown(f"[{df['Book-Title'][62]}]({fetch_book_details(df['Book-Title'][62])[5]})")
|
171 |
-
|
172 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][62]}",unsafe_allow_html=True)
|
173 |
-
st.markdown(f"Votes - {df['num_ratings'][62]}")
|
174 |
-
st.markdown(f"rating - {round(df['avg_ratings'][62],2)}")
|
175 |
-
with col3:
|
176 |
-
st.image(df['Image-URL-M'][63])
|
177 |
-
st.markdown(f"[{df['Book-Title'][63]}]({fetch_book_details(df['Book-Title'][63])[5]})")
|
178 |
-
|
179 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][63]}",unsafe_allow_html=True)
|
180 |
-
st.markdown(f"Votes - {df['num_ratings'][63]}")
|
181 |
-
st.markdown(f"rating - {round(df['avg_ratings'][63],2)}")
|
182 |
-
with col4:
|
183 |
-
st.image(df['Image-URL-M'][72])
|
184 |
-
st.markdown(f"[{df['Book-Title'][72]}]({fetch_book_details(df['Book-Title'][72])[5]})")
|
185 |
-
|
186 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][72]}",unsafe_allow_html=True)
|
187 |
-
st.markdown(f"Votes - {df['num_ratings'][72]}")
|
188 |
-
st.markdown(f"rating - {round(df['avg_ratings'][72],2)}")
|
189 |
-
|
190 |
-
|
191 |
-
st.text("")
|
192 |
-
col1,col2,col3,col4=st.columns(4)
|
193 |
-
with col1:
|
194 |
-
st.image(df['Image-URL-M'][73])
|
195 |
-
st.markdown(f"[{df['Book-Title'][73]}]({fetch_book_details(df['Book-Title'][73])[5]})")
|
196 |
-
|
197 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][73]}",unsafe_allow_html=True)
|
198 |
-
st.markdown(f"Votes - {df['num_ratings'][73]}")
|
199 |
-
st.markdown(f"rating - {round(df['avg_ratings'][73],2)}")
|
200 |
-
with col2:
|
201 |
-
st.image(df['Image-URL-M'][78])
|
202 |
-
st.markdown(f"[{df['Book-Title'][78]}]({fetch_book_details(df['Book-Title'][78])[5]})")
|
203 |
-
|
204 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][78]}",unsafe_allow_html=True)
|
205 |
-
st.markdown(f"Votes - {df['num_ratings'][78]}")
|
206 |
-
st.markdown(f"rating - {round(df['avg_ratings'][78],2)}")
|
207 |
-
with col3:
|
208 |
-
st.image(df['Image-URL-M'][84])
|
209 |
-
st.markdown(f"[{df['Book-Title'][84]}]({fetch_book_details(df['Book-Title'][84])[5]})")
|
210 |
-
|
211 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][84]}",unsafe_allow_html=True)
|
212 |
-
st.markdown(f"Votes - {df['num_ratings'][84]}")
|
213 |
-
st.markdown(f"rating - {round(df['avg_ratings'][84],2)}")
|
214 |
-
with col4:
|
215 |
-
st.image(df['Image-URL-M'][85])
|
216 |
-
st.markdown(f"[{df['Book-Title'][85]}]({fetch_book_details(df['Book-Title'][85])[5]})")
|
217 |
-
|
218 |
-
st.markdown(f"<b>Author:<b>{df['Book-Author'][85]}",unsafe_allow_html=True)
|
219 |
-
st.markdown(f"Votes - {df['num_ratings'][85]}")
|
220 |
-
st.markdown(f"rating - {round(df['avg_ratings'][85],2)}")
|
221 |
-
|
222 |
-
elif option=='recommender':
|
223 |
-
st.title("Books Recommender System")
|
224 |
-
book_list = final_books['Book-Title'].values
|
225 |
-
selected_book = st.selectbox("Select your book ",book_list)
|
226 |
-
if st.button("show recommendation"):
|
227 |
-
st.header("Recommend For You....")
|
228 |
-
st.text("")
|
229 |
-
data=recommend_book(selected_book)
|
230 |
-
col1,col2,col3,col4=st.columns(4)
|
231 |
-
|
232 |
-
with col1:
|
233 |
-
st.image(fetch_book_details(data[0][0])[6])
|
234 |
-
st.markdown(f"[{data[0][0]}]({fetch_book_details(data[0][0])[5]})")
|
235 |
-
|
236 |
-
|
237 |
-
with col2:
|
238 |
-
st.image(fetch_book_details(data[1][0])[6])
|
239 |
-
st.markdown(f"[{data[1][0]}]({fetch_book_details(data[1][0])[5]})")
|
240 |
-
|
241 |
-
with col3:
|
242 |
-
st.image(fetch_book_details(data[2][0])[6])
|
243 |
-
st.markdown(f"[{data[2][0]}]({fetch_book_details(data[2][0])[5]})")
|
244 |
-
|
245 |
-
|
246 |
-
with col4:
|
247 |
-
st.image(fetch_book_details(data[3][0])[6])
|
248 |
-
st.markdown(f"[{data[3][0]}]({fetch_book_details(data[3][0])[5]})")
|
249 |
-
|
250 |
-
|
251 |
-
elif option=="about":
|
252 |
-
st.title("Book Recommendation Engine V-2.0")
|
253 |
-
st.markdown("This Engine Developed by <a href='https://github.com/datamind321'>DataMind Platform</a>",unsafe_allow_html=True)
|
254 |
-
st.subheader("if you have any query Contact us on : [email protected]")
|
255 |
-
st.markdown("More on : ")
|
256 |
-
|
257 |
-
|
258 |
-
st.markdown("[](https://www.linkedin.com/in/rahul-rathour-402408231/)",unsafe_allow_html=True)
|
259 |
-
|
260 |
-
|
261 |
-
st.markdown("[](https://instag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