Spaces:
Runtime error
Runtime error
Shrikrishna
commited on
Commit
•
583d3ee
1
Parent(s):
fce58be
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import pickle
|
3 |
import requests
|
|
|
4 |
|
5 |
footer="""<style>
|
6 |
a:link , a:visited{
|
@@ -36,6 +37,26 @@ def fetch_poster(movie_id):
|
|
36 |
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
|
37 |
return full_path
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def recommend(movie):
|
40 |
index = movies[movies['title'] == movie].index[0]
|
41 |
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
|
@@ -54,6 +75,12 @@ st.title("Movie Recommender System")
|
|
54 |
|
55 |
movies = pickle.load(open('movie_list.pkl','rb'))
|
56 |
similarity = pickle.load(open('similarity.pkl','rb'))
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
movie_list = movies['title'].values
|
59 |
option_selected = st.selectbox(
|
@@ -64,6 +91,7 @@ option_selected = st.selectbox(
|
|
64 |
if st.button('Show Recommendation'):
|
65 |
recommended_movie_names, recommended_movie_posters = recommend(option_selected)
|
66 |
col1, col2, col3, col4, col5 = st.columns(5)
|
|
|
67 |
with col1:
|
68 |
st.image(recommended_movie_posters[0], caption=recommended_movie_names[0])
|
69 |
with col2:
|
@@ -76,6 +104,73 @@ if st.button('Show Recommendation'):
|
|
76 |
with col5:
|
77 |
st.image(recommended_movie_posters[4], caption=recommended_movie_names[4])
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|
81 |
st.markdown(footer,unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
import pickle
|
3 |
import requests
|
4 |
+
import pandas as pd
|
5 |
|
6 |
footer="""<style>
|
7 |
a:link , a:visited{
|
|
|
37 |
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
|
38 |
return full_path
|
39 |
|
40 |
+
def get_popular(qualified):
|
41 |
+
top_5 = qualified.head(5)
|
42 |
+
return top_5
|
43 |
+
|
44 |
+
|
45 |
+
def top_genre_based_movies(genre, percentile=0.95):
|
46 |
+
df = genre_df[genre_df['genres'].str.contains(genre)]
|
47 |
+
vote_counts = df['vote_count'].astype('int')
|
48 |
+
vote_averages = df['vote_average'].astype('int')
|
49 |
+
C = vote_averages.mean()
|
50 |
+
m = vote_counts.quantile(percentile)
|
51 |
+
qualified = df[(df['vote_count'] >= m)][['movie_id', 'title', 'vote_count', 'vote_average', 'genres']]
|
52 |
+
qualified['vote_count'] = qualified['vote_count'].astype('int')
|
53 |
+
qualified['vote_average'] = qualified['vote_average'].astype('int')
|
54 |
+
qualified['wr'] = qualified.apply(
|
55 |
+
lambda x: (x['vote_count'] / (x['vote_count'] + m) * x['vote_average']) + (m / (m + x['vote_count']) * C),
|
56 |
+
axis=1)
|
57 |
+
qualified = qualified.sort_values('wr', ascending=False).head(250)
|
58 |
+
return qualified
|
59 |
+
|
60 |
def recommend(movie):
|
61 |
index = movies[movies['title'] == movie].index[0]
|
62 |
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
|
|
|
75 |
|
76 |
movies = pickle.load(open('movie_list.pkl','rb'))
|
77 |
similarity = pickle.load(open('similarity.pkl','rb'))
|
78 |
+
all_movies = pickle.load(open('movies_df.pkl','rb'))
|
79 |
+
top_popular = pickle.load(open('top_popular.pkl','rb'))
|
80 |
+
|
81 |
+
s = all_movies.apply(lambda x: pd.Series(x['genres']),axis=1).stack().reset_index(level=1, drop=True)
|
82 |
+
s.name = 'genres'
|
83 |
+
genre_df = all_movies.drop('genres', axis=1).join(s)
|
84 |
|
85 |
movie_list = movies['title'].values
|
86 |
option_selected = st.selectbox(
|
|
|
91 |
if st.button('Show Recommendation'):
|
92 |
recommended_movie_names, recommended_movie_posters = recommend(option_selected)
|
93 |
col1, col2, col3, col4, col5 = st.columns(5)
|
94 |
+
st.header("Movies Based on Movie Content: Similar Movies")
|
95 |
with col1:
|
96 |
st.image(recommended_movie_posters[0], caption=recommended_movie_names[0])
|
97 |
with col2:
|
|
|
104 |
with col5:
|
105 |
st.image(recommended_movie_posters[4], caption=recommended_movie_names[4])
|
106 |
|
107 |
+
st.header("Top Popular Movies")
|
108 |
+
popular = []
|
109 |
+
for row in top_popular_movies.loc[:,['title','movie_id']].values:
|
110 |
+
popular.append(row)
|
111 |
+
col6, col7, col8, col9, col10 = st.columns(5)
|
112 |
+
with col6:
|
113 |
+
full_path = fetch_poster(popular[0][1])
|
114 |
+
st.image(full_path, caption=popular[0][0])
|
115 |
+
with col7:
|
116 |
+
full_path = fetch_poster(popular[1][1])
|
117 |
+
st.image(full_path, caption=popular[1][0])
|
118 |
+
with col8:
|
119 |
+
full_path = fetch_poster(popular[2][1])
|
120 |
+
st.image(full_path, caption=popular[2][0])
|
121 |
+
with col9:
|
122 |
+
full_path = fetch_poster(popular[3][1])
|
123 |
+
st.image(full_path, caption=popular[3][0])
|
124 |
+
with col10:
|
125 |
+
full_path = fetch_poster(popular[4][1])
|
126 |
+
st.image(full_path, caption=popular[4][0])
|
127 |
+
|
128 |
+
|
129 |
+
st.header("Top Romantic Movies")
|
130 |
+
top_gener_based = top_genre_based_movies('Romance').head(5)
|
131 |
+
genre_popular = []
|
132 |
+
for row in top_gener_based.loc[:, ['title', 'movie_id']].values:
|
133 |
+
genre_popular.append(row)
|
134 |
+
col11, col12, col13, col14, col15 = st.columns(5)
|
135 |
+
with col11:
|
136 |
+
full_path = fetch_poster(genre_popular[0][1])
|
137 |
+
st.image(full_path, caption=genre_popular[0][0])
|
138 |
+
with col12:
|
139 |
+
full_path = fetch_poster(genre_popular[1][1])
|
140 |
+
st.image(full_path, caption=genre_popular[1][0])
|
141 |
+
with col13:
|
142 |
+
full_path = fetch_poster(genre_popular[2][1])
|
143 |
+
st.image(full_path, caption=genre_popular[2][0])
|
144 |
+
with col14:
|
145 |
+
full_path = fetch_poster(genre_popular[3][1])
|
146 |
+
st.image(full_path, caption=genre_popular[3][0])
|
147 |
+
with col15:
|
148 |
+
full_path = fetch_poster(genre_popular[4][1])
|
149 |
+
st.image(full_path, caption=genre_popular[4][0])
|
150 |
+
|
151 |
+
st.header("Top Action Movies")
|
152 |
+
top_gener_based = top_genre_based_movies('Action').head(5)
|
153 |
+
genre_popular = []
|
154 |
+
for row in top_gener_based.loc[:, ['title', 'movie_id']].values:
|
155 |
+
genre_popular.append(row)
|
156 |
+
col16, col17, col18, col19, col20 = st.columns(5)
|
157 |
+
with col16:
|
158 |
+
full_path = fetch_poster(genre_popular[0][1])
|
159 |
+
st.image(full_path, caption=genre_popular[0][0])
|
160 |
+
with col17:
|
161 |
+
full_path = fetch_poster(genre_popular[1][1])
|
162 |
+
st.image(full_path, caption=genre_popular[1][0])
|
163 |
+
with col18:
|
164 |
+
full_path = fetch_poster(genre_popular[2][1])
|
165 |
+
st.image(full_path, caption=genre_popular[2][0])
|
166 |
+
with col19:
|
167 |
+
full_path = fetch_poster(genre_popular[3][1])
|
168 |
+
st.image(full_path, caption=genre_popular[3][0])
|
169 |
+
with col20:
|
170 |
+
full_path = fetch_poster(genre_popular[4][1])
|
171 |
+
st.image(full_path, caption=genre_popular[4][0])
|
172 |
+
|
173 |
+
|
174 |
|
175 |
|
176 |
st.markdown(footer,unsafe_allow_html=True)
|