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