Commit
·
9aaf61d
1
Parent(s):
2f04850
Upload 14 files
Browse files- Movie_Recommendation_app.py +214 -0
- chunk_1.pkl +3 -0
- chunk_10.pkl +3 -0
- chunk_11.pkl +3 -0
- chunk_2.pkl +3 -0
- chunk_3.pkl +3 -0
- chunk_4.pkl +3 -0
- chunk_5.pkl +3 -0
- chunk_6.pkl +3 -0
- chunk_7.pkl +3 -0
- chunk_8.pkl +3 -0
- chunk_9.pkl +3 -0
- movie_list.pkl +3 -0
- requirements (2).txt +8 -0
Movie_Recommendation_app.py
ADDED
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import pickle
|
3 |
+
import streamlit as st
|
4 |
+
import requests
|
5 |
+
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
+
from tmdbv3api import TMDb
|
8 |
+
import json
|
9 |
+
import requests
|
10 |
+
from tmdbv3api import Movie
|
11 |
+
tmdb = TMDb()
|
12 |
+
tmdb.api_key = '8265bd1679663a7ea12ac168da84d2e8&language=en-US'
|
13 |
+
|
14 |
+
page_bg_img = '''
|
15 |
+
<style>
|
16 |
+
[data-testid="stAppViewContainer"]{
|
17 |
+
background-image: url("https://www.vshsolutions.com/wp-content/uploads/2020/02/recommender-system-for-movie-recommendation.jpg");
|
18 |
+
background-size: cover;
|
19 |
+
}
|
20 |
+
|
21 |
+
[data-testid="stHeader"]{
|
22 |
+
background-color: rgba(0,0,0,0);
|
23 |
+
}
|
24 |
+
</style>
|
25 |
+
'''
|
26 |
+
st.markdown(page_bg_img, unsafe_allow_html=True)
|
27 |
+
hide_menu_style = """
|
28 |
+
<style>
|
29 |
+
#MainMenu {visibility:hidden;}
|
30 |
+
footer {visibility: hidden;}
|
31 |
+
</style>
|
32 |
+
"""
|
33 |
+
st . markdown (hide_menu_style ,unsafe_allow_html=True)
|
34 |
+
|
35 |
+
tmdb_movie = Movie()
|
36 |
+
def get_movie_id(x):
|
37 |
+
result = tmdb_movie.search(x)
|
38 |
+
movie_id = result[0].id
|
39 |
+
return movie_id
|
40 |
+
|
41 |
+
similarity = pickle.load(open('similarity.pkl','rb'))
|
42 |
+
movies = pickle.load(open('movie_list.pkl','rb'))
|
43 |
+
|
44 |
+
def fetch_poster(movie_id):
|
45 |
+
url = "https://api.themoviedb.org/3/movie/{}?api_key={}".format(movie_id,tmdb.api_key)
|
46 |
+
data = requests.get(url)
|
47 |
+
data = data.json()
|
48 |
+
poster_path = data['poster_path']
|
49 |
+
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
|
50 |
+
return full_path
|
51 |
+
|
52 |
+
def recommend(movie):
|
53 |
+
index = movies[movies['movie_title'] == movie].index[0]
|
54 |
+
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
|
55 |
+
recommended_movie_names = []
|
56 |
+
recommended_movie_posters = []
|
57 |
+
for i in distances[1:6]:
|
58 |
+
# fetch the movie poster
|
59 |
+
movie_name = movies.iloc[i[0]].movie_title
|
60 |
+
recommended_movie_posters.append(fetch_poster(get_movie_id(movie_name)))
|
61 |
+
recommended_movie_names.append(movies.iloc[i[0]].movie_title.title())
|
62 |
+
|
63 |
+
return recommended_movie_names,recommended_movie_posters
|
64 |
+
|
65 |
+
st.title(':red[Movie Recommendation System]')
|
66 |
+
|
67 |
+
movie_list = movies['movie_title'].values
|
68 |
+
selected_movie = st.selectbox(":red[Type or select a movie from the dropdown]",movie_list)
|
69 |
+
if st.button('Show Recommendation'):
|
70 |
+
recommended_movie_names,recommended_movie_posters = recommend(selected_movie)
|
71 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
72 |
+
with col1:
|
73 |
+
html_str = f"""
|
74 |
+
<style>
|
75 |
+
p.a {{
|
76 |
+
font: bold {18}px Courier;
|
77 |
+
color: cyan;
|
78 |
+
}}
|
79 |
+
</style>
|
80 |
+
<p class="a">{recommended_movie_names[0]}</p>
|
81 |
+
"""
|
82 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
83 |
+
st.image(recommended_movie_posters[0])
|
84 |
+
|
85 |
+
with col2:
|
86 |
+
html_str = f"""
|
87 |
+
<style>
|
88 |
+
p.a {{
|
89 |
+
font: bold {18}px Courier;
|
90 |
+
color: cyan;
|
91 |
+
}}
|
92 |
+
</style>
|
93 |
+
<p class="a">{recommended_movie_names[1]}</p>
|
94 |
+
"""
|
95 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
96 |
+
st.image(recommended_movie_posters[1])
|
97 |
+
|
98 |
+
with col3:
|
99 |
+
html_str = f"""
|
100 |
+
<style>
|
101 |
+
p.a {{
|
102 |
+
font: bold {18}px Courier;
|
103 |
+
color: cyan;
|
104 |
+
}}
|
105 |
+
</style>
|
106 |
+
<p class="a">{recommended_movie_names[2]}</p>
|
107 |
+
"""
|
108 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
109 |
+
st.image(recommended_movie_posters[2])
|
110 |
+
with col4:
|
111 |
+
html_str = f"""
|
112 |
+
<style>
|
113 |
+
p.a {{
|
114 |
+
font: bold {18}px Courier;
|
115 |
+
color: cyan;
|
116 |
+
}}
|
117 |
+
</style>
|
118 |
+
<p class="a">{recommended_movie_names[3]}</p>
|
119 |
+
"""
|
120 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
121 |
+
st.image(recommended_movie_posters[3])
|
122 |
+
with col5:
|
123 |
+
html_str = f"""
|
124 |
+
<style>
|
125 |
+
p.a {{
|
126 |
+
font: bold {18}px Courier;
|
127 |
+
color: cyan;
|
128 |
+
}}
|
129 |
+
</style>
|
130 |
+
<p class="a">{recommended_movie_names[4]}</p>
|
131 |
+
"""
|
132 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
133 |
+
st.image(recommended_movie_posters[4])
|
134 |
+
|
135 |
+
|
136 |
+
st.markdown(""" <style> .font {
|
137 |
+
font-size:50px ; font-family: 'Cooper Black'; color: #FF9633;}
|
138 |
+
</style> """, unsafe_allow_html=True)
|
139 |
+
st.markdown('<p class="font">You may also like</p>', unsafe_allow_html=True)
|
140 |
+
|
141 |
+
|
142 |
+
# recommended_movie_names,recommended_movie_posters = recommend(selected_movie)
|
143 |
+
suggested_movie_name,suggested_movie_poster = recommend(recommended_movie_names[3].lower())
|
144 |
+
|
145 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
146 |
+
with col1:
|
147 |
+
html_str = f"""
|
148 |
+
<style>
|
149 |
+
p.a {{
|
150 |
+
font: bold {18}px Courier;
|
151 |
+
color: cyan;
|
152 |
+
}}
|
153 |
+
</style>
|
154 |
+
<p class="a">{suggested_movie_name[0]}</p>
|
155 |
+
"""
|
156 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
157 |
+
st.image(suggested_movie_poster[0])
|
158 |
+
|
159 |
+
with col2:
|
160 |
+
html_str = f"""
|
161 |
+
<style>
|
162 |
+
p.a {{
|
163 |
+
font: bold {18}px Courier;
|
164 |
+
color: cyan;
|
165 |
+
}}
|
166 |
+
</style>
|
167 |
+
<p class="a">{suggested_movie_name[1]}</p>
|
168 |
+
"""
|
169 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
170 |
+
st.image(suggested_movie_poster[1])
|
171 |
+
|
172 |
+
with col3:
|
173 |
+
html_str = f"""
|
174 |
+
<style>
|
175 |
+
p.a {{
|
176 |
+
font: bold {18}px Courier;
|
177 |
+
color: cyan;
|
178 |
+
}}
|
179 |
+
</style>
|
180 |
+
<p class="a">{suggested_movie_name[2]}</p>
|
181 |
+
"""
|
182 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
183 |
+
st.image(suggested_movie_poster[2])
|
184 |
+
with col4:
|
185 |
+
html_str = f"""
|
186 |
+
<style>
|
187 |
+
p.a {{
|
188 |
+
font: bold {18}px Courier;
|
189 |
+
color: cyan;
|
190 |
+
}}
|
191 |
+
</style>
|
192 |
+
<p class="a">{suggested_movie_name[3]}</p>
|
193 |
+
"""
|
194 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
195 |
+
st.image(suggested_movie_poster[3])
|
196 |
+
with col5:
|
197 |
+
html_str = f"""
|
198 |
+
<style>
|
199 |
+
p.a {{
|
200 |
+
font: bold {18}px Courier;
|
201 |
+
color: cyan;
|
202 |
+
}}
|
203 |
+
</style>
|
204 |
+
<p class="a">{suggested_movie_name[4]}</p>
|
205 |
+
"""
|
206 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
207 |
+
st.image(suggested_movie_poster[4])
|
208 |
+
|
209 |
+
|
210 |
+
|
211 |
+
|
212 |
+
|
213 |
+
|
214 |
+
|
chunk_1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0f7ee040543dbc5d19113ce7686ea91e1b2fe4de966641a7c11f81e1242570ca
|
3 |
+
size 20941219
|
chunk_10.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c650f71419cfcaf777c2dd4198df609a11e514e7d5f008f744143eb3640ec165
|
3 |
+
size 20941219
|
chunk_11.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a2b241dc6b626e928ae987b2e3a3c9caf5b50b48b2713cb1c27d623829e735da
|
3 |
+
size 20769571
|
chunk_2.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eb0eec35f585580443495219963d1ab9606864195c3419b13f58d8a9c4d32a26
|
3 |
+
size 20941219
|
chunk_3.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6df715ed25bcad5ea636c2334ee429b91439ddc4c7c91b430d2032bdd2a4893a
|
3 |
+
size 20941219
|
chunk_4.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:249a858cf2a0382ab6d8bc89ddbd5d30e88dd57ed33103b1939b584c4c2b16a9
|
3 |
+
size 20941219
|
chunk_5.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fda8b30064af2f7f91a85dfc17086ec6c19be8feec498fe3b74e3e35bf7350e4
|
3 |
+
size 20941219
|
chunk_6.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aa6ae1377d5b93973dd68c638290ea85b769c4fefb6bed7beb24644f20822b41
|
3 |
+
size 20941219
|
chunk_7.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:18b5a7b2f7c06f7c1f82c55785034f7b57493ff6422f284913adf516edf82047
|
3 |
+
size 20941219
|
chunk_8.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7b9c0416357cbd9be68013e5a77d90492d5609c00ef0c6745a3502b124df731d
|
3 |
+
size 20941219
|
chunk_9.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dfaca51556226f74b3dd527d553dfd7585450d09a0e7ed9159a16965aba54368
|
3 |
+
size 20941219
|
movie_list.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:907d0ed05e022da386cecb65d278fc05ab0877c648622b69ff46bb13f8bd20e4
|
3 |
+
size 823960
|
requirements (2).txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit_option_menu == 0.3.2
|
2 |
+
requests==2.28.0
|
3 |
+
streamlit-lottie==0.0.3
|
4 |
+
pickle-mixin==1.0.2
|
5 |
+
times==0.7
|
6 |
+
scikit-learn == 1.0.2
|
7 |
+
streamlit==1.22.0
|
8 |
+
tmdbv3api==1.7.7
|