Spaces:
Sleeping
Sleeping
File size: 1,962 Bytes
662ec2c 2e507bd 662ec2c 2e507bd 662ec2c 2e507bd 662ec2c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import streamlit as st
import pickle
import requests
import os
movies = pickle.load(open('movies.pkl','rb'))
similarity = pickle.load(open('similarity.pkl','rb'))
movie_list = movies['title'].values
tmdb_api_token = os.environ["TMDB_API_TOKEN"]
def poster_fetcher(id):
url = "https://api.themoviedb.org/3/movie/{}?api_key={}".format(id,tmdb_api_token)
response = requests.get(url)
obj = response.json()
return "https://image.tmdb.org/t/p/w500/" + obj['poster_path']
def recommend(movie):
movie_names = []
posters = []
movie_index = movies[movies['title']==movie].index[0]
distance = similarity[movie_index]
movie_list = sorted((list(enumerate(distance))),reverse=True,key=lambda x : x[1])[1:6]
for i in movie_list:
# movie_id = i[0]
movie_names.append(movies.iloc[i[0]].title)
posters.append(poster_fetcher(movies.iloc[i[0]].movie_id))
return movie_names,posters
st.title("movie recommendation system")
selected_movie_name = st.selectbox("select any movie that you like",movie_list)
if st.button('recommend'):
names,posters = recommend(selected_movie_name)
st.title("recommendations:")
# for (i,j) in zip(names,posters):
# st.write(i)
# st.image(j)
# col1, col2, col3, col4, col5 = st.columns(5)
# with col1:
# st.text(names[0])
# st.image(posters[0])
# with col1:
# st.text(names[1])
# st.image(posters[1])
# with col1:
# st.text(names[2])
# st.image(posters[2])
# with col1:
# st.text(names[3])
# st.image(posters[3])
# with col1:
# st.text(names[4])
# st.image(posters[4])
col = st.columns(len(names))[0]
# Use a loop to add images horizontally
for (i,j) in zip(names,posters):
with col:
st.divider()
st.text(i)
st.image(j)
st.divider()
st.text('source - TMDB')
|