mudit68 commited on
Commit
780fd60
·
verified ·
1 Parent(s): 627f63a

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +58 -0
  2. movies.pkl +3 -0
  3. similarity_matrix.pkl +3 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import requests
4
+ from dotenv import load_dotenv
5
+ import os
6
+
7
+ load_dotenv()
8
+ api_key = os.getenv("API_KEY")
9
+
10
+ movies_list = pickle.load(open('movies.pkl','rb'))
11
+ similarity = pickle.load(open('similarity_matrix.pkl','rb'))
12
+ all_movies = movies_list['title'].values
13
+
14
+ def fetch_poster(id):
15
+ response = requests.get(f"https://api.themoviedb.org/3/movie/{id}?api_key={api_key}&language=en-US")
16
+ data = response.json()
17
+ if data['poster_path']:
18
+ return "http://image.tmdb.org/t/p/w500/"+data['poster_path']
19
+ return "https://www.kingsporttn.gov/wp-content/uploads/Image-Not-Available.jpg"
20
+
21
+
22
+ def recommend(movie):
23
+ recommended_movie = []
24
+ recommended_movie_poster = []
25
+ index = movies_list[movies_list['title']==movie].index[0]
26
+ movieList = sorted(list(enumerate(similarity[index])),reverse=True,key=lambda x:x[1])[1:6]
27
+ for i in movieList:
28
+ movie_id = movies_list.loc[i[0]].id
29
+
30
+ poster_path = fetch_poster(movie_id)
31
+ recommended_movie.append(movies_list.loc[i[0]].title)
32
+ recommended_movie_poster.append(poster_path)
33
+ return recommended_movie,recommended_movie_poster
34
+
35
+ st.title('Movie Recommendation System')
36
+ movieName = st.selectbox('Enter the movie',all_movies)
37
+ if st.button('Recommend'):
38
+ st.write('You might like:')
39
+ recommendations,posters = recommend(movieName)
40
+
41
+ col1, col2, col3, col4, col5 = st.columns(5)
42
+
43
+ with col1:
44
+ st.text(recommendations[0])
45
+ st.image(posters[0])
46
+ with col2:
47
+ st.text(recommendations[1])
48
+ st.image(posters[1])
49
+ with col3:
50
+ st.text(recommendations[2])
51
+ st.image(posters[2])
52
+ with col4:
53
+ st.text(recommendations[3])
54
+ st.image(posters[3])
55
+ with col5:
56
+ st.text(recommendations[4])
57
+ st.image(posters[4])
58
+
movies.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f37363b31c6c28a88316b6599fd89e0e1738d0ded1d7dc7e4263ddf82c69d955
3
+ size 2578161
similarity_matrix.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc7b17503b6ca7bb7985087bb1ae451062bb101c481e0cc8879bb8e4ca2e13a9
3
+ size 184935075