Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pickle
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
def fetch_poster(movie_id):
|
| 8 |
+
response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US'.format(movie_id))
|
| 9 |
+
data = response.json()
|
| 10 |
+
return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def recommend(movie):
|
| 14 |
+
movie_index = movies[movies['title'] == movie].index[0]
|
| 15 |
+
distances = similarity[movie_index]
|
| 16 |
+
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x:x[1])[1:6]
|
| 17 |
+
recomended_movies = []
|
| 18 |
+
recommended_movies_posters = []
|
| 19 |
+
for i in movies_list:
|
| 20 |
+
movie_id= movies.iloc[i[0]].movie_id
|
| 21 |
+
recomended_movies.append(movies.iloc[i[0]].title)
|
| 22 |
+
recommended_movies_posters.append(fetch_poster(movie_id))
|
| 23 |
+
return recomended_movies, recommended_movies_posters
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
movies_dict = pickle.load(open('movie_dict.pkl', 'rb'))
|
| 27 |
+
movies = pd.DataFrame(movies_dict)
|
| 28 |
+
similarity = pickle.load(open('similarity.pkl', 'rb'))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
st.title('Movie Recommender System')
|
| 32 |
+
|
| 33 |
+
selected_movie_name = st.selectbox(
|
| 34 |
+
'How',
|
| 35 |
+
movies['title'].values
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if st.button('Recommend'):
|
| 39 |
+
recommended_movie_names, recommended_movie_posters = recommend(selected_movie_name)
|
| 40 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 41 |
+
with col1:
|
| 42 |
+
st.text(recommended_movie_names[0])
|
| 43 |
+
st.image(recommended_movie_posters[0])
|
| 44 |
+
with col2:
|
| 45 |
+
st.text(recommended_movie_names[1])
|
| 46 |
+
st.image(recommended_movie_posters[1])
|
| 47 |
+
|
| 48 |
+
with col3:
|
| 49 |
+
st.text(recommended_movie_names[2])
|
| 50 |
+
st.image(recommended_movie_posters[2])
|
| 51 |
+
with col4:
|
| 52 |
+
st.text(recommended_movie_names[3])
|
| 53 |
+
st.image(recommended_movie_posters[3])
|
| 54 |
+
with col5:
|
| 55 |
+
st.text(recommended_movie_names[4])
|
| 56 |
+
st.image(recommended_movie_posters[4])
|
| 57 |
+
|