Spaces:
Build error
Build error
File size: 1,030 Bytes
5a413ea afc0915 5a413ea afc0915 5a413ea afc0915 5a413ea afc0915 | 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 | import streamlit as st
import numpy as np
from joblib import load
st.title("Book Recommendation System")
# Load models and data
model = load("model.pkl")
books_name = load("book_names.pkl")
final_rating = load("final_rating.pkl")
book_pivot_tale = load("book_pivot_tale.pkl")
# Book selection
select_book = st.selectbox("Select a book", options=books_name)
# Recommendation function
def recommended_book(book_name):
book_id = np.where(book_pivot_tale.index == book_name)[0][0]
distances, suggestions = model.kneighbors(
book_pivot_tale.iloc[book_id, :].values.reshape(1, -1), n_neighbors=6
)
recommended_books = []
for i in suggestions[0][1:]: # Skipping the first as it's the input book itself
recommended_books.append(book_pivot_tale.index[i])
return recommended_books
# On button click
if st.button("Recommend"):
books_list = recommended_book(select_book)
st.success("Recommended books are:")
for i, book in enumerate(books_list):
st.write(f"{i+1}. {book}")
|