bhavyagiri commited on
Commit
225e0eb
1 Parent(s): f44d37b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %%writefile movie_recommendation_app.py
2
+
3
+ import pickle
4
+ import streamlit as st
5
+ from sklearn.metrics.pairwise import cosine_similarity
6
+ from PIL import Image
7
+
8
+ @st.cache
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 pairwsie 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.image(image)
44
+
45
+ st.markdown('You might have wondered sometime or at some point that how do platforms like Netflix or AmazonPrime Video are able to recommend us TV shows or movies, what kind of an algorithm do these websites use to recommend us movies. Well as complicated or difficult as it might seem this is simply just a mixture of some machine learning algorithms with some Natural Language Processing. ')
46
+ st.markdown('There are two main techniques used in recommendation system, known as content-based filtering and collaborative filtering')
47
+ st.markdown('For this project I have used Content Based Recommendation System, It uses attributes such as genre, director, description, actors, etc. for movies, to make suggestions for the users. The intuition behind this sort of recommendation system is that if a user liked a particular movie or show, he/she might like a movie or a show similar to it.')
48
+
49
+ df1 = pickle.load(open('movie_list.pkl ', 'rb'))
50
+ tfidf_matrix = pickle.load(open('tfidf_matrix.pkl ', 'rb'))
51
+
52
+ movies_list = df1['title'].values
53
+ selected_movie = st.selectbox('Type and Choose The Movie',movies_list)
54
+
55
+ if st.button('Show Recommendation'):
56
+ poster,recommended_movie_names,recommended_movie_posters,recommended_movie_overview = get_recommendation(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])