From 25f665a8b9c4347f784e3aec2356159856d41366 Mon Sep 17 00:00:00 2001 From: rishi2019194 <58341663+rishi2019194@users.noreply.github.com> Date: Sat, 14 Oct 2023 21:44:44 -0400 Subject: [PATCH 1/7] Added genre tags in the email notifier --- src/recommenderapp/app.py | 2 +- src/recommenderapp/utils.py | 56 +++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/recommenderapp/app.py b/src/recommenderapp/app.py index 5d37ac330..aed1c6d38 100644 --- a/src/recommenderapp/app.py +++ b/src/recommenderapp/app.py @@ -66,7 +66,7 @@ def feedback(): Handles user feedback submission and mails the results. """ data = json.loads(request.data) - user_email = "ananyamantravadi@gmail.com" + user_email = "11rishi.singhal@gmail.com" send_email_to_user(user_email, beautify_feedback_data(data)) return data diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index 83c04eb3e..9cb70fc33 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -2,12 +2,45 @@ import logging import smtplib +import pandas as pd from smtplib import SMTPException from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import constants as c +def create_colored_tags(genres): + # Define colors for specific genres + genre_colors = { + 'Musical': '#FF1493', # DeepPink + 'Sci-Fi': '#00CED1', # DarkTurquoise + 'Mystery': '#8A2BE2', # BlueViolet + 'Thriller': '#FF4500', # OrangeRed + 'Horror': '#FF0000', # Red + 'Documentary': '#228B22', # ForestGreen + 'Fantasy': '#FF8C00', # DarkOrange + 'Adventure': '#FFD700', # Gold + 'Children': '#32CD32', # LimeGreen + 'Film-Noir': '#000000', # Black + 'Comedy': '#FFD700', # Gold + 'Crime': '#8B0000', # DarkRed + 'Drama': '#8B008B', # DarkMagenta + 'Western': '#FF6347', # Tomato + 'IMAX': '#7FFFD4', # Aquamarine + 'Action': '#FF4500', # OrangeRed + 'War': '#B22222', # FireBrick + '(no genres listed)': '#A9A9A9', # DarkGray + 'Romance': '#FF69B4', # HotPink + 'Animation': '#20B2AA' # LightSeaGreen + } + tags = [] + for genre in genres: + color = genre_colors.get(genre, '#CCCCCC') # Default color if not found + tag = f'{genre}' + tags.append(tag) + return ' '.join(tags) + def beautify_feedback_data(data): """ Utility function to beautify the feedback json containing predicted movies for sending in email @@ -52,12 +85,29 @@ def send_email_to_user(recipient_email, categorized_data): message['From'] = sender_email message['To'] = recipient_email message['Subject'] = subject + + # Load the CSV file into a DataFrame + movie_genre_df = pd.read_csv('../../data/movies.csv') + + # Create a dictionary to map movies to their genres + movie_to_genres = {} + + for row in movie_genre_df.iterrows(): + movie = row[1]['title'] + genres = row[1]['genres'].split('|') + movie_to_genres[movie] = genres # Create the email message with HTML content html_content = c.EMAIL_HTML_CONTENT.format( - '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Liked']), - '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Disliked']), - '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Yet to Watch'])) + '\n'.join(f'
  • {movie} \ + {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}

  • ' \ + for movie in categorized_data['Liked']), + '\n'.join(f'
  • {movie} \ + {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}

  • ' \ + for movie in categorized_data['Disliked']), + '\n'.join(f'
  • {movie} \ + {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}

  • ' \ + for movie in categorized_data['Yet to Watch'])) # Attach the HTML email body message.attach(MIMEText(html_content, 'html')) From 5a9f3f4f14ab1eaf5210b62594bb41c87a29eb2e Mon Sep 17 00:00:00 2001 From: rishi2019194 <58341663+rishi2019194@users.noreply.github.com> Date: Sat, 14 Oct 2023 21:55:49 -0400 Subject: [PATCH 2/7] Added genre tags in the email notifier --- src/recommenderapp/utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index 9cb70fc33..e94becbc6 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -2,14 +2,18 @@ import logging import smtplib -import pandas as pd from smtplib import SMTPException from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart +import pandas as pd import constants as c def create_colored_tags(genres): + """ + Utitilty function to create colored tags for different + movie genres + """ # Define colors for specific genres genre_colors = { 'Musical': '#FF1493', # DeepPink @@ -35,10 +39,10 @@ def create_colored_tags(genres): } tags = [] for genre in genres: - color = genre_colors.get(genre, '#CCCCCC') # Default color if not found - tag = f'{genre}' - tags.append(tag) + color = genre_colors.get(genre, '#CCCCCC') # Default color if not found + tag = f'{genre}' + tags.append(tag) return ' '.join(tags) def beautify_feedback_data(data): @@ -85,7 +89,6 @@ def send_email_to_user(recipient_email, categorized_data): message['From'] = sender_email message['To'] = recipient_email message['Subject'] = subject - # Load the CSV file into a DataFrame movie_genre_df = pd.read_csv('../../data/movies.csv') From 02fdc51d1e94568a0e90ceb132fbe8de5cc47208 Mon Sep 17 00:00:00 2001 From: rishi2019194 <58341663+rishi2019194@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:03:47 -0400 Subject: [PATCH 3/7] refactor the code --- src/recommenderapp/utils.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index e94becbc6..840bd00de 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -69,6 +69,21 @@ def beautify_feedback_data(data): return categorized_data_dict +def create_movie_genres(movie_genre_df): + """ + Utility function for creating a dictionary for movie-genres mapping + """ + # Create a dictionary to map movies to their genres + movie_to_genres = {} + + # Iterating on all movies to create the map + for row in movie_genre_df.iterrows(): + movie = row[1]['title'] + genres = row[1]['genres'].split('|') + movie_to_genres[movie] = genres + return movie_to_genres + + def send_email_to_user(recipient_email, categorized_data): """ Utility function to send movie recommendations to user over email @@ -91,15 +106,8 @@ def send_email_to_user(recipient_email, categorized_data): message['Subject'] = subject # Load the CSV file into a DataFrame movie_genre_df = pd.read_csv('../../data/movies.csv') - - # Create a dictionary to map movies to their genres - movie_to_genres = {} - - for row in movie_genre_df.iterrows(): - movie = row[1]['title'] - genres = row[1]['genres'].split('|') - movie_to_genres[movie] = genres - + # Creating movie-genres map + movie_to_genres = create_movie_genres(movie_genre_df) # Create the email message with HTML content html_content = c.EMAIL_HTML_CONTENT.format( '\n'.join(f'
  • {movie} \ From 00ce51540dcc978002623060ddb88f71a12f5e48 Mon Sep 17 00:00:00 2001 From: rishi2019194 <58341663+rishi2019194@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:06:12 -0400 Subject: [PATCH 4/7] refactor the code --- src/recommenderapp/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index 840bd00de..2bce115af 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -83,7 +83,6 @@ def create_movie_genres(movie_genre_df): movie_to_genres[movie] = genres return movie_to_genres - def send_email_to_user(recipient_email, categorized_data): """ Utility function to send movie recommendations to user over email From 3841c9b7f35c2b294918228d131d2ee03ee15283 Mon Sep 17 00:00:00 2001 From: rishi2019194 <58341663+rishi2019194@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:08:07 -0400 Subject: [PATCH 5/7] refactor the code --- src/recommenderapp/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index 2bce115af..476072bc7 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -82,7 +82,6 @@ def create_movie_genres(movie_genre_df): genres = row[1]['genres'].split('|') movie_to_genres[movie] = genres return movie_to_genres - def send_email_to_user(recipient_email, categorized_data): """ Utility function to send movie recommendations to user over email From da1db469f993d493920b8a2d1a0d5912c2751230 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Sun, 15 Oct 2023 17:01:43 -0400 Subject: [PATCH 6/7] pylint refactor, UI improve & code cleaning --- src/recommenderapp/app.py | 16 +- .../templates/landing_page.html | 215 ++++++------------ 2 files changed, 75 insertions(+), 156 deletions(-) diff --git a/src/recommenderapp/app.py b/src/recommenderapp/app.py index 1405756ce..59f43f2f5 100644 --- a/src/recommenderapp/app.py +++ b/src/recommenderapp/app.py @@ -2,16 +2,18 @@ Module for routing all calls from the frontend """ -from utils import send_email_to_user, beautify_feedback_data -from flask_cors import CORS +import json +import sys + from flask import Flask, jsonify, render_template, request +from flask_cors import CORS from search import Search -import sys -import json +from utils import beautify_feedback_data, send_email_to_user + sys.path.append("../../") +#pylint: disable=wrong-import-position from src.prediction_scripts.item_based import recommend_for_new_user -# pylint: disable=wrong-import-position -# pylint: enable=wrong-import-position +#pylint: enable=wrong-import-position app = Flask(__name__) @@ -69,7 +71,7 @@ def feedback(): @app.route("/sendMail", methods=["POST"]) -def sendMail(): +def send_mail(): """ Handles user feedback submission and mails the results. """ diff --git a/src/recommenderapp/templates/landing_page.html b/src/recommenderapp/templates/landing_page.html index cf7b884b3..537e95c66 100644 --- a/src/recommenderapp/templates/landing_page.html +++ b/src/recommenderapp/templates/landing_page.html @@ -1,177 +1,94 @@ - + + PopcornPicks🍿 - - - - + + + + - - -
    +

    🎬 Pick a Movie! 🎬