Spaces:
Runtime error
Runtime error
File size: 1,893 Bytes
1bef7aa |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import pickle
import streamlit as st
import numpy as np
st.header("Movie Recommender System using machine learning system")
model = pickle.load(open('artifacts/model.pkl','rb'))
books_name = pickle.load(open('artifacts/books_names.pkl','rb'))
final_rating = pickle.load(open('artifacts/final_rating.pkl','rb'))
book_pivot = pickle.load(open('artifacts/book_pivot.pkl','rb'))
selected_books = st.selectbox(
"Type or select a book",
books_name
)
def fetch_poster(suggestion):
books_name = []
ids_index = []
poster_url = []
for book_id in suggestion:
books_name.append(book_pivot.index[book_id])
for i in books_name[0]:
ids = np.where(final_rating['title']==i)[0][0]
ids_index.append(ids)
for idx in ids_index:
url = final_rating.iloc[idx]['img_url']
poster_url.append(url)
return poster_url
def recommend_book(book_name):
book_list = []
book_id = np.where(book_pivot.index == book_name)[0][0]
distance, suggestion = model.kneighbors(book_pivot.iloc[book_id,:].values.reshape(1,-1), n_neighbors=6 )
poster_url = fetch_poster(suggestion)
for i in range(len(suggestion)):
books = book_pivot.index[suggestion[i]]
for j in books:
book_list.append(j)
return book_list, poster_url
if st.button("Show Recommendation "):
recommended_books,poster_url = recommend_book(selected_books)
col1, col2, col3,col4, col5 = st.columns(5)
with col1:
st.text(recommended_books[1])
st.image(poster_url[1])
with col2:
st.text(recommended_books[2])
st.image(poster_url[2])
with col3:
st.text(recommended_books[3])
st.image(poster_url[3])
with col4:
st.text(recommended_books[4])
st.image(poster_url[4])
with col5:
st.text(recommended_books[5])
st.image(poster_url[5])
|