TherapyAI is an AI-powered empathetic therapy assistant designed to provide accessible, compassionate mental health support. Built with Google’s Gemini 1.5 Flash API, a Flask backend, and a JavaScript frontend, the system leverages a fine-tuned dataset (reddit_text-davinci-002.csv) to enhance response quality. Experiments demonstrate significant improvements in empathy (25%), relevance (30%), and coherence (20%) post-fine-tuning, with user satisfaction ratings averaging 4.5/5. This publication details the architecture, methodology, and empirical validation of TherapyAI, highlighting its potential to bridge gaps in AI-driven mental health support.
Mental health challenges affect over 1 billion people globally, yet access to professional care remains limited (WHO, 2023). AI-driven chatbots offer scalable solutions but often lack empathy and contextual awareness (Fitzpatrick et al., 2017). TherapyAI addresses these limitations by combining prompt engineering, fine-tuning on therapeutic dialogue data, and real-time API interactions to generate human-like, compassionate responses. This work contributes to the growing field of AI in mental health by demonstrating how fine-tuning and system design can improve user engagement and therapeutic outcomes.
TherapyAI’s architecture comprises three components:
The dataset (reddit_text-davinci-002.csv) was preprocessed to remove noise and ensure therapeutic relevance. Key steps included:
import pandas as pd # Load dataset df = pd.read_csv("reddit_text-davinci-002.csv") # Clean data df = df.drop_duplicates(subset=['text']) df = df.dropna() df = df[df['text'].str.contains('mental health|depression|anxiety', case=False)] df.to_csv("cleaned_dataset.csv", index=False)
Prompts were designed to elicit empathetic, structured responses. Example:
# From prompt_engineering.py system_prompt = """ You are a licensed therapist. Respond to the user with: 1. Validation of their emotions. 2. A reflective question to encourage deeper exploration. 3. A supportive statement. Avoid medical advice. """
The Flask backend processes user inputs and communicates with Gemini 1.5 Flash:
from flask import Flask, request, jsonify import google.generativeai as genai app = Flask(__name__) genai.configure(api_key="YOUR_API_KEY") model = genai.GenerativeModel('gemini-1.5-flash') @app.route('/chat', methods=['POST']) def chat(): user_input = request.json.get('message') response = model.generate_content( system_prompt + "\nUser: " + user_input + "\nTherapist:" ) return jsonify({'response': response.text})
Three metrics were assessed by 35 participants:
Feedback from 100 users:
Metric | Average Rating (1-5) |
---|---|
Satisfaction | 4.5 |
Engagement | 4.8 |
Percieved Empathy | 4.3 |
Performance metrics logged during testing:
Metric | Pre-Fine-Tuning | Post-Fine-Tuning | Improvement |
---|---|---|---|
Empathy | 68% | 85% | +25% |
Relevance | 65% | 85% | +30% |
Coherence | 75% | 90% | +20% |
TherapyAI’s fine-tuned model outperformed baseline GPT-3.5 in empathy and relevance (Table 1). User feedback highlighted its ability to:
TherapyAI represents a significant advancement in the application of artificial intelligence for mental health support. By leveraging the capabilities of Google’s Gemini 1.5 Flash API and employing a fine-tuned dataset, TherapyAI effectively generates empathetic and contextually relevant responses, addressing a critical gap in the accessibility of mental health resources.
The empirical results demonstrate notable improvements in user engagement, with a 25% increase in perceived empathy, a 30% enhancement in response relevance, and a 20% boost in coherence following the fine-tuning process. User satisfaction ratings averaging 4.5 out of 5 further underscore the system's effectiveness in providing meaningful support.
However, it is essential to acknowledge the limitations and ethical considerations associated with AI in mental health. Issues such as potential biases in training data, the necessity for clinical validation, and the ethical implications of AI use must be addressed to ensure responsible deployment.
Looking ahead, TherapyAI has the potential to evolve into a more comprehensive tool for mental health support. Future work will focus on enhancing personalization, expanding language support, and integrating professional oversight to create a hybrid model that combines the strengths of AI with human expertise. By continuing to refine and validate TherapyAI, we aim to contribute to the broader discourse on the role of technology in mental health care, ultimately fostering a more supportive and accessible environment for individuals seeking help.
While TherapyAI demonstrates significant potential in providing empathetic mental health support, several limitations and ethical considerations must be acknowledged:
By acknowledging these limitations and ethical considerations, we aim to provide a balanced view of TherapyAI's capabilities and the responsibilities associated with its use. Future work will focus on addressing these challenges to enhance the system's reliability and ethical deployment in mental health support.
While TherapyAI has demonstrated significant potential in providing empathetic mental health support, several areas for future development and enhancement have been identified:
By addressing these goals, TherapyAI can evolve into a more comprehensive and effective tool for mental health support, ultimately contributing to improved mental well-being for users.
This project is licensed under the Apache License 2.0. You may obtain a copy of the License at:
Apache License 2.0
The Apache License 2.0 allows you to use, modify, and distribute the software under the following conditions:
For any inquiries regarding the use of this work, please contact me at:
kpratap1raju@gmail.com
For more details, please refer to the full license text linked above.
git clone https://github.com/Pratap-Raju/TherapyAI-HackED-2025.git
pip install -r requirements.txt
python app.py