-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
355 lines (228 loc) · 7.2 KB
/
app.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#importing dependencies
import streamlit as st
import pickle
import pandas as pd
import requests
import random
#set the page configuration
st.set_page_config(page_title="Movie Recommendation System",page_icon=":tada:",layout="wide")
@st.cache(allow_output_mutation=True)
# making a dummy function (not required)
def ob():
pass
#importing the dataframe and similarity matrix
movie_dict=pickle.load(open("movie_dict.pkl","rb"))
movie=pd.DataFrame(movie_dict)
similarity=pickle.load(open("similarity.pkl","rb"))
#creating a function to import css style file
def local_css(filename):
with open(filename) as f:
st.markdown(f"<style>{f.read()}</style>",unsafe_allow_html=True)
local_css("style\style.css")
#creating a function to featch the movie image from movie id
def fetch_data(movie_id):
response=requests.get("https://api.themoviedb.org/3/movie/{}?api_key=c1a0fd94adf3e2100677929be4361d07&language=en-U".format(movie_id))
data=response.json()
return "https://image.tmdb.org/t/p/w500/"+data["poster_path"]
#creating a fuction to recommend movies based on selected movies
def recommend(name):
index = movie[movie['title'] == name].index[0]
distances = sorted(list(enumerate(similarity[index])),reverse=True,key = lambda x: x[1])
recommended_movies=[]
recommended_poster=[]
for i in distances[1:16]:
recommended_movies.append(movie.iloc[i[0]].title)
recommended_poster.append(fetch_data(movie.iloc[i[0]].movie_id))
return recommended_movies,recommended_poster
#Header section of webpage
with st.container():
st.title("Movie Recommendation System")
#select box of webpage
option = st.selectbox(
'How would you like to be contacted?',
movie["title"].values)
#After selection recommend movie name along with poster
if st.button('Recommend'):
with st.spinner('Loading ...'):
name,poster=recommend(option)
col1,col2,col3,col4,col5 = st.columns(5)
with col1:
st.image(poster[0])
st.text(name[0])
with col2:
st.image(poster[1])
st.text(name[1])
with col3:
st.image(poster[2])
st.text(name[2])
with col4:
st.image(poster[3])
st.text(name[3])
with col5:
st.image(poster[4])
st.text(name[4])
with col1:
st.image(poster[5])
st.text(name[5])
with col2:
st.image(poster[6])
st.text(name[6])
with col3:
st.image(poster[7])
st.text(name[7])
with col4:
st.image(poster[8])
st.text(name[8])
with col5:
st.image(poster[9])
st.text(name[9])
with col1:
st.image(poster[10])
st.text(name[10])
with col2:
st.image(poster[11])
st.text(name[11])
with col3:
st.image(poster[12])
st.text(name[12])
with col4:
st.image(poster[13])
st.text(name[13])
with col5:
st.image(poster[14])
st.text(name[14])
#If movie name is not selected then it will show some random movies
else:
with st.spinner('Loading ...'):
random_number = []
random_poster = []
# Set a length of the list to 10
for i in range(0,30):
# any random numbers from 0 to 1000
random_number.append(random.randint(0, 4804))
random_movies = []
random_id = []
for i in random_number:
random_movies.append(movie_dict['title'][i])
for i in random_number:
random_id.append(movie_dict['movie_id'][i])
for i in random_id:
random_poster.append(fetch_data(i))
col1,col2,col3,col4,col5 = st.columns(5)
with col1:
st.image(random_poster[0])
st.text(random_movies[0])
with col2:
st.image(random_poster[1])
st.text(random_movies[1])
with col3:
st.image(random_poster[2])
st.text(random_movies[2])
with col4:
st.image(random_poster[3])
st.text(random_movies[3])
with col5:
st.image(random_poster[4])
st.text(random_movies[4])
with col1:
st.image(random_poster[5])
st.text(random_movies[5])
with col2:
st.image(random_poster[6])
st.text(random_movies[6])
with col3:
st.image(random_poster[7])
st.text(random_movies[7])
with col4:
st.image(random_poster[8])
st.text(random_movies[8])
with col5:
st.image(random_poster[9])
st.text(random_movies[9])
with col1:
st.image(random_poster[10])
st.text(random_movies[10])
with col2:
st.image(random_poster[11])
st.text(random_movies[11])
with col3:
st.image(random_poster[12])
st.text(random_movies[12])
with col4:
st.image(random_poster[13])
st.text(random_movies[13])
with col5:
st.image(random_poster[14])
st.text(random_movies[14])
with col1:
st.image(random_poster[15])
st.text(random_movies[15])
with col2:
st.image(random_poster[16])
st.text(random_movies[16])
with col3:
st.image(random_poster[17])
st.text(random_movies[17])
with col4:
st.image(random_poster[18])
st.text(random_movies[18])
with col5:
st.image(random_poster[19])
st.text(random_movies[19])
with col1:
st.image(random_poster[20])
st.text(random_movies[20])
with col2:
st.image(random_poster[21])
st.text(random_movies[21])
with col3:
st.image(random_poster[22])
st.text(random_movies[22])
with col4:
st.image(random_poster[23])
st.text(random_movies[23])
with col5:
st.image(random_poster[24])
st.text(random_movies[24])
with col1:
st.image(random_poster[25])
st.text(random_movies[25])
with col2:
st.image(random_poster[26])
st.text(random_movies[26])
with col3:
st.image(random_poster[27])
st.text(random_movies[27])
with col4:
st.image(random_poster[28])
st.text(random_movies[28])
with col5:
st.image(random_poster[29])
st.text(random_movies[29])
# Footer part
#Making the submit form to submit quires
with st.container():
st.write("---")
st.subheader("Get in contect with me")
st.write("##")
contact_form="""<form action="https://formsubmit.co/abhijeetmaharana77@gmail.com" method="POST">
<input type="hidden" name="_captcha" value="false">
<input type="text" name="name" placeholder="Your name" required>
<input type="email" name="email" placeholder="Your e-mail" required>
<textarea name="message" placeholder="Your message" required></textarea>
<button type="submit">Send</button>
</form>"""
left_column,right_column=st.columns(2)
with left_column:
st.markdown(contact_form,unsafe_allow_html=True)
#Writing the term condition in footer part only for style purpose(dummy type)
with st.container():
st.write("---")
st.write("##")
col1,col2,col3 = st.columns(3)
with col1:
st.write("2023 © Movie-Recommendation System | All Rights Reserved.")
with col3:
st.write(" Privacy Policy")
st.write(" Terms and Conditions")
st.write(" Copyright")