Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Movie recommender system.jpg +0 -0
- app.py +122 -0
- movie_list.pkl +3 -0
- requirements.txt +6 -0
- tfidf_matrix.pkl +3 -0
Movie recommender system.jpg
ADDED
app.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import streamlit as st
|
3 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
4 |
+
from PIL import Image
|
5 |
+
from scipy.sparse import csr_matrix
|
6 |
+
|
7 |
+
|
8 |
+
@st.cache_data
|
9 |
+
def get_recommendation(title):
|
10 |
+
idx = df1.index[df1['title'] == title][0]
|
11 |
+
poster = f'https://image.tmdb.org/t/p/w500/{df1.loc[idx, "poster_path"]}'
|
12 |
+
|
13 |
+
# Get the pairwise similarity scores of all movies with that movie
|
14 |
+
sim_scores = list(enumerate(
|
15 |
+
cosine_similarity(
|
16 |
+
tfidf_matrix,
|
17 |
+
tfidf_matrix[idx])))
|
18 |
+
|
19 |
+
# Sort the movies based on the similarity scores
|
20 |
+
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
21 |
+
|
22 |
+
# Get the scores of the 10 most similar movies
|
23 |
+
sim_scores = sim_scores[1:13]
|
24 |
+
|
25 |
+
# Get the movie indices
|
26 |
+
movie_indices = [i[0] for i in sim_scores]
|
27 |
+
|
28 |
+
# Return the top 10 most similar movies
|
29 |
+
result = df1.iloc[movie_indices]
|
30 |
+
|
31 |
+
recommended_movie_names = []
|
32 |
+
recommended_movie_posters = []
|
33 |
+
recommended_movie_overview = []
|
34 |
+
|
35 |
+
for i, j in enumerate(result.poster_path):
|
36 |
+
recommended_movie_names.append(result.iloc[i].title)
|
37 |
+
recommended_movie_posters.append(f'https://image.tmdb.org/t/p/w500/{j}')
|
38 |
+
recommended_movie_overview.append(result.iloc[i].overview)
|
39 |
+
return poster, recommended_movie_names, recommended_movie_posters, recommended_movie_overview
|
40 |
+
|
41 |
+
|
42 |
+
image = Image.open('Movie recommender system.jpg')
|
43 |
+
st.title("Movie Recommendation Engine")
|
44 |
+
st.image(image)
|
45 |
+
|
46 |
+
st.markdown('For this project, I developed a Content-Based Recommendation System that suggests movies based on attributes like genre, director, description, and actors. The system operates on the principle that users who enjoyed a specific movie or show are likely to appreciate other movies or shows with similar characteristics.')
|
47 |
+
|
48 |
+
df1 = pickle.load(open('movie_list.pkl', 'rb'))
|
49 |
+
tfidf_matrix = pickle.load(open('tfidf_matrix.pkl', 'rb'))
|
50 |
+
|
51 |
+
movies_list = df1['title'].values
|
52 |
+
selected_movie = st.sidebar.selectbox('Select a Movie', movies_list) # Move selectbox to the sidebar
|
53 |
+
|
54 |
+
if st.sidebar.button('Show Recommendation'): # Move button to the sidebar
|
55 |
+
poster, recommended_movie_names, recommended_movie_posters, recommended_movie_overview = get_recommendation(
|
56 |
+
selected_movie)
|
57 |
+
st.image(poster, width=160)
|
58 |
+
col1, col2, col3, col4 = st.columns(4)
|
59 |
+
with col1:
|
60 |
+
st.image(recommended_movie_posters[0])
|
61 |
+
st.markdown(recommended_movie_names[0])
|
62 |
+
with st.expander("OverView"):
|
63 |
+
st.write(recommended_movie_overview[0])
|
64 |
+
|
65 |
+
st.image(recommended_movie_posters[4])
|
66 |
+
st.markdown(recommended_movie_names[4])
|
67 |
+
with st.expander("OverView"):
|
68 |
+
st.write(recommended_movie_overview[4])
|
69 |
+
|
70 |
+
st.image(recommended_movie_posters[8])
|
71 |
+
st.markdown(recommended_movie_names[8])
|
72 |
+
with st.expander("OverView"):
|
73 |
+
st.write(recommended_movie_overview[8])
|
74 |
+
|
75 |
+
with col2:
|
76 |
+
st.image(recommended_movie_posters[1])
|
77 |
+
st.markdown(recommended_movie_names[1])
|
78 |
+
with st.expander("OverView"):
|
79 |
+
st.write(recommended_movie_overview[1])
|
80 |
+
|
81 |
+
st.image(recommended_movie_posters[5])
|
82 |
+
st.markdown(recommended_movie_names[5])
|
83 |
+
with st.expander("OverView"):
|
84 |
+
st.write(recommended_movie_overview[5])
|
85 |
+
|
86 |
+
st.image(recommended_movie_posters[9])
|
87 |
+
st.markdown(recommended_movie_names[9])
|
88 |
+
with st.expander("OverView"):
|
89 |
+
st.write(recommended_movie_overview[9])
|
90 |
+
|
91 |
+
with col3:
|
92 |
+
st.image(recommended_movie_posters[2])
|
93 |
+
st.markdown(recommended_movie_names[2])
|
94 |
+
with st.expander("OverView"):
|
95 |
+
st.write(recommended_movie_overview[2])
|
96 |
+
|
97 |
+
st.image(recommended_movie_posters[6])
|
98 |
+
st.markdown(recommended_movie_names[6])
|
99 |
+
with st.expander("OverView"):
|
100 |
+
st.write(recommended_movie_overview[6])
|
101 |
+
|
102 |
+
st.image(recommended_movie_posters[10])
|
103 |
+
st.markdown(recommended_movie_names[10])
|
104 |
+
with st.expander("OverView"):
|
105 |
+
st.write(recommended_movie_overview[10])
|
106 |
+
|
107 |
+
with col4:
|
108 |
+
st.image(recommended_movie_posters[3])
|
109 |
+
st.markdown(recommended_movie_names[3])
|
110 |
+
with st.expander("OverView"):
|
111 |
+
st.write(recommended_movie_overview[3])
|
112 |
+
|
113 |
+
st.image(recommended_movie_posters[7])
|
114 |
+
st.markdown(recommended_movie_names[7])
|
115 |
+
with st.expander("OverView"):
|
116 |
+
st.write(recommended_movie_overview[7])
|
117 |
+
|
118 |
+
st.image(recommended_movie_posters[11])
|
119 |
+
st.markdown(recommended_movie_names[11])
|
120 |
+
with st.expander("OverView"):
|
121 |
+
st.write(recommended_movie_overview[11])
|
122 |
+
st.sidebar.markdown("Made by Uday Singh")
|
movie_list.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:24cf160e196ce93c871caf36bcb5d1b1ee16ba5b6ad20f44a6ac40556a4bf605
|
3 |
+
size 53612081
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pillow
|
3 |
+
scipy
|
4 |
+
scikit-learn==1.0.2
|
5 |
+
pandas==1.3.5
|
6 |
+
numpy==1.21.6
|
tfidf_matrix.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8fdc5ad0bec25dad6f3c948c137a67b01506566f8efbaf0eebd44dbe30e514a0
|
3 |
+
size 20298550
|