isurulkh commited on
Commit
b3f2cbc
1 Parent(s): b03c56b

Upload 5 files

Browse files
Models/movies_list.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a49e245df2f07650b0636368563395731468f2fecf5711e41efcf03f7e94b992
3
+ size 3243620
Models/similarity.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f201811c220c7a2869c375cc3619929fe969d76795330ffd9148b12d87c0f51
3
+ size 800000163
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import requests
4
+
5
+ # Function to load movie data and similarity scores
6
+ @st.cache_data
7
+ def load_data():
8
+ movies = pickle.load(open("Models/movies_list.pkl", 'rb'))
9
+ similarity = pickle.load(open("Models/similarity.pkl", 'rb'))
10
+ return movies, similarity
11
+
12
+ # Function to fetch movie posters,
13
+ @st.cache_data
14
+ def fetch_poster(movie_id):
15
+ url = f"https://api.themoviedb.org/3/movie/{movie_id}?api_key=f99f126bfd58ba9b4aa8a3e6db301b6e&language=en-US"
16
+ data = requests.get(url).json()
17
+ poster_path = data.get('poster_path')
18
+ full_path = f"https://image.tmdb.org/t/p/w500/{poster_path}"
19
+ return full_path
20
+
21
+ # Function to recommend movies based on the similarity scores
22
+ def recommend(movie):
23
+ index = movies[movies['title'] == movie].index[0]
24
+ distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
25
+ recommended_movies = []
26
+ recommended_posters = []
27
+ for i in distances[1:6]:
28
+ movie_id = movies.iloc[i[0]].id
29
+ recommended_movies.append(movies.iloc[i[0]].title)
30
+ recommended_posters.append(fetch_poster(movie_id))
31
+ return recommended_movies, recommended_posters
32
+
33
+ # Load movies and similarity data
34
+ movies, similarity = load_data()
35
+
36
+ # Streamlit UI
37
+ st.title("Movie Recommender System")
38
+
39
+ # Dynamic movie selection with autocomplete feature
40
+ movie_list = movies['title'].values
41
+ selected_movie = st.selectbox("Type or select a movie from the dropdown", movie_list)
42
+
43
+ if st.button("Show Recommendations"):
44
+ recommended_movie_names, recommended_movie_posters = recommend(selected_movie)
45
+
46
+ # Displaying recommendations in a more visually appealing manner
47
+ cols = st.columns(5)
48
+ for i, (movie_name, movie_poster) in enumerate(zip(recommended_movie_names, recommended_movie_posters)):
49
+ with cols[i % 5]:
50
+ st.image(movie_poster, caption=movie_name, use_column_width=True)
51
+
52
+ st.markdown("""
53
+ <style>
54
+ /* Custom CSS for improving the UI/UX of the Streamlit app */
55
+ .streamlit-container {
56
+ margin-top: 20px;
57
+ }
58
+ .stButton>button {
59
+ width: 100%;
60
+ border-radius: 20px;
61
+ border: 1px solid #4CAF50;
62
+ background-color: #4CAF50;
63
+ color: white;
64
+ padding: 10px 24px;
65
+ cursor: pointer;
66
+ font-size: 18px;
67
+ }
68
+ .stButton>button:hover {
69
+ background-color: #45a049;
70
+ }
71
+ </style>
72
+ """, unsafe_allow_html=True)
movie_helpers.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ def fetch_poster(movie_id):
4
+ url = f"https://api.themoviedb.org/3/movie/{movie_id}?api_key=f99f126bfd58ba9b4aa8a3e6db301b6e&language=en-US"
5
+ data = requests.get(url).json()
6
+ poster_path = data['poster_path']
7
+ full_path = f"https://image.tmdb.org/t/p/w500/{poster_path}"
8
+ return full_path
9
+
10
+ def recommend(movie, movies, similarity):
11
+ index = movies[movies['title'] == movie].index[0]
12
+ distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
13
+ recommended_movies = []
14
+ recommended_posters = []
15
+ for i in distances[1:8]: # Get top 5 recommendations
16
+ movie_id = movies.iloc[i[0]].id
17
+ recommended_movies.append(movies.iloc[i[0]].title)
18
+ recommended_posters.append(fetch_poster(movie_id))
19
+ return recommended_movies, recommended_posters
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ h2o_wave
2
+ pandas
3
+ numpy
4
+ requests
5
+ gdown