import gradio as gr from recommend import get_genres_movies_for_user, test_users label_value_mapping = {f"User {user_id}": user_id for user_id in test_users} # Define a function to generate colors based on genre def get_genre_color(movie_genres, top_genres): genre_colors = { 'Action': '#F44336', # Red: Energetic and intense 'Adventure': '#FF5722', # Deep Orange: Exciting and daring 'Thriller': '#9C27B0', # Purple: Suspenseful and mysterious 'Animation': '#FFEB3B', # Yellow: Bright and cheerful 'Children': '#4CAF50', # Green: Fresh, youthful, and playful 'Fantasy': '#673AB7', # Deep Purple: Magical and imaginative 'Comedy': '#FFC107', # Amber: Lighthearted and funny 'Musical': '#E91E63', # Pink: Romantic and artistic 'Romance': '#FF4081', # Light Pink: Love and tenderness 'Crime': '#607D8B', # Blue Grey: Gritty and dark 'Mystery': '#8BC34A', # Lime Green: Curious and investigative 'Film-Noir': '#212121', # Black: Dark and moody 'Documentary': '#009688', # Teal: Informative and grounded 'Drama': '#3F51B5', # Blue: Serious and emotional 'Horror': '#B71C1C', # Dark Red: Fearful and intense 'Sci-Fi': '#00BCD4', # Cyan: Futuristic and techy 'War': '#795548', # Brown: Rugged and historical 'Western': '#D7A87E', # Tan: Rustic and wild } # Default color if no genre matches default_color = '#9E9E9E' if not top_genres: return genre_colors.get(movie_genres[0], default_color) # Check for the first genre in movie_genres that is also in top_genres for genre in movie_genres: if genre in top_genres and genre in genre_colors: return genre_colors[genre] # Check for the first valid genre in movie_genres that has a color for genre in movie_genres: if genre in genre_colors: return genre_colors[genre] # Return the default color if no matches return default_color def get_movie_recommendations(user_id): # Fetch the top genres and recommended movies based on user_id user_id = label_value_mapping[user_id] top_genres, movies = get_genres_movies_for_user(user_id) genre_cards = "".join([ f"