Spaces:
Sleeping
Sleeping
first commit
Browse files- main.py +55 -0
- requirements.txt +0 -0
main.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import pandas as pd
|
4 |
+
import requests
|
5 |
+
|
6 |
+
def fetch_poster(movie_id):
|
7 |
+
data = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=3da50835eefad1461468d6eedd91edf7&language=en-US'.format(movie_id))
|
8 |
+
data = data.json()
|
9 |
+
return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
|
10 |
+
|
11 |
+
def recommend(movie):
|
12 |
+
movie_index = movies[movies['title'] == movie].index[0]
|
13 |
+
distances = similarity[movie_index]
|
14 |
+
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
|
15 |
+
|
16 |
+
recommended_movies = []
|
17 |
+
recommended_movies_posters = []
|
18 |
+
for i in movies_list:
|
19 |
+
movie_id = movies.iloc[i[0]].movie_id
|
20 |
+
recommended_movies.append(movies.iloc[i[0]].title)
|
21 |
+
recommended_movies_posters.append(fetch_poster(movie_id))
|
22 |
+
return recommended_movies,recommended_movies_posters
|
23 |
+
|
24 |
+
movies_dict = pickle.load(open('movies.pkl','rb'))
|
25 |
+
movies = pd.DataFrame(movies_dict)
|
26 |
+
|
27 |
+
similarity = pickle.load(open('similarity.pkl','rb'))
|
28 |
+
|
29 |
+
st.title('Movie Recommender System')
|
30 |
+
|
31 |
+
selected_movie_name = st.selectbox('Name of Movies', movies['title'].values)
|
32 |
+
|
33 |
+
if st.button('Recommend'):
|
34 |
+
names,posters = recommend(selected_movie_name)
|
35 |
+
col1, col2, col3, col4 ,col5 = st.columns(5)
|
36 |
+
|
37 |
+
with col1:
|
38 |
+
st.text(names[0])
|
39 |
+
st.image(posters[0])
|
40 |
+
|
41 |
+
with col2:
|
42 |
+
st.text(names[1])
|
43 |
+
st.image(posters[1])
|
44 |
+
|
45 |
+
with col3:
|
46 |
+
st.text(names[2])
|
47 |
+
st.image(posters[2])
|
48 |
+
|
49 |
+
with col4:
|
50 |
+
st.text(names[3])
|
51 |
+
st.image(posters[3])
|
52 |
+
|
53 |
+
with col5:
|
54 |
+
st.text(names[4])
|
55 |
+
st.image(posters[4])
|
requirements.txt
ADDED
Binary file (1.66 kB). View file
|
|