Artificial Intelligence Concepts for Mental Health Application Development: Therapily for Mental Health Care

ABSTRACT


INTRODUCTION Motivation and Background Study
In recent years, mental health illnesses have grown to become more common globally, causing severe repercussions to an individual's daily routine. Approximately 70% of individuals with mental health issues do not receive appropriate treatment due to a lack of self-awareness (Henderson, Evan-Lacko & Thornicroft.,2013). Many are reported to avoid seeking treatment due to prejudice against mental health issues within society. The following reports indicate the link between an individual's subjective well-being and physical health and resulting productivity. The World Health Organization (WHO) (WHO, 2021) reports that 1 in 7 of the world's children and adolescents with mental illnesses due to various factors are more susceptible to disability. The onset of the global pandemic in 2020 resulted in individuals within the age group 15 -29 succumbing to anxiety disorders, depression, and stress-related issues due to a lack of social interaction and increased workload. Across the United Arab Emirates (UAE), COVID-19 resulted in a severe psychological impact on 27.3% of the country's population (Cheikh Ismail, 2021). The worsening health conditions eventually affect work, relationships, and other life aspects leading to significant disruptions in one's daily life. The support required comes at a high price, with concerns over geographical access and fitting therapy into one's busy schedules. Most experienced therapists charge on a higher-end for in-person sessions and are often fully booked. Globalization has led to the search for cost-effective "web-based mental health interventions" (Chandrashekar, 2018) to garner assistance for improving psychological well-being. A clinical report published by Pooja Chandrashekar in 2018 (Chandrashekar, 2018) suggests mental health care applications delivering therapeutic interventions supplement in-person therapy treatment, providing mechanisms to alleviate some symptoms and self-manage distressing emotions. Therefore, the health care domain is currently witnessing growth in applications targeted towards mental health care. To curb the stigma surrounding mental health and normalize communication of an individual's feelings or thoughts, the team proposes the development of Therapily. Designed to be an iOS mobile application, Therapily aims to make mental health care easily accessible. It comprises modules for inducing self-awareness and works as a novel form of first-aid for users in overwhelming moments. The application is equipped with tools and techniques to facilitate processing emotions and well-being in a selfhelp context and within a safe, unbiased environment, thereby building an individual's emotional resilience.

Scope and Functionalities
The team plans to take advantage of the increased acceleration of the adoption of mental health services in the digitalized era by incorporating various distinct features currently not present in the applications developed by competitors in the market domain. The overall scope of the Therapily app is discussed below: • The Therapily app is implemented for an iOS platform and targets an audience of 12 and above, belonging to any gender.
• Scope will include developing a deep neural AI network for the emotion detection module that will analyze user facial features to recognize user emotions in real-time via a video feed. The model will also include an eye blink counter which will detect users eye blink rate. This is particularly important to distinguish anxiety. Research shows that when exposed to anxiety inducing activities a person experiences a higher count of blinks, and a lower mean time between blinks (Haak, Bos, Panic & Rothkrantz, 2009) (Giota & kleftaras, 2014). Application will take the output from facial detection and combine the confidence level with symptom selection results to give a final emotion detected result. The AI model will be created with python in Jupyter Notebook to carry out image preprocessing, face detection, and feature classification.
• The app will include the development and deployment of an NLP-enabled chatbot which will be available 24/7 to conduct humanistic calming conversations and therapeutic activities as well as provide suggestions on steps that the user can take for improving their mental and physical well-being. The development will be made through IBM Watson Assistant Platform; integration with the iOS app will be through Watson Software Development Kit (SDK) with swift in XCode.
• The app will include an online consultation platform that will allow users to select doctors available and book a personal consultation appointment on a given date and time. The consultations will take place via Zoom Meetings (video or audio). This module will be implemented with dummy doctors; the project scope does not include approaching and onboarding of professional doctors and therapists.
• Scope will include the creation and deployment of a backend database that will be utilized throughout the user journey for various functional features.
• Scope will include the creation of a functional user interface complying User Experience (UX) principles for all functional requirements with Swift in XCode.
• The scope of this project will not include the creation of therapies for the users. The therapeutic activities and the associated walkthroughs implemented within the application will be suggested by licensed therapists.
All Therapily users will have access to the functional features below to achieve their goals. These functionalities have been curated in accordance with the user requirements. The functionalities outlined below have been grouped into functional groups and they comply with the scope of the application.

User Account
i. Users will be allowed to sign up and create an account to access Therapily.
ii. They can log in with previously created accounts.
iii. They can reset their password while logging in if they have forgotten their login details.
iv. Users also have the freedom to delete their accounts in case they no longer wish to use Therapily.

