,

Architecture behind Daily, Nightly

|

Overview

I created Daily, Nightly – The EQ App, as a way to model a few different methods that I have found effective to boost my overall mood. Over these past few months, I’ve found journaling, positive quotes, and affirmations to be very helpful in improving my mood. As a way to further practice mobile development, I decided to combine the three techniques into an easy-to-use hub.

Every night at 9pm, Daily, Nightly sends you a notification to write a journal reflection, which is only accessible after 9 for the user’s respective timezone. I designed it this way because I always write my journal at the end of the day.

  1. If the journal is being posted through an image, the blob, once arrived at the express server, is firstly uploaded to a private S3 bucket. Then, the Amazon Textract API easily extracts the text.
  2. If the journal is being posted through text, the above process is not relevant

By now, the plain text is ready for machine learning models to form predictions. The text is routed through another post request to a privately hosted server, which was created with FastAPI in Python. I chose to use FastAPI, rather than Django, because I only needed a light-weight API, not a full fledged web server. I had a lot of fun browsing though the different pre-trained models on Hugging Face, and I decided two distinct ones to implement: One that ranked text on scales of 26 emotions, and one that predicted general masculine or feminine energy based on the tone. Setting up the pipeline was quick and easy in Docker. After ensuring the API could only be accessed with a proper authorization header in the post request, the API returned the JSON data.

Example of the JSON response

The deployment package was massive, so in order to upload the code to AWS Lambda as I intended, I had to containerize the package with Docker first. After a little configuration of the timeout and memory of the lambda function, the API was then running smoothly

Now that I had data I could work with, the express server relayed the data to a MySQL database hosted on AWS RDS, where the data is stored with the corresponding user for the date of the journal entry. For starters, I used React Native on the frontend to get a client up and running quickly. One of the screens had graphs to visualize the emotions data in pie charts.

Example of Data Visualization Screen

Now, the point of this application was to send custom positive affirmations and inspirational quotes, tailored to a prediction of your current mood based off of journal entries. To achieve this feat, an algorithm was created that compounded each of a user’s emotion data, with a higher weight given to newer entries. This was in combination with a general sentiment, as well as the masculine and feminine energy weights.

To push ChatGPTs limits, I asked for it to come up with a total of 5,200 positive affirmations for each of the emotions that were scaled by the previous machine learning model. Each of these emotions were stored in a JSON, with the corresponding emotion mapped to it. To get the positive quotes, I scraped publicly accessible data online, and stored the quote’s author alongside with it in the database.

A new lambda that fires off at 3 am EST runs the following: After predicting a user’s mood for the current time based on the past data, a random generator, weighted with the probability of each emotion, ran 6 times individually. Each emotion returned is then mapped to a random positive affirmation of that emotion. There also is a simple method that calculates 6 random times between 9 am and 9 pm adjusted to that user’s timezone, and that time is stored in the database, along with the affirmation. The positive quotes are determined in a similar manner as well.

Another lambda then periodically runs every 15 minutes to see if that time for that affirmation or quote is within the time slot. If it is, a push notification via expo’s push notification API sends the notification to the respective user’s device.

There is a final lambda that also sends a reminder to each user at 9 pm in their timezone to complete their journal.

In all, this project continues to be of use for me today.

Leave a Reply

Your email address will not be published. Required fields are marked *