-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
51 lines (36 loc) · 1.6 KB
/
app.py
1
2
3
4
5
6
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
import streamlit as st
import pickle
st.title('Book Recommendation Engine ( Group 4) ')
df = pickle.load(open(r"C:/Users/sivas/FE/df.pkl", "rb"))
model = pickle.load(open(r"C:/Users/sivas/FE/model.pkl", "rb"))
data = pickle.load(open(r"C:/Users/sivas/FE/data.pkl", "rb"))
def recommend(books):
recommended_book_names = []
distances, indices = model.kneighbors(df.loc[books].values.reshape(1, -1), n_neighbors=10)
print("\nRecommended books:\n")
for i in range(0, len(distances.flatten())):
if i > 0:
recommended_book_names.append(df.index[indices.flatten()[i]])
return recommended_book_names
users = data['User-ID'].values
Users_book = st.selectbox('Select a books from drop down', users)
selected_user_id = data[data["User-ID"] == Users_book].sort_values('Book-Rating', ascending=False).head(1)
selected_book = selected_user_id['Book-Title'].values
st.write('You selected:', Users_book)
if st.button('Show Recommend book'):
recommended_book = recommend(selected_book)
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
st.markdown(recommended_book[0])
with col2:
st.markdown(recommended_book[1])
with col3:
st.markdown(recommended_book[2])
with col4:
st.markdown(recommended_book[3])
with col5:
st.markdown(recommended_book[4])
# Use the full page instead of a narrow central column
#st.set_page_config(layout="wide")
# Space out the maps so the first one is 2x the size of the other three
#col1, col2, col3, col4,col5 = st.columns((2, 1, 1, 1,1))