Spaces:
Runtime error
Runtime error
Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Personalized Mental Health Assistant
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
This project is an AI-powered **Mental Health Assistant** that analyzes user queries, detects emotions, and provides relevant responses and resources. It leverages **NLP (Natural Language Processing)** techniques and **Machine Learning (ML)** models for sentiment analysis, emotion classification, and response generation.
|
5 |
+
|
6 |
+
## Features
|
7 |
+
- **Sentiment & Emotion Detection**: Classifies user queries based on emotions (Happy, Sad, Anxious, Overwhelmed, etc.).
|
8 |
+
- **Preprocessing Pipeline**: Cleans and preprocesses text data using **NLTK**.
|
9 |
+
- **TF-IDF Vectorization**: Converts user queries into numerical representations.
|
10 |
+
- **ML Classification**: Uses a **Random Forest Classifier** to predict emotions.
|
11 |
+
- **Response Generation**: Suggests appropriate responses based on detected emotions.
|
12 |
+
- **AWS Deployment**: Deploys as an API using **Flask & AWS Lambda**.
|
13 |
+
|
14 |
+
## Dataset Columns
|
15 |
+
The dataset includes the following columns:
|
16 |
+
| Column | Description |
|
17 |
+
|--------|-------------|
|
18 |
+
| ID | Unique identifier for each query |
|
19 |
+
| User Query | Raw text input from the user |
|
20 |
+
| Preprocessed Text | Cleaned version of the user query |
|
21 |
+
| Sentiment | Sentiment label (Positive, Neutral, Negative) |
|
22 |
+
| Emotion | Emotion label (e.g., Happy, Sad, Anxious) |
|
23 |
+
| Severity | Severity level of distress |
|
24 |
+
| Intent | Intent classification for responses |
|
25 |
+
| Suggested Response | AI-generated response for user support |
|
26 |
+
| Recommended Action | Suggested action based on the query |
|
27 |
+
| Related Resources | External resources for mental health support |
|
28 |
+
| Time of Interaction | Timestamp of the query |
|
29 |
+
|
30 |
+
---
|
31 |
+
## Installation
|
32 |
+
### **1. Clone Repository**
|
33 |
+
```bash
|
34 |
+
git clone https://github.com/your-repo/mental-health-assistant.git
|
35 |
+
cd mental-health-assistant
|
36 |
+
```
|
37 |
+
|
38 |
+
### **2. Install Dependencies**
|
39 |
+
```bash
|
40 |
+
pip install -r requirements.txt
|
41 |
+
```
|
42 |
+
|
43 |
+
### **3. Download NLTK Resources**
|
44 |
+
```python
|
45 |
+
import nltk
|
46 |
+
nltk.download('stopwords')
|
47 |
+
nltk.download('wordnet')
|
48 |
+
```
|
49 |
+
|
50 |
+
---
|
51 |
+
## Training the Model
|
52 |
+
### **Step 1: Preprocess and Train**
|
53 |
+
```python
|
54 |
+
python train.py
|
55 |
+
```
|
56 |
+
This script:
|
57 |
+
- Loads the dataset.
|
58 |
+
- Preprocesses text using **NLTK**.
|
59 |
+
- Extracts features using **TF-IDF**.
|
60 |
+
- Trains a **Random Forest Classifier**.
|
61 |
+
- Saves the trained model and vectorizer.
|
62 |
+
|
63 |
+
### **Step 2: Test Model with Example Queries**
|
64 |
+
```python
|
65 |
+
python test.py
|
66 |
+
```
|
67 |
+
---
|
68 |
+
## Deployment on AWS
|
69 |
+
This project can be deployed on **AWS Lambda & API Gateway** using Flask.
|
70 |
+
|
71 |
+
### **1. Create an AWS Lambda Function**
|
72 |
+
1. Package your code into a **ZIP file**:
|
73 |
+
```bash
|
74 |
+
zip -r deployment.zip *
|
75 |
+
```
|
76 |
+
2. Upload the ZIP file to AWS Lambda.
|
77 |
+
3. Set the runtime to **Python 3.8+**.
|
78 |
+
4. Create a handler function (`lambda_function.py`):
|
79 |
+
|
80 |
+
```python
|
81 |
+
from flask import Flask, request, jsonify
|
82 |
+
import joblib
|
83 |
+
|
84 |
+
app = Flask(__name__)
|
85 |
+
model = joblib.load("mental_health_model.pkl")
|
86 |
+
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
87 |
+
label_encoder = joblib.load("label_encoder.pkl")
|
88 |
+
|
89 |
+
def predict_emotion(query):
|
90 |
+
vectorized_input = vectorizer.transform([query]).toarray()
|
91 |
+
prediction = model.predict(vectorized_input)
|
92 |
+
return label_encoder.inverse_transform(prediction)[0]
|
93 |
+
|
94 |
+
@app.route("/predict", methods=["POST"])
|
95 |
+
def predict():
|
96 |
+
data = request.get_json()
|
97 |
+
query = data.get("query", "")
|
98 |
+
response = predict_emotion(query)
|
99 |
+
return jsonify({"emotion": response})
|
100 |
+
|
101 |
+
if __name__ == "__main__":
|
102 |
+
app.run()
|
103 |
+
```
|
104 |
+
5. Deploy with **AWS API Gateway** to create an endpoint.
|
105 |
+
|
106 |
+
### **2. Access API**
|
107 |
+
Once deployed, you can access the API via:
|
108 |
+
```bash
|
109 |
+
curl -X POST "https://your-api-gateway-url.amazonaws.com/prod/predict" -H "Content-Type: application/json" -d '{"query": "I feel stressed and anxious."}'
|
110 |
+
```
|
111 |
+
|
112 |
+
---
|
113 |
+
## Future Improvements
|
114 |
+
- **Use Deep Learning (LSTMs, Transformers)** for better accuracy.
|
115 |
+
- **Integrate GPT-based models** for advanced response generation.
|
116 |
+
- **Expand dataset** to include more diverse mental health situations.
|
117 |
+
|
118 |
+
---
|
119 |
+
## License
|
120 |
+
MIT License. Free to use and modify.
|
121 |
+
|
122 |
+
---
|
123 |
+
## Contributors
|
124 |
+
- **Your Name** – [GitHub Profile](https://github.com/your-github)
|
125 |
+
- **Open for Contributions** 🚀
|