Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import pandas as pd
|
4 |
+
import requests
|
5 |
+
original_title = '<p style="color:White; font-size: 80px;">CinePicks</p>'
|
6 |
+
st.markdown(original_title, unsafe_allow_html=True)
|
7 |
+
st.markdown(
|
8 |
+
f"""
|
9 |
+
<style>
|
10 |
+
.stApp {{
|
11 |
+
background: url("https://wallup.net/wp-content/uploads/2018/03/20/414708-Iron_Man-Iron_Man_2-Iron_Man_3-iron_man__mark_XLIII-The_Avengers.jpg");
|
12 |
+
}}
|
13 |
+
</style>
|
14 |
+
""",
|
15 |
+
unsafe_allow_html=True
|
16 |
+
)
|
17 |
+
def fetch_poster(movie_id):
|
18 |
+
url='https://api.themoviedb.org/3/movie/{}?api_key=4e9dfb203bf90ff6a4fc33522c802f3b'.format(movie_id)
|
19 |
+
data=requests.get(url)
|
20 |
+
data=data.json()
|
21 |
+
poster_path=data['poster_path']
|
22 |
+
full_path="https://image.tmdb.org/t/p/w500/" + poster_path
|
23 |
+
return full_path
|
24 |
+
|
25 |
+
|
26 |
+
similarity=pickle.load(open('similarity.pkl','rb'))
|
27 |
+
def recommend(movie):
|
28 |
+
movie_index = movies[movies['title'] == movie].index[0]
|
29 |
+
distances = similarity[movie_index]
|
30 |
+
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
|
31 |
+
recommended_movies=[]
|
32 |
+
recommended_movie_posters = []
|
33 |
+
|
34 |
+
for i in movies_list:
|
35 |
+
movie_id=movies.iloc[i[0]].movie_id
|
36 |
+
# Fetch poster from API
|
37 |
+
recommended_movies.append(movies.iloc[i[0]].title)
|
38 |
+
recommended_movie_posters.append(fetch_poster(movie_id))
|
39 |
+
return recommended_movies,recommended_movie_posters
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
movies_dict=pickle.load(open('movies_dict.pkl','rb'))
|
44 |
+
movies=pd.DataFrame(movies_dict)
|
45 |
+
selected_movie_name=st.selectbox('Recently Watched',movies['title'].values)
|
46 |
+
if st.button('Show Recommendations'):
|
47 |
+
recommended_movie_names, recommended_movie_posters = recommend(selected_movie_name)
|
48 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
49 |
+
with col1:
|
50 |
+
st.text(recommended_movie_names[0])
|
51 |
+
st.image(recommended_movie_posters[0])
|
52 |
+
with col2:
|
53 |
+
st.text(recommended_movie_names[1])
|
54 |
+
st.image(recommended_movie_posters[1])
|
55 |
+
|
56 |
+
with col3:
|
57 |
+
st.text(recommended_movie_names[2])
|
58 |
+
st.image(recommended_movie_posters[2])
|
59 |
+
with col4:
|
60 |
+
st.text(recommended_movie_names[3])
|
61 |
+
st.image(recommended_movie_posters[3])
|
62 |
+
with col5:
|
63 |
+
st.text(recommended_movie_names[4])
|
64 |
+
st.image(recommended_movie_posters[4])
|