Emotion Detection
i. Users can use the emotion detection module to understand what emotions they are feeling in the moment. This will take place after the user has granted access to the phone camera and an acceptable video has been recorded.
ii. Select any applicable bodily symptoms if the user is experiencing any.
iii. Select an appropriate contextual scenario of why the user might be experiencing these emotions. This assists the self-awareness process.

Therapeutic Activities
i. Audio, video, and chatbot therapeutic activities will be displayed for the user to select and carry out.
ii. Users will have a chance to rate the activity and submit feedback related to the conducted activity.

Chatbot
i. Users can utilize the chatbot to conduct calming conversations at any given time.
ii. Users will also be able to use the chatbot to conduct some of the therapeutic activities.

Online Consultation
i. Users will be able to view all doctors that are listed on Therapily for online consultations. Users can also view details of all these doctors before booking an appointment with a suitable therapist.
ii. Users will be given access to booking an appointment with their selected doctor. They will be required to select an available date and time. Users will have the choice to modify or delete this booking in future.
iii. After the booking is complete, users can view all scheduled consultations, and their details like doctor name, date, time and the join meeting option.
iv. To attend a consultation, users will be required to have the Zoom App installed on their phone. Once the consultation commences, users will be directed to the doctors meeting room for the audio/video consultation session.

Settings
i. Users will have the freedom to customize their app by adjusting any of the settings like language or time zone.
ii. Users can also change their account settings in case they wish to modify their username, email ID, phone number, or medical history.

FAQ / Help
i. Users will have access to searching for help using keywords. They will be directed to Frequently Asked Questions (FAQs) and their solutions.

Contact Us
i. Users will be given the opportunity to contact Therapily team via Instagram, phone call, email ID, or request form with their queries.

LITERATURE REVIEW
This section entails a brief account of comparable mental health platforms followed by a discussion of how Therapily builds on them thereby promoting selfawareness.

Existing Mental Health Platforms
Research indicates that mental health mobile applications have a positively progressive relationship with a range of issues like stress and depression since they act as a bridge between therapy and adherence to treatment (Chen, Gulatitt, Hamid, Huang, Luo, Morisseau-Leroy, Powell, & Zhan, 2003). Wysa mobile application utilizes a chatbot concept and uses forms of psychotherapy which are Cognitive Behavioral Therapy (CBT) and Dialectical Behavior Therapy (DBT) through chatbot software. Similarly, Sanvello also provides CBT tools to help cope with mild anxiety, depression, and stress. MoodMission is an evidence-based application requiring users to fill in six surveys determining the user's current mood followed by providing therapeutic assistance. 7 Cups app is a chatbased mental health application that provides incognito users and connects them to qualified professionals, mentors, or trainers who can listen and respond accordingly in a proper manner. Likewise, the What's up app employs CBT and Acceptance Commitment Therapy (ACT) to approach mental health issues like stress, anxiety, and depression by providing a journal to maintain recorded progress of good and bad habits and day to day feelings and thoughts. While the above-mentioned applications have been inspirational in the ideation aspect of Therapily's chatbot and online consultation features, most of them such as Wysa, Sanvello, MoodMission, etc., require users to answer questions to label their emotions based on which assistance is provided. The trouble with mental health and emotion regulation is that quite often people are unaware of their current emotion(s)/mood. Moreover, asking users to fill in long monotonous surveys to identify their emotions could be vexing at the time of feeling distressing emotions. Therapily provides a solution for the same by incorporating AI in real-time emotion detection which is discussed in the below sub-section.

Proposed solution -Therapily
The novelty of the proposed mobile application lies in its emotion detection module which is a tool that guides the users in the right direction versus just making a diagnosis. Sometimes people are so confused about what they feel at some point in time which makes it difficult to classify into one category the emotion they are feeling. Sometimes a spectrum or a range is what psychology needs because humans do not actually fall into one box or one category. The same applies to our emotions as well. Thus, this application aims to help people in being more aware of their in the moment emotion(s) by incorporating a threefold approach for the detection of emotions which is in contrast to existing applications, by integrating and analyzing the information obtained through the following techniques constituting the emotion detection module: Firstly, the physical/peripheral aspect of emotion is covered through detecting emotions by analyzing the user's facial expressions using a DL model. Secondly, biosignals/physiological detection represents one spectrum of the bodily symptoms associated with an emotion. This will be integrated as a future enhancement to upgrade the detection efficiency since relying only on facial expressions of a user is not very convenient. This is because facial expressions could sometimes lead to the concealing of a user's actual emotions. Thus, bio-signals cover the internal aspect of emotions and are more reliable since they are not in the control of the user. Lastly, users are asked to select from a list containing distinguishable symptoms related to each distressing emotion. With the above methodology, the main objective is to help people identify and deal with mixed emotions since human behavior and emotions are so complex that they can't just be put into a single category. Moreover, it aims to act as a kickstarter for getting a professional assessment of mental health by helping the user in being conscious of and thus acknowledging recurring distressing emotion

