forked from KAN-Team/Movies-AI-Recommender-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.py
97 lines (84 loc) · 3.17 KB
/
interface.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import streamlit as st
import pandas as pd
import requests
import pickle
# =========================================
def get_movie_poster(movie_id):
response = requests.get('https://api.themoviedb.org/3/movie/{'
'}?api_key=042fd2989c8e20e75eb1431a4d9f880c&language=en-US'.format(movie_id))
data = response.json()
return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
# Re-implement the 'recommend' function
def recommend(movie_name):
movie_idx = movies[movies['title'] == movie_name].index[0]
distances = nlp_model[movie_idx]
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda i: i[1])[0:11]
movies_recommended_list = []
movies_recommended_posters = []
for movie in movies_list:
movie_id = movies.iloc[movie[0]].movie_id
movies_recommended_list.append(movies.iloc[movie[0]].title)
movies_recommended_posters.append(get_movie_poster(movie_id))
return movies_recommended_list, movies_recommended_posters
# =========================================
# Loading Movies Data...
movies_dict = pickle.load(open('movies_dict.pkl', 'rb'))
movies = pd.DataFrame(movies_dict)
nlp_model = pickle.load(open('nlp_model.pkl', 'rb'))
# Building Widgets...
st.set_page_config(layout="wide")
# Page Title
colT1, colT2 = st.columns([5, 10])
with colT2:
st.title('Movies AI-Recommender')
# Movies Select Box
selected_movie_name = st.selectbox('Pick a Movie to get Similar Movies!', movies['title'].values)
# Recommend Button
if st.button('Recommend 10 Similar Movies'):
names, posters = recommend(selected_movie_name)
st.subheader(names[0])
st.image(posters[0], width=180)
col1, col2, col3 = st.columns(3)
with col1:
with st.form(key='f1'):
st.subheader(names[1])
st.image(posters[1])
st.form_submit_button("See More")
with st.form(key='f4'):
st.subheader(names[4])
st.image(posters[4])
st.form_submit_button("See More")
with st.form(key='f7'):
st.subheader(names[7])
st.image(posters[7])
st.form_submit_button("See More")
with st.form(key='f10'):
st.subheader(names[10])
st.image(posters[10])
st.form_submit_button("See More")
with col2:
with st.form(key='f2'):
st.subheader(names[2])
st.image(posters[2])
st.form_submit_button("See More")
with st.form(key='f5'):
st.subheader(names[5])
st.image(posters[5])
st.form_submit_button("See More")
with st.form(key='f8'):
st.subheader(names[8])
st.image(posters[8])
st.form_submit_button("See More")
with col3:
with st.form(key='f3'):
st.subheader(names[3])
st.image(posters[3])
st.form_submit_button("See More")
with st.form(key='f6'):
st.subheader(names[6])
st.image(posters[6])
st.form_submit_button("See More")
with st.form(key='f9'):
st.subheader(names[9])
st.image(posters[9])
st.form_submit_button("See More")