Spaces:
Runtime error
Runtime error
Shrikrishna
commited on
Commit
•
fce58be
1
Parent(s):
34f004b
Upload 4 files
Browse files- app.py +81 -0
- movie_list.pkl +3 -0
- requirements.txt +2 -0
- similarity.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import requests
|
4 |
+
|
5 |
+
footer="""<style>
|
6 |
+
a:link , a:visited{
|
7 |
+
color: black;
|
8 |
+
background-color: transparent;
|
9 |
+
}
|
10 |
+
|
11 |
+
a:hover, a:active {
|
12 |
+
color: red;
|
13 |
+
background-color: transparent;
|
14 |
+
}
|
15 |
+
|
16 |
+
.footer {
|
17 |
+
position: fixed;
|
18 |
+
left: 0;
|
19 |
+
bottom: 0;
|
20 |
+
width: 100%;
|
21 |
+
background-color: white;
|
22 |
+
color: black;
|
23 |
+
text-align: center;
|
24 |
+
}
|
25 |
+
</style>
|
26 |
+
<div class="footer">
|
27 |
+
<p>Developed with <span style ='color:red'>❤</span> by <a href="https://shrikrishnaparab.tech/" target="_blank">Shrikrishna Parab</a></p>
|
28 |
+
</div>
|
29 |
+
"""
|
30 |
+
|
31 |
+
def fetch_poster(movie_id):
|
32 |
+
url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id)
|
33 |
+
data = requests.get(url)
|
34 |
+
data = data.json()
|
35 |
+
poster_path = data['poster_path']
|
36 |
+
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
|
37 |
+
return full_path
|
38 |
+
|
39 |
+
def recommend(movie):
|
40 |
+
index = movies[movies['title'] == movie].index[0]
|
41 |
+
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
|
42 |
+
recommended_movie_names = []
|
43 |
+
recommended_movie_posters = []
|
44 |
+
for i in distances[1:6]:
|
45 |
+
# fetch the movie poster
|
46 |
+
movie_id = movies.iloc[i[0]].movie_id
|
47 |
+
recommended_movie_posters.append(fetch_poster(movie_id))
|
48 |
+
recommended_movie_names.append(movies.iloc[i[0]].title)
|
49 |
+
|
50 |
+
return recommended_movie_names,recommended_movie_posters
|
51 |
+
|
52 |
+
|
53 |
+
st.title("Movie Recommender System")
|
54 |
+
|
55 |
+
movies = pickle.load(open('movie_list.pkl','rb'))
|
56 |
+
similarity = pickle.load(open('similarity.pkl','rb'))
|
57 |
+
|
58 |
+
movie_list = movies['title'].values
|
59 |
+
option_selected = st.selectbox(
|
60 |
+
'Type or Select Movie Name from Dropdown',
|
61 |
+
movie_list
|
62 |
+
)
|
63 |
+
|
64 |
+
if st.button('Show Recommendation'):
|
65 |
+
recommended_movie_names, recommended_movie_posters = recommend(option_selected)
|
66 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
67 |
+
with col1:
|
68 |
+
st.image(recommended_movie_posters[0], caption=recommended_movie_names[0])
|
69 |
+
with col2:
|
70 |
+
st.image(recommended_movie_posters[1], caption=recommended_movie_names[1])
|
71 |
+
|
72 |
+
with col3:
|
73 |
+
st.image(recommended_movie_posters[2], caption=recommended_movie_names[2])
|
74 |
+
with col4:
|
75 |
+
st.image(recommended_movie_posters[3], caption=recommended_movie_names[3])
|
76 |
+
with col5:
|
77 |
+
st.image(recommended_movie_posters[4], caption=recommended_movie_names[4])
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
st.markdown(footer,unsafe_allow_html=True)
|
movie_list.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a7be347c4e22aae6549aafb013a4172287511db29112d87ad08b12b6abb1e41e
|
3 |
+
size 2294433
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
sklearn
|
similarity.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bb54916c165572df7b87afe95cf7b56241383c4c13255031d1a4bccdb9231dce
|
3 |
+
size 184781248
|