nishantguvvada
commited on
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import requests
|
4 |
+
|
5 |
+
def fetch_poster(movie_id):
|
6 |
+
url = "https://api.themoviedb.org/3/movie/{}?api_key=c7ec19ffdd3279641fb606d19ceb9bb1&language=en-US".format(movie_id)
|
7 |
+
data=requests.get(url)
|
8 |
+
data=data.json()
|
9 |
+
poster_path = data['poster_path']
|
10 |
+
full_path = "https://image.tmdb.org/t/p/w500/"+poster_path
|
11 |
+
return full_path
|
12 |
+
|
13 |
+
movies = pickle.load(open("movies_list.pkl", 'rb'))
|
14 |
+
similarity = pickle.load(open("similarity.pkl", 'rb'))
|
15 |
+
movies_list=movies['title'].values
|
16 |
+
|
17 |
+
st.header("Movie Recommender System")
|
18 |
+
|
19 |
+
import streamlit.components.v1 as components
|
20 |
+
|
21 |
+
imageCarouselComponent = components.declare_component("image-carousel-component", path="frontend/public")
|
22 |
+
|
23 |
+
|
24 |
+
imageUrls = [
|
25 |
+
fetch_poster(1632),
|
26 |
+
fetch_poster(299536),
|
27 |
+
fetch_poster(17455),
|
28 |
+
fetch_poster(2830),
|
29 |
+
fetch_poster(429422),
|
30 |
+
fetch_poster(9722),
|
31 |
+
fetch_poster(13972),
|
32 |
+
fetch_poster(240),
|
33 |
+
fetch_poster(155),
|
34 |
+
fetch_poster(598),
|
35 |
+
fetch_poster(914),
|
36 |
+
fetch_poster(255709),
|
37 |
+
fetch_poster(572154)
|
38 |
+
|
39 |
+
]
|
40 |
+
|
41 |
+
|
42 |
+
imageCarouselComponent(imageUrls=imageUrls, height=200)
|
43 |
+
selectvalue=st.selectbox("Select movie from dropdown", movies_list)
|
44 |
+
|
45 |
+
def recommend(movie):
|
46 |
+
index=movies[movies['title']==movie].index[0]
|
47 |
+
distance = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda vector:vector[1])
|
48 |
+
recommend_movie=[]
|
49 |
+
recommend_poster=[]
|
50 |
+
for i in distance[1:6]:
|
51 |
+
movies_id=movies.iloc[i[0]].id
|
52 |
+
recommend_movie.append(movies.iloc[i[0]].title)
|
53 |
+
recommend_poster.append(fetch_poster(movies_id))
|
54 |
+
return recommend_movie, recommend_poster
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
if st.button("Show Recommend"):
|
59 |
+
movie_name, movie_poster = recommend(selectvalue)
|
60 |
+
col1,col2,col3,col4,col5=st.columns(5)
|
61 |
+
with col1:
|
62 |
+
st.text(movie_name[0])
|
63 |
+
st.image(movie_poster[0])
|
64 |
+
with col2:
|
65 |
+
st.text(movie_name[1])
|
66 |
+
st.image(movie_poster[1])
|
67 |
+
with col3:
|
68 |
+
st.text(movie_name[2])
|
69 |
+
st.image(movie_poster[2])
|
70 |
+
with col4:
|
71 |
+
st.text(movie_name[3])
|
72 |
+
st.image(movie_poster[3])
|
73 |
+
with col5:
|
74 |
+
st.text(movie_name[4])
|
75 |
+
st.image(movie_poster[4])
|