Spaces:
Runtime error
Runtime error
added app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# function to fetch the poster
|
| 7 |
+
def fetch_poster(movie_id):
|
| 8 |
+
response = requests.get(f"https://api.themoviedb.org/3/movie/{movie_id}?api_key=bb1678d9f4f581a1a07e8161ffe487a0&language=en-US%27")
|
| 9 |
+
data = response.json()
|
| 10 |
+
if 'poster_path' in data:
|
| 11 |
+
return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
|
| 12 |
+
else:
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
movielist_of_5000_movies = pickle.load(open('movies.pkl', 'rb'))
|
| 18 |
+
similarityArray = pickle.load(open('similarityArray.pkl', 'rb'))
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def recommended(movie):
|
| 22 |
+
movie_index = movielist_of_5000_movies[movielist_of_5000_movies['title'] == movie].index[0]
|
| 23 |
+
distances = similarityArray[movie_index]
|
| 24 |
+
movie_list = sorted(enumerate(distances), reverse=True, key=lambda x: x[1])[1:11]
|
| 25 |
+
|
| 26 |
+
recommended_movies = []
|
| 27 |
+
recommended_movies_posters = []
|
| 28 |
+
|
| 29 |
+
for i in movie_list:
|
| 30 |
+
recommended_movies.append(movielist_of_5000_movies.iloc[i[0]].title)
|
| 31 |
+
recommended_movies_posters.append(fetch_poster(movielist_of_5000_movies.iloc[i[0]].movie_id))
|
| 32 |
+
|
| 33 |
+
return recommended_movies, recommended_movies_posters
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
st.title("Movie Recommendation System")
|
| 37 |
+
st.subheader("The is a Movie Recommendation System. I have created this for fun")
|
| 38 |
+
st.caption("I hope you all will like it!!!")
|
| 39 |
+
|
| 40 |
+
selected_movie = st.selectbox(
|
| 41 |
+
'Please Select the Movie you like to get Recommendation ',
|
| 42 |
+
movielist_of_5000_movies['title'].values)
|
| 43 |
+
|
| 44 |
+
if st.button('Recommend'):
|
| 45 |
+
st.write('The Recommended Movies for ', selected_movie, " are: ")
|
| 46 |
+
recommendations, posters = recommended(selected_movie)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
col1, col2 = st.columns(2)
|
| 51 |
+
for i in range(5):
|
| 52 |
+
with col1:
|
| 53 |
+
st.text(recommendations[i])
|
| 54 |
+
st.image(posters[i])
|
| 55 |
+
|
| 56 |
+
for i in range(5, 10):
|
| 57 |
+
with col2:
|
| 58 |
+
st.text(recommendations[i])
|
| 59 |
+
st.image(posters[i])
|