-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMRS.py
48 lines (37 loc) · 1.29 KB
/
MRS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import pandas as pd
import pickle
import requests
def fetch_p(m_id):
url = "https://api.themoviedb.org/3/movie/{}?api_key=7c1b29091b8ce2b0516521ab48c89744&language=en-USb48c89744/285".format(m_id)
data = requests.get(url)
data=data.json()
p_path=data['poster_path']
p_path="http://image.tmdb.org/t/p/w500"+p_path
return p_path
similarity=pickle.load(open("similarity.pkl",'rb'))
def recommend(movie):
index = movies[movies['title'] == movie].index[0]
distances = sorted(list(enumerate(similarity[index])),reverse=True,key = lambda x: x[1])
return distances
st.title("Movie Recommendation System")
movie_dict=pickle.load(open('movies.pkl','rb'))
movies=pd.DataFrame(movie_dict)
option = st.selectbox(
'Movies',
(movies['title'].values))
movie_rec=[]
if st.button('Recommend'):
# recommend() function return list of distance between each movie
movie_rec=recommend(option)
st.subheader('Top 5 :blue[movies] are :sunglasses: \n\n')
col = st.columns(5)
k=0;
for i in movie_rec[:5]:
with col[k]:
j=k+1
st.text(str(j)+": "+ movies.iloc[i[0]].title)
img_path=fetch_p(movies.iloc[i[0]].movie_id)
st.write("\n")
st.image(img_path)
k+=1