import streamlit as st import methods def Strategy(): st.title("Recommendations Strategy") strategy_options = ["Using my ratings", "Answer some questions", "Depending on my mood"] signUp = False recorded_ratings = True ratingsNum = 5 # Update options list based on boolean variables if signUp: strategy_options.remove("Using my ratings") # Rating selection with unique key selected_strategy = st.radio("Select your preferred st option:", strategy_options, key="level2_radio_1") # Submit button if st.button("Submit"): if recorded_ratings and selected_strategy == "Using my ratings": st.error("We have recorded " + str(ratingsNum) + " ratings for you. This option is not recommended") # st.session_state["page"] = 1 elif recorded_ratings and selected_strategy == "Answer some questions": st.success(f"Preferred strategy: {selected_strategy}") return True def questionnaire(): st.title("Movie Preferences") # Age age = st.number_input("How old are you?", min_value=0, max_value=120, step=1) # Country st.write("---") location = st.text_input("Where are you from?") enjoy_other_countries = st.checkbox("I also enjoy movies from other countries") selected_countries = [] if enjoy_other_countries: st.subheader("Famous Countries") famous_countries = ["United States of America", "United Kingdom", "France", "India", "China"] selected_countries = st.multiselect("Select famous countries you enjoy movies from", famous_countries) if len(selected_countries) > 0 and selected_countries[0] not in famous_countries: st.warning("The first selected country should be from the famous countries list.") # Genres st.write("---") available_genres = ['Drama', 'Comedy', 'Thriller', 'Romance', 'Action', 'Horror', 'Crime', 'Documentary', 'Adventure', 'Science Fiction', 'Family', 'Mystery', 'Fantasy', 'Animation', 'Foreign', 'Music', 'History', 'War', 'Western', 'TV Movie'] favorite_genres = st.multiselect("Select your favorite movie genres", available_genres) remaining_genres = list(set(available_genres) - set(favorite_genres)) least_favorite_genres = st.multiselect("Select your least favorite genres", remaining_genres) # Date st.write("---") date_options = ["Doesn't matter", "Published in the last 3 years.", "Published in the last 5 years.", "Published in the last 10 years.", "Published in the last 20 years.", "Before 2000."] selected_date = st.radio("Select your preferred date option:", date_options) date_preference = 0 if selected_date == date_options[1]: date_preference = 2018 elif selected_date == date_options[2]: date_preference = 2015 elif selected_date == date_options[3]: date_preference = 2010 elif selected_date == date_options[4]: date_preference = 2000 elif selected_date == date_options[5]: date_preference = -1 # Rating st.write("---") available_rating_options = ["Doesn't matter", "Over 6", "Over 7", "Over 8", "Over 9"] selected_rating_preference = st.radio("Select your preferred rating option:", available_rating_options) rating_preference = 0 if selected_rating_preference == available_rating_options[1]: rating_preference = 6 elif selected_rating_preference == available_rating_options[2]: rating_preference = 7 elif selected_rating_preference == available_rating_options[3]: rating_preference = 8 elif selected_rating_preference == available_rating_options[4]: rating_preference = 9 # Runtime st.write("---") runtime_options = ["Doesn't matter", "Under 30", "30 to 90", "90 to 180", "180 to 270", "above 270"] selected_runtime = st.radio("Select your preferred runtime option:", runtime_options) runtime_preference = 0 if selected_runtime == runtime_options[0]: runtime_preference = 0 elif selected_runtime == runtime_options[1]: runtime_preference = 1 elif selected_runtime == runtime_options[2]: runtime_preference = 2 elif selected_runtime == runtime_options[3]: runtime_preference = 3 elif selected_runtime == runtime_options[4]: runtime_preference = 4 # Collection col1, col2 = st.columns(2) with col1: collection_movies = st.checkbox("Collection movies") with col2: single_movies = st.checkbox("Single movies") single_preference = 0 if single_movies and collection_movies: single_preference = 2 elif single_movies: single_preference = 1 elif collection_movies: single_preference = 0 # User profile if st.button("Submit"): user_profile = { "age": age, "countries": [location] + selected_countries, "favorite_genres": favorite_genres, "least_favorite_genres": least_favorite_genres, "year": date_preference, "rated_over": rating_preference, "runTime": runtime_preference, "single": single_preference, } st.write(user_profile) return user_profile def selectedMovies(userProfile): st.title("Favorite Movies ") # List of favorite movies movies = methods.get_moviesName(methods.get_filtered_df(userProfile)) allMovies = methods.getALLMovies() favorite_movies = st.selectbox("Select your favorite movies from your filters:", movies, key="favorite_movies") # Checkbox for additional options show_additional_options = st.checkbox("Show all options (from 35000 movies)") additional_movies = [] if show_additional_options: additional_movies = st.multiselect("Select additional movies:", allMovies) submitted_favorite = st.button("Submit", key="selectedMovies") if submitted_favorite: return favorite_movies def level3(user_profile, movie_name): st.title("Favorite Selection") movie_URL = methods.getPosters(movie_name) # Display image if movie_URL != 'Not Found': image_url = movie_URL st.image(image_url, caption=movie_name, use_column_width=True) # Display selected text selected_text = "You selected " + movie_name + " as your favorite." # st.write(selected_text) imdb_id = methods.getIMDB(movie_name) # Display rate text rate_text = "Rate these things:" # st.write(rate_text) # Display rating options rating_options = ['Director', 'Cast', 'Description'] ratings = [] for option in rating_options: rating = st.slider(f"{option}", 1, 5, key=option, format="%d") ratings.append(rating) # Submit button submitted = st.button("Submit", key="level3") picked_movies_arr = { "imdb_id": imdb_id, # Include IMDb ID in the dictionary "cast_point": ratings[1], "director_point": ratings[0], "story_point": ratings[2] } if submitted: # Process the ratings here st.write('submit') recommendations = recommendOne(methods.get_filtered_df(user_profile), [picked_movies_arr]) def recommendOne(filter_df, profile): # Define the image URLs and names image_names, image_urls = methods.getNames(filter_df, profile) col1, col2, col3 = st.columns(3) # Display the first image in the first column with col1: st.image(image_urls[0], caption=image_names[0], use_column_width=True) # Display the second image in the second column with col2: st.image(image_urls[1], caption=image_names[1], use_column_width=True) # Display the third image in the third column with col3: st.image(image_urls[2], caption=image_names[2], use_column_width=True) # Return the recommendations with names and URLs return [ (image_names[0], image_urls[0]), (image_names[1], image_urls[1]), (image_names[2], image_urls[2]) ] def main(): page = st.sidebar.selectbox("Select Page", ["Strategy", "Questionnaire", "Selected Movies", "Level 3"]) if page == "Strategy": if Strategy(): st.session_state["page"] = "Questionnaire" elif page == "Questionnaire": user_profile = questionnaire() if user_profile: st.session_state["user_profile"] = user_profile st.session_state["page"] = "Selected Movies" elif page == "Selected Movies": if "user_profile" in st.session_state: user_profile = st.session_state["user_profile"] movie_name = selectedMovies(user_profile) if movie_name: st.session_state["movie_name"] = movie_name st.session_state["page"] = "Level 3" elif page == "Level 3": if "user_profile" in st.session_state and "movie_name" in st.session_state: user_profile = st.session_state["user_profile"] movie_name = st.session_state["movie_name"] level3(user_profile, movie_name) if __name__ == "__main__": main()