import pickle import streamlit as st import requests # Set page title and sidebar properties st.set_page_config(page_title="Insightly") st.markdown( """ """, unsafe_allow_html=True, ) # Sidebar contents with st.sidebar: st.image("https://i.ibb.co/bX6GdqG/insightly-wbg.png", use_column_width=True) st.markdown("
", unsafe_allow_html=True) st.markdown(" ", unsafe_allow_html=True) st.markdown(" ", unsafe_allow_html=True) st.markdown(" ", unsafe_allow_html=True) st.markdown("", unsafe_allow_html=True) def fetch_poster(movie_id): url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id) data = requests.get(url) data = data.json() poster_path = data['poster_path'] full_path = "https://image.tmdb.org/t/p/w500/" + poster_path return full_path def recommend(movie): index = movies[movies['title'] == movie].index[0] distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1]) recommended_movie_names = [] recommended_movie_posters = [] for i in distances[1:6]: # fetch the movie poster movie_id = movies.iloc[i[0]].movie_id recommended_movie_posters.append(fetch_poster(movie_id)) recommended_movie_names.append(movies.iloc[i[0]].title) return recommended_movie_names,recommended_movie_posters st.title('Movie Recommender 🎬') # Provide the correct absolute paths to the pickled data movie_list_path = "https://drive.google.com/file/d/1OmueIayrvczEQKRWIOfEkKH5zLWGxCn1/view?usp=drive_link" similarity_path = "https://drive.google.com/file/d/1RI6XgtbaNxlBqZM0cznOZXN88tQWo98a/view?usp=drive_link" movies = pickle.load(open(movie_list_path, 'rb')) similarity = pickle.load(open(similarity_path, 'rb')) movies = pickle.load(open(movie_list_path, 'rb')) similarity = pickle.load(open(similarity_path, 'rb')) movie_list = movies['title'].values selected_movie = st.selectbox( "Type or select a movie from the dropdown", movie_list ) if st.button('Show Recommendation'): recommended_movie_names, recommended_movie_posters = recommend(selected_movie) # Create columns based on the number of recommended movies num_recommendations = len(recommended_movie_names) num_columns = 3 num_rows = (num_recommendations + num_columns - 1) // num_columns # Calculate the number of rows required # Create a list of columns cols = [st.columns(num_columns) for _ in range(num_rows)] # Loop through recommended movies and posters and display them in the columns for i, movie_name in enumerate(recommended_movie_names): col_index = i // num_columns row_index = i % num_columns cols[col_index][row_index].markdown(f"{movie_name}", unsafe_allow_html=True) cols[col_index][row_index].image(recommended_movie_posters[i]) # Add padding between the rows st.markdown("