-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
73 lines (51 loc) · 1.99 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import streamlit as st
import pickle
import requests
from PIL import Image
import config
def fetch_info(movie_id):
response=requests.get('https://api.themoviedb.org/3/movie/{}?api_key={}'.format(movie_id,config.api_key))
data=response.json()
images="https://image.tmdb.org/t/p/w500"+data['poster_path']
desc=data['overview']
name=data['original_title']
return images,desc,name
cosine_sim=pickle.load(open('pickle/cosine.pkl','rb'))
#recommendation function
def get_recommendations(title,cosine_sim=cosine_sim):
#index of the movie
idx=indices[title]
#pairwise similarity scores of all movies with the movie
sim_scores=list(enumerate(cosine_sim[idx]))
#sort the sim_scores and taking the top 10 movies
sim_scores=sorted(sim_scores,key=lambda x:x[1],reverse=True) #sorted on the basis of the element on index 1
sim_scores=sim_scores[1:11]
movie_indices=[i[0] for i in sim_scores]
movie_name=movie_list_df['title_x'].iloc[movie_indices]
movie_id=movie_list_df['id'].iloc[movie_indices]
#return top 10 movies
movie_poster=[fetch_info(id) for id in movie_id]
return movie_poster
#fecting movies poster and discription
#importing movie details
movie_list_df= pickle.load(open('pickle/movie_name.pkl','rb'))
movie_list=movie_list_df['title_x'].values
#index of the movie
indices=pickle.load(open('pickle/indices.pkl','rb'))
#streamlit UI
st.title('Movie Recommender System')
selected_movie = st.selectbox(
'Type movie/select movie name',
movie_list)
with open('style.css') as f:
st.markdown(f'<style>{f.read()}</style>',unsafe_allow_html=True)
if st.button('Recommend me !'):
list_of_rec=get_recommendations(selected_movie)
for i in list_of_rec:
col1,col2=st.columns(2)
with col1:
st.image(i[0],width=150)
st.write(i[2])
with col2:
st.write(i[1])
#st.write(desc[i])