thisisashwinraj commited on
Commit
7634d2f
1 Parent(s): 94e3fc1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Import required Libraries
2
+ import streamlit as st
3
+ import pickle
4
+ import pandas as pd
5
+ import requests
6
+
7
+ #Hide Streamlit Menu and Default Footer
8
+ hide_menu_style = """
9
+ <style>
10
+ #MainMenu {visibility: hidden;}
11
+ footer {visibility: hidden;}
12
+ </style>
13
+ """
14
+ st.markdown(hide_menu_style, unsafe_allow_html=True)
15
+
16
+ #Fetch posters from TMDb Database
17
+ def fetch_poster(movie_id):
18
+ response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=[TMDb-API-KEY]&language=en-US'.format(movie_id))
19
+ data = response.json()
20
+ return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
21
+
22
+ #Recommend movies based on content
23
+ def recommend(movie):
24
+ movie_index = movies[movies['original_title'] == movie].index[0]
25
+ distances = similarity[movie_index]
26
+ movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
27
+
28
+ recommended_movies = []
29
+ recommended_movies_poster = []
30
+ for i in movies_list:
31
+ movie_id = movies.iloc[i[0]].id
32
+ recommended_movies.append(movies.iloc[i[0]].original_title)
33
+ recommended_movies_poster.append(fetch_poster(movie_id))
34
+ return recommended_movies,recommended_movies_poster
35
+
36
+ #Frontend Design for StreamLit WebApp Sidebar
37
+ st.sidebar.subheader(" ")
38
+
39
+ st.sidebar.subheader("Technology:")
40
+ st.sidebar.text("Natural Language Processing")
41
+
42
+ st.sidebar.subheader("Developed By")
43
+ st.sidebar.text("Ashwin Raj, Student at UCEK")
44
+
45
+ movies_dict = pickle.load(open('pickle/movie_dict.pkl','rb'))
46
+ movies = pd.DataFrame(movies_dict)
47
+
48
+ similarity = pickle.load(open('pickle/similarity.pkl','rb'))
49
+
50
+ #Frontend Hero Section
51
+ st.title("Movie Recommender System")
52
+
53
+ selected_movie_name = st.selectbox(
54
+ 'Select a movie to recommend',
55
+ movies['original_title'].values)
56
+
57
+ #Output Recommendations with Posters
58
+ if st.button('Recommend'):
59
+ name, posters = recommend(selected_movie_name)
60
+
61
+ col1, col2, col3, col4, col5 = st.columns(5)
62
+ with col1:
63
+ st.text(name[0])
64
+ st.image(posters[0])
65
+ with col2:
66
+ st.text(name[1])
67
+ st.image(posters[1])
68
+ with col3:
69
+ st.text(name[2])
70
+ st.image(posters[2])
71
+ with col4:
72
+ st.text(name[3])
73
+ st.image(posters[3])
74
+ with col5:
75
+ st.text(name[4])
76
+ st.image(posters[4])