METHODOLOGY Design
Architecture Therapily application is a client server architecture with a centralized system and a distributed structure into three essential tiers: Interface tier, Application tier and Database tier as shown in the figure below. Isolation of tiers allows efficient and simple reconfiguration of the system in case of system failure or updating any one of the tiers without the interruption of the other tiers. Illustrating the tiers in detail, the presentation tier functions as the user interface and communication layer of the app. It overlooks the interaction between the user and the app by collecting relevant input data from the user's end and controlling the output data to be displayed on the application's interface. Protocols like Secure Sockets Layer (SSL) secure the communication process, that is, the transfer of data via GET and POST methods from the client (iOS application) to the server in the application tier. The Application tier is the core tier responsible for logical processing. In this tier, the requests and information collected from the presentation tier are processed with logic and a set of predefined rules defined within the workflow. It also utilizes input data to perform Data Manipulation Language (DML) commands to manipulate data records in the data tier via Application Programming Interface (API) calls. This tier is an intermediary enabling communication between the presentation tier and the data tier. It comprises application servers for query processing against the Jupyter server storing the trained model to detect users' emotions through facial expressions and provide feedback in the form of emotions recognized. The application server will also enable the storage and retrieval of information from the Cloud Firestore database. In addition, the tier will contain the trained Watson Assistant running the Watson service instance to receive user responses and provide appropriate feedback after processing.
The Data-tier is responsible for storing and managing information processed by the app throughout its life cycle. The tier comprising NoSQL document database -Cloud Firestore will store, index, manage and model information needed for the application. The database will model and optimize the query to enhance database performance and provide quick access to data required by the user (Education, 2021). The database will also perform the necessary validation and verification of user data. This architecture offers the following benefits due to which it was chosen for Therapily: • High security: In this architecture, the presentation tier and data tier cannot communicate directly thus the "application tier functions as a kind of internal firewall thereby preventing Structured Query Language (SQL) injections and any other malicious exploits" (Logi Analytics, 2021).
• High reliability: A downtime in one tier doesn't significantly impact the availability/performance of the other two tiers (Hollemans, 2022).
• Low requirements for technical characteristics of a mobile phone (Hollemans, 2022).
• Easy and cheap to build functionality and update the system software.
• Extensive scalability, flexibility, and maintainability: This architecture provides ease of maintenance and an ability to scale and update one tier's technology stack without affecting other tiers and application as a whole (Hollemans, 2022).

High Level Design
Below is the package diagram which gives an overview of how the system packages will look.

Implementation
The iOS application was implemented using Python 2.6 for deep learning (DL) model training, IBM Watson Assistant for backend chatbot implementation, CoreML for DL model deployment, Swift 13.1 in XCode for frontend user interface (UI) implementation and Firebase Firestore as the backend app database.

Emotion Detection
The deep learning model was built and trained using the compiler program Jupyter Notebook in an Anaconda environment. Keras and Tensorflow-gpu libraries were utilized for modeling. Neural networks perform numerous computations which makes it increasingly important that they run efficiently on computing power deficit devices like smartphones. Since the DL model was to be deployed in an iOS mobile application, MobileNetV2 Convolutional Neural Network (CNN) which is 53 layers deep was chosen. Fewer calculations i.e., around 300 megaFLOPS (MFLOPS) are computed as compared to other architectures such as VGGNet or Inception (coremltools, 2022). This made MobileNetV2 as the most suitable CNN architecture for mobile vision application, Therapily. The FER2013 dataset was acquired from Kaggle. It contains 48x48 grayscale images of faces for 7 emotions (0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral). However, only the data for emotions Happy, Fear, Sad and Anger were used from the dataset. ImageDataGenerator class from TensorFlow was utilized to configure random transformations on the image data to augment them. This was done to prevent overfitting, maximize feature extraction thereby making the model generalize better. The network takes 224x224 grayscale images. Hence, before the dataset is fed to the network, the image size of the dataset has been resized to 224x224 using the target_ size parameter of Image Data Generator. Transfer learning was performed using Mobile NetV2 which is pre-trained on the Image Net dataset. This was used as the base model to train on the FER2013 dataset. The output from the 6th to the last layer of the model was used to build a new model suitable for the dataset at hand. The new model created consisted of the original MobileNetV2 model till the 6th last layer. The last five layers of the original architecture were excluded which was decided after thorough experimentation. A Dense layer consisting of 4 output nodes for the 4 classes was created using the softmax activation function. Keras Functional API i.e., Model constructor was used to create the model for which the input was equal to the input of the original MobileNetV2 architecture. The output was set as the aforementioned Dense layer with 4 output nodes. The weights of most of the earlier layers were frozen to retain what the original model learned from the ImageNet dataset. However, after experimentation, it was deduced that training the last 29 layers gave a decent performing model. In other terms, from the first layer to layer 28, the original ImageNet weights are frozen whereas from layer 29 to the last layer, all the layers are trained by fitting the model to the FER2013 dataset. The model was compiled using the Adam optimizer with a learning rate of 0.001, categorical crossentropy loss function and accuracy metric, to measure the model performance.
The input to the network has been divided into batches of 2014 images. The model was trained for 100 epochs. Tensorflow-gpu was used to train the model, which was completed in around 3 hours. The parameters of the model applied are as shown in Table I.
CoreML framework was utilized to integrate the DL model into the application. The app uses Core ML APIs and the data acquired from the user, to make predictions on the user's device. Privacy of the user's data is assured by running the model strictly on the device which prevents the need for a network connection (IBM, 2022). AVKit, UIKit, Vision, and CoreImage libraries were used in the swift implementation of the emotion detection module consisting of detecting emotions Happy, Fear, Sad and Angry using the DL model and detecting eye blinks for the recognition of the anxiety emotion from the user's 15 second frontal real-time video feed. Since the video feed consists of multiple frames and each frame is analyzed by the DL model and the eye detection algorithm, the results i.e., levels of the 5 emotions for all the frames, are averaged and displayed on the screen.

Therapeutic Activities
Using the results from the emotion detection module, audio/video therapeutic activities are retrieved from the Firebase Firestore which was used as the backend database to store the names of the distressing emotions that the application addresses, along with the corresponding contextual scenarios and the names of the therapeutic activities. UIKit, AVKit and AVFoundation libraries were used to implement the custom audio/video player and the activity review form.

Chatbot
The NLP-enabled AI Chatbot integrated within the The testing accuracy achieved was 72%. A confusion matrix was plotted using the scikit-learn library as shown in Figure. 3.

Figure 3: Confusion Matrix
Am. J. Multidis. Res. Innov. 1(6) 127-135, 2022 application was built and trained in the IBM Cloud Lite services of IBM Watson Assistant. The Virtual Assistant Therapily is designed after creating a Watson Assistant service instance. The Assistant layer acts as the face of the Virtual Assistant and comprises the extensive component -Dialog Skill (Bhargava, 2020). Watson Dialog Skill primarily includes the AI-driven components -Intents, Entities, and Dialog nodes enabling the creation of personalized dialog.

Intents
Commonly described as the user's intention expressed in their utterance or a task/action specified by the user (Du, Long & Yuan., 2017). The Watson Assistant was trained with intents as shown in Figure. 4, each comprising multiple unique examples for Watson to comprehend the user's goal from the phrases entered.

Entities
Elements or specific words extracted from the user's utterance, crucial to perform the user's goal specified through intents (Du, Long & Yuan., 2017). The Watson Assistant was trained with entities as shown in Figure. 5, each comprising multiple categories of values and their synonyms for Watson to match and detect from the user's input.

Dialog Nodes
The dialog tree has been designed to contain 115 nodes archived in uniquely named folders, forming an extensive chatbot workflow to enable users to conduct various therapeutic activities and encourage well-being in a self-help context. Each node is triggered upon various combinations of intents and entities recognized from the user's utterance (IBM, 2022). The distressing emotions targeted within this application usually cause an increase in blood activity and reduce breathing capacity. Therefore, the chatbot incorporates relaxing mechanisms and converses with the user to stimulate their minds to reduce cortisol levels and help users breathe. There are a total of 9 activities conducted with the chatbot. These include Happiness activity, Mood Journal, Grounding exercise, Introspection activity, self-compassion activity, remembrance activity, reassurance activity, self-love affirmation activity, and rewrite your story activity. Some of these activities are dialogue-based, which stimulates a humanistic conversation with the user, while the other activities are video-based, which walk the user through the calming task. Activities such as Mood Journal follow the concept of CBT which aids in emotional awareness by enabling users to evaluate their outlook on a situation, reason out and justify their emotions. With the help of the intents mentioned above, entities, and meaningful phrases, the chatbot is trained to acknowledge users' emotions rather than make them feel uncomfortable about emoting such feelings by providing empathetic, semantic, and educational responses simulating humanistic behavior.  (Bhargava, 2020).

Online Consultation
Online consultation module has implemented all the functional features to ensure that a user can successfully browse doctors, book an appointment, modify, or delete the booking, view the scheduled consultations, and join the meeting successfully. The functionalities were deployed with connection to the Firebase Firestore backend for data storage and retrieval. The UI screens were developed in Xcode using Swift. These screens were connected via multiple segues to ensure a smooth navigational experience. Booking of appointments and consultation viewing was based on the unique document IDs associated with consultation bookings stored in the database. Libraries such as FSCalendar, Firebase, UIKit were used in the process to display calendars, connect to the database, open zoom meetings, and display relevant information in the table view cells.

Prototype Testing Results
The Therapily application was tested to ensure that functional and non-functional requirements are met for the production release of the application to the general public. This testing was to detect any bugs, defects and issues faced with the functionalities, come up with solutions for the same and implement them. The  Incorporate a text-to-speech feature for the chatbot. Tester 2 Quite an interesting application for a good cause. If possible, take timely user feedback to improve model and application Tester 3 Very interesting and helpful from a professional psychologist's point of view. Maybe try to add activities from a scientific book -Brinnie Brown's "Gifts of Imperfection". Tester 4 Seems like a necessary app in today's world. Improve chatbot feedback. Reduce face inspection time; during frustrating times people do not want to wait for a long period of time Tester 5 Beautiful user interface. A good improvement could be taking parent name and number to give children report / feedback Tester 6 From a psychologist's perspective, few modules within the app could be improved. The emotion detection model and chatbot could be refined with the activities conducted within comprising a UI/ UX design involving more graphics and less text-based content. More contextual scenarios could be added. The medical history could allow patients to explicitly list down family history, medication, description regarding complaints or emotions felt, daily stressors, etc. and these details when shared with the consulting therapist would enable them to approach the patient in a better way. Tester 7 As a person who had been suffering from mental health issues, this application seems very helpful and soothing. Something I would definitely use quite often. Tester 8 Very beautiful app, very helpful for people going through tough times and can be quite useful for selfawareness for someone who doesn't know what they are going through.
developed iOS app was tested with a sample of 8 random people in a natural environment setting with an iPhone 11 which has Therapily application installed. It should be noted that so far preliminary testing has been conducted to evaluate functional and navigational aspects of the system and interface. However, as the development progresses, more rigorous and large-scale testing will be carried out covering all necessary facets of application testing. The traceability matrix in Table 2 summarizes the testing result for each functional requirement. Overall, the testing of the app was satisfactory with adequate results. The feedback gathered from participants as shown in Table  3, have been taken into consideration for future changes of the application.

CONCLUSION AND FUTURE WORK
Combining the power of AI with the portability of smartphones can yield efficient and effective mental health assistance solutions. In this paper, a new mobile application, Therapily, is proposed which makes use of various AI branches to provide a type of first aid for mental health to users in their moment of need. Therapily comprises an emotion detection module leveraging computer vision, thereby promoting selfawareness. This module entails analyzing the user's facial expressions to recognize in-the-moment emotion(s) followed by suggesting audio-visual and/or chatbot therapeutic activities based on the results. To predict the emotion of a user, a deep learning-based CNN model MobileNetV2 was utilized and trained on FER2013 which resulted in an accuracy rate of 72%. It can be gleaned from the evaluation metrics that further model tuning is required to improve the performance, which is integral since Therapily deals with the sensitive domain of mental health. The application also consists of an NLP-based chatbot built on the premise of CBT, guiding users through the acknowledgment and management of distressing emotions. Users can also conduct online consultations with licensed and experienced free-lancing or medical center-based therapists.
To further improve the user experience the system is likely to be extended or modified which will be discussed in detail in subsequent papers. In future versions of the application, a voice bot, which is a chatbot that uses a voice channel for communication, will be incorporated to make the application more accessible and inclusive to a larger customer base. The bot will further be trained to make it capable of understanding cultural nuances. The responses will be improved by making the chatbot learn human behavior through scanning of previous conversations with users. Adoption of "bio-signals/physiological signals such as Heartbeat (HR), Photoplethysmogram (PPG), Electrocardiogram (ECG) and Electroencephalogram (EEG) which provide continuous measurements and are out of an individual's control" (Du, Long & Yuan., 2017) will be considered, to obtain more accurate emotion detection results. The deep learning model will be enhanced to predict and train on the incoming user data-stream to automatically improve itself. Lastly, a payment portal will also be implemented so that consultations can be charged instead of keeping it free.