Rishabh055 commited on
Commit
07a45b2
1 Parent(s): c9e1496

second commit

Browse files
Files changed (2) hide show
  1. Movie Recommender System.ipynb +0 -0
  2. app.py +96 -0
Movie Recommender System.ipynb DELETED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pickle
4
+ import requests
5
+
6
+ def fetch_poster(movie_id):
7
+ url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id)
8
+ data = requests.get(url)
9
+ data = data.json()
10
+ poster_path = data['poster_path']
11
+ full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
12
+ return full_path
13
+
14
+ def recommend(movie):
15
+ movie_index = movies[movies['title'] == movie].index[0]
16
+ distances = similarity[movie_index]
17
+ movies_list = sorted(list(enumerate(distances)), reverse =True,key=lambda x: x[1])[1:6]
18
+
19
+ recommended_movies = []
20
+ recommended_movies_posters = []
21
+ for i in movies_list:
22
+ movie_id = movies.iloc[i[0]].movie_id
23
+ # Help to fetch poster from api
24
+ recommended_movies.append(movies.iloc[i[0]]['title'])
25
+ recommended_movies_posters.append(fetch_poster(movie_id))
26
+ return recommended_movies, recommended_movies_posters
27
+
28
+
29
+ movies = pickle.load(open('movies.pkl','rb'))
30
+ similarity = pickle.load(open('similarity.pkl', 'rb'))
31
+ st.title('Movie Recommendation App')
32
+
33
+ selected_movie = st.selectbox(
34
+ 'Select a movie to get recommendations',
35
+ movies['title'].values)
36
+
37
+ if st.button('Get Recommendations'):
38
+ names,posters = recommend(selected_movie)
39
+
40
+ col1, col2, col3,col4,col5 = st.columns(5)
41
+ with col1:
42
+ st.text(names[0])
43
+ st.image(posters[0])
44
+
45
+ with col2:
46
+ st.text(names[1])
47
+ st.image(posters[1])
48
+
49
+ with col3:
50
+ st.text(names[2])
51
+ st.image(posters[2])
52
+
53
+ with col4:
54
+ st.text(names[3])
55
+ st.image(posters[3])
56
+
57
+ with col5:
58
+ st.text(names[4])
59
+ st.image(posters[4])
60
+
61
+
62
+ hide_streamlit_style = """
63
+ <style>
64
+ #MainMenu {visibility: hidden;}
65
+ footer {visibility: hidden;}
66
+ </style>
67
+ """
68
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
69
+ footer="""<style>
70
+ a:link , a:visited{
71
+ color: yellow;
72
+ background-color: transparent;
73
+ text-decoration: underline;
74
+ }
75
+
76
+ a:hover, a:active {
77
+ color: white;
78
+ # background-color: transparent;
79
+ text-decoration: underline;
80
+ }
81
+
82
+ .footer {
83
+ position: fixed;
84
+ left: 0;
85
+ bottom: 0;
86
+ width: 100%;
87
+ color: white;
88
+ text-align: center;
89
+ text-size: 30px;
90
+ }
91
+ </style>
92
+ <div class="footer">
93
+ <p>Developed ❤ by Rishabh <a style='display: block; text-align: center;' href="https://www.twitter.com/rishabh_55/" target="_blank">Rishabh Rathore</a></p>
94
+ </div>
95
+ """
96
+ st.markdown(footer,unsafe_allow_html=True)