Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- book details.pkl +3 -0
- main.py +34 -0
- requirements.txt +3 -0
- similarity score.npy +3 -0
- user book data.pkl +3 -0
book details.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6b4889ef8a8a856d8a658614206d6c2e39299823f685e150ae8b3db401c8ed23
|
| 3 |
+
size 125363
|
main.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])
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==1.23.5
|
| 2 |
+
pandas==2.0.1
|
| 3 |
+
streamlit==1.29.0
|
similarity score.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:102e6dec5bf8a642474b87b031a9bfc18e2ae73e760ca0382349d3decd666531
|
| 3 |
+
size 3987616
|
user book data.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:baa62baed1a5e620cb55a28ff6e171764266569bd34781a9f8de52e9788a0972
|
| 3 |
+
size 4601015
|