CoolFace
Apppublic

Irshad112/project

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
web.py64 linesDownload Raw Back to root
1import streamlit as st2import pickle3import requests4 5movies_df = pickle.load(open('movies.pkl','rb'))6movies_list = movies_df['title'].values # names of all the movies7 8# similarity list of movies with other movies9similarity = pickle.load(open('similarity.pkl','rb'))10 11 12# -------------------------------13# poster function14# -------------------------------15def poster(movie_id):16  response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=12804ad378a8ba3bd3da09faac00798a&language=en-US'.format(movie_id))17  data = response.json()18  return 'https://image.tmdb.org/t/p/w500/' + data['poster_path']19 20 21# -------------------------------22# recommending function23# -------------------------------24def recom(movie):25  # movies index26  movies_index = movies_df[movies_df['title'] == movie].index[0]27  # top similar movies28  recommended_list = sorted(list(enumerate(similarity[movies_index])), reverse = True, key = lambda x: x[1])[0:6]29  30  recommended_movies = []31  movie_poster =[]32  33  for i in recommended_list:34    # movie id35    movie_id = movies_df.iloc[i[0]].id36    # fetch poster from API37    movie_poster.append(poster(movie_id))38    # appending recommendations39    recommended_movies.append(movies_list[i[0]])40  return recommended_movies,movie_poster41  42  43# title of the website 44st.title('Movie Recommendation System🍿')45 46# user input47movie_name = st.selectbox(48    'Search:',49    movies_list)50 51# enter button52if st.button('Enter'):53  names,posters = recom(movie_name)54  col1, col2, col3, col4, col5,col6 = st.columns(6)55  col_list = [col1,col2,col3,col4,col5,col6]56  57  for i in col_list:58    with i:59      st.image(posters[col_list.index(i)])60  # with col1:61  #   st.image(posters[0])62 63 64