Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- app.py +61 -0
- movies.pkl +3 -0
- requirements.txt +0 -0
- similarity.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
|
| 4 |
+
# extract the new_df dataframe from movies.pkl
|
| 5 |
+
movies_list = pickle.load(open("movies.pkl", "rb"))
|
| 6 |
+
# extract the titles of movies
|
| 7 |
+
movies_list_title = movies_list["title"].values
|
| 8 |
+
|
| 9 |
+
# extract the similarity which contain our cosine similarity values
|
| 10 |
+
similarity = pickle.load(open("similarity.pkl", "rb"))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# make a recommend function which will take movie title and return 5 similar movies with their posters
|
| 14 |
+
def recommend(movie):
|
| 15 |
+
movie_index = movies_list[movies_list["title"] == movie].index[0]
|
| 16 |
+
distances = similarity[movie_index]
|
| 17 |
+
sorted_movie_list = sorted(list(enumerate(distances)), reverse=True,
|
| 18 |
+
key=lambda x:x[1])[1:6]
|
| 19 |
+
|
| 20 |
+
recommended_movies = []
|
| 21 |
+
recommended_posters = []
|
| 22 |
+
for i in sorted_movie_list:
|
| 23 |
+
poster_path = movies_list["poster_path"][i[0]]
|
| 24 |
+
recommended_movies.append(movies_list.iloc[i[0]].title)
|
| 25 |
+
recommended_posters.append("https://image.tmdb.org/t/p/original"+poster_path)
|
| 26 |
+
|
| 27 |
+
return recommended_movies, recommended_posters
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# Create title for your stream lit page
|
| 32 |
+
st.title("Movie Recommender System")
|
| 33 |
+
|
| 34 |
+
# Create a input box for movies name
|
| 35 |
+
selected_movie_name = st.selectbox(
|
| 36 |
+
"What is the movie name?",
|
| 37 |
+
movies_list_title
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# create a recommend button with function of displaying recommended movies and movie posters
|
| 41 |
+
if st.button("Recommend"):
|
| 42 |
+
recommendation, movie_posters = recommend(selected_movie_name)
|
| 43 |
+
|
| 44 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 45 |
+
|
| 46 |
+
with col1:
|
| 47 |
+
st.write(recommendation[0])
|
| 48 |
+
st.image(movie_posters[0])
|
| 49 |
+
with col2:
|
| 50 |
+
st.write(recommendation[1])
|
| 51 |
+
st.image(movie_posters[1])
|
| 52 |
+
with col3:
|
| 53 |
+
st.write(recommendation[2])
|
| 54 |
+
st.image(movie_posters[2])
|
| 55 |
+
with col4:
|
| 56 |
+
st.write(recommendation[3])
|
| 57 |
+
st.image(movie_posters[3])
|
| 58 |
+
with col5:
|
| 59 |
+
st.write(recommendation[4])
|
| 60 |
+
st.image(movie_posters[4])
|
| 61 |
+
|
movies.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:59bfacbec6572a27ccdddd3d636b325e4c2288b563e365c356dbbecb253055ef
|
| 3 |
+
size 3834246
|
requirements.txt
ADDED
|
Binary file (10.7 kB). View file
|
|
|
similarity.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92eb0c1f80c11321b9701b61815de547ab3f5cdee87b797451c96a3ea40ac1aa
|
| 3 |
+
size 465979555
|