Spaces:
Paused
Paused
Nada commited on
Commit ·
a82eaf8
1
Parent(s): 4d7ee49
up
Browse files
README.md
CHANGED
|
@@ -1,257 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
- Conversation memory
|
| 10 |
-
- Therapeutic techniques integration
|
| 11 |
-
- Risk flag detection and crisis intervention
|
| 12 |
-
- Automatic detection of high-risk messages
|
| 13 |
-
- Immediate crisis response protocol
|
| 14 |
-
- Professional support referral system
|
| 15 |
-
- Emergency contact information
|
| 16 |
-
- RESTful API interface
|
| 17 |
-
- Session management and summaries
|
| 18 |
-
- User reply tracking for another depression and anxiety detection from text.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
## Risk Flag Detection
|
| 22 |
-
|
| 23 |
-
The chatbot automatically monitors messages for potential risk indicators and provides appropriate crisis intervention responses.
|
| 24 |
-
|
| 25 |
-
### Risk Indicators
|
| 26 |
-
The system detects various risk-related keywords and phrases, including but not limited to:
|
| 27 |
-
- Self-harm references
|
| 28 |
-
- Suicidal ideation
|
| 29 |
-
- Extreme emotional distress
|
| 30 |
-
- Crisis situations
|
| 31 |
-
|
| 32 |
-
### Crisis Response Protocol
|
| 33 |
-
When risk flags are detected:
|
| 34 |
-
1. Immediate crisis response is triggered
|
| 35 |
-
2. User is provided with:
|
| 36 |
-
- Emergency contact information
|
| 37 |
-
- Professional support options
|
| 38 |
-
- Immediate coping strategies
|
| 39 |
-
3. Option to connect with licensed professionals
|
| 40 |
-
4. Grounding exercises and calming techniques
|
| 41 |
-
|
| 42 |
-
### Example Crisis Response
|
| 43 |
-
```json
|
| 44 |
-
{
|
| 45 |
-
"response":"I'm really sorry you're feeling this way — it sounds incredibly heavy,and I want you to know that you're not alone. You don't have to face this by yourself.Our app has licensed mental health professionals ready to support you.I can connect you with one right now if you'd like.Would you like to connect with a professional now,or would you rather keep talking with me for a bit? Either way, I'm here for you.",
|
| 46 |
-
"session_id": "user123_20240314103000",
|
| 47 |
-
"risk_detected": true,
|
| 48 |
-
"crisis_protocol_activated": true
|
| 49 |
-
}
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
## Setup
|
| 53 |
-
|
| 54 |
-
1. Install the required dependencies:
|
| 55 |
-
```bash
|
| 56 |
-
pip install -r requirements.txt
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
2. Download the required NLTK data:
|
| 60 |
-
```bash
|
| 61 |
-
python -m nltk.downloader punkt
|
| 62 |
-
```
|
| 63 |
-
|
| 64 |
-
3. Run the chatbot server:
|
| 65 |
-
```bash
|
| 66 |
-
python app.py
|
| 67 |
-
```
|
| 68 |
-
|
| 69 |
-
The server will start on `http://127.0.0.1:8000`
|
| 70 |
-
|
| 71 |
-
## API Documentation
|
| 72 |
-
|
| 73 |
-
### Base URL
|
| 74 |
-
```
|
| 75 |
-
http://127.0.0.1:8000
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
### API Endpoints
|
| 79 |
-
|
| 80 |
-
#### 1. Start a Session
|
| 81 |
-
```http
|
| 82 |
-
POST /start_session?user_id={user_id}
|
| 83 |
-
```
|
| 84 |
-
|
| 85 |
-
Example:
|
| 86 |
-
```bash
|
| 87 |
-
curl -X 'POST' \
|
| 88 |
-
'http://127.0.0.1:8000/start_session?user_id=user123' \
|
| 89 |
-
-H 'accept: application/json'
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
Response:
|
| 93 |
-
```json
|
| 94 |
-
{
|
| 95 |
-
"response": "Hello! I'm here to support you today. How have you been feeling lately?",
|
| 96 |
-
"session_id": "user123_20240314103000"
|
| 97 |
-
}
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
#### 2. Send a Message
|
| 101 |
-
```http
|
| 102 |
-
POST /send_message
|
| 103 |
-
Content-Type: application/json
|
| 104 |
-
|
| 105 |
-
{
|
| 106 |
-
"user_id": "user123",
|
| 107 |
-
"message": "I'm feeling anxious today"
|
| 108 |
-
}
|
| 109 |
-
```
|
| 110 |
-
|
| 111 |
-
Example:
|
| 112 |
-
```bash
|
| 113 |
-
curl -X 'POST' \
|
| 114 |
-
'http://127.0.0.1:8000/send_message' \
|
| 115 |
-
-H 'accept: application/json' \
|
| 116 |
-
-H 'Content-Type: application/json' \
|
| 117 |
-
-d '{
|
| 118 |
-
"user_id": "user123",
|
| 119 |
-
"message": "I'\''m feeling anxious today"
|
| 120 |
-
}'
|
| 121 |
-
```
|
| 122 |
-
|
| 123 |
-
Response:
|
| 124 |
-
```json
|
| 125 |
-
{
|
| 126 |
-
"response": "I understand you're feeling anxious. Can you tell me more about what's causing this?",
|
| 127 |
-
"session_id": "user123_20240314103000"
|
| 128 |
-
}
|
| 129 |
-
```
|
| 130 |
-
|
| 131 |
-
#### 3. Get User Replies
|
| 132 |
-
```http
|
| 133 |
-
GET /user_replies/{user_id}
|
| 134 |
-
```
|
| 135 |
-
|
| 136 |
-
Example:
|
| 137 |
-
```bash
|
| 138 |
-
curl -X 'GET' \
|
| 139 |
-
'http://127.0.0.1:8000/user_replies/user123' \
|
| 140 |
-
-H 'accept: application/json'
|
| 141 |
-
```
|
| 142 |
-
|
| 143 |
-
Response:
|
| 144 |
-
```json
|
| 145 |
-
{
|
| 146 |
-
"user_id": "user123",
|
| 147 |
-
"timestamp": "2024-03-14T10:30:00",
|
| 148 |
-
"replies": [
|
| 149 |
-
{
|
| 150 |
-
"text": "I'm feeling anxious today",
|
| 151 |
-
"timestamp": "2024-03-14T10:30:00",
|
| 152 |
-
"session_id": "user123_20240314103000"
|
| 153 |
-
}
|
| 154 |
-
]
|
| 155 |
-
}
|
| 156 |
-
```
|
| 157 |
-
|
| 158 |
-
#### 4. Get Session Summary
|
| 159 |
-
```http
|
| 160 |
-
GET /session_summary/{session_id}?include_summary={boolean}&include_recommendations={boolean}&include_emotions={boolean}&include_characteristics={boolean}&include_duration={boolean}&include_phase={boolean}
|
| 161 |
-
```
|
| 162 |
-
|
| 163 |
-
Example:
|
| 164 |
-
```bash
|
| 165 |
-
curl -X 'GET' \
|
| 166 |
-
'http://127.0.0.1:8000/session_summary/user123_20240314103000?include_summary=true&include_recommendations=true&include_emotions=true&include_characteristics=false&include_duration=false&include_phase=false' \
|
| 167 |
-
-H 'accept: application/json'
|
| 168 |
-
```
|
| 169 |
-
|
| 170 |
-
Response:
|
| 171 |
-
```json
|
| 172 |
-
{
|
| 173 |
-
"session_id": "user123_20240314103000",
|
| 174 |
-
"user_id": "user123",
|
| 175 |
-
"start_time": "2024-03-14T10:30:00",
|
| 176 |
-
"end_time": "2024-03-14T10:45:00",
|
| 177 |
-
"summary": "Session focused on anxiety management...",
|
| 178 |
-
"recommendations": [
|
| 179 |
-
"Practice deep breathing exercises",
|
| 180 |
-
"Consider journaling your thoughts"
|
| 181 |
-
],
|
| 182 |
-
"primary_emotions": ["anxiety", "stress"],
|
| 183 |
-
"emotion_progression": ["anxiety", "calm"],
|
| 184 |
-
"duration_minutes": 0.0,
|
| 185 |
-
"current_phase": "unknown",
|
| 186 |
-
"session_characteristics": {}
|
| 187 |
-
}
|
| 188 |
-
```
|
| 189 |
-
|
| 190 |
-
#### 5. End Session
|
| 191 |
-
```http
|
| 192 |
-
POST /end_session?user_id={user_id}
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
Example:
|
| 196 |
-
```bash
|
| 197 |
-
curl -X 'POST' \
|
| 198 |
-
'http://127.0.0.1:8000/end_session?user_id=user123' \
|
| 199 |
-
-H 'accept: application/json'
|
| 200 |
-
```
|
| 201 |
-
|
| 202 |
-
Response: Complete session summary with all fields.
|
| 203 |
-
|
| 204 |
-
#### 6. Health Check
|
| 205 |
-
```http
|
| 206 |
-
GET /health
|
| 207 |
-
```
|
| 208 |
-
|
| 209 |
-
Example:
|
| 210 |
-
```bash
|
| 211 |
-
curl -X 'GET' \
|
| 212 |
-
'http://127.0.0.1:8000/health' \
|
| 213 |
-
-H 'accept: application/json'
|
| 214 |
-
```
|
| 215 |
-
|
| 216 |
-
Response:
|
| 217 |
-
```json
|
| 218 |
-
{
|
| 219 |
-
"status": "healthy"
|
| 220 |
-
}
|
| 221 |
-
```
|
| 222 |
-
|
| 223 |
-
## Integration Guidelines
|
| 224 |
-
|
| 225 |
-
### Best Practices
|
| 226 |
-
1. Always store the `session_id` returned from `/start_session`
|
| 227 |
-
2. Use the same `user_id` throughout a conversation
|
| 228 |
-
3. Include appropriate error handling for API responses
|
| 229 |
-
4. Monitor the health endpoint for system status
|
| 230 |
-
|
| 231 |
-
### Error Handling
|
| 232 |
-
The API returns standard HTTP status codes:
|
| 233 |
-
- 200: Success
|
| 234 |
-
- 400: Bad Request
|
| 235 |
-
- 404: Not Found
|
| 236 |
-
- 500: Internal Server Error
|
| 237 |
-
|
| 238 |
-
Error responses include a detail message:
|
| 239 |
-
```json
|
| 240 |
-
{
|
| 241 |
-
"detail": "Error message here"
|
| 242 |
-
}
|
| 243 |
-
```
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
## Important Notes
|
| 247 |
-
|
| 248 |
-
- This is not a replacement for professional mental health care
|
| 249 |
-
- Always seek professional help for serious mental health concerns
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
## Privacy and Security
|
| 253 |
-
|
| 254 |
-
- Conversations are stored in memory only
|
| 255 |
-
- No personal data is permanently stored
|
| 256 |
-
- The system is designed to be HIPAA-compliant
|
| 257 |
-
- Users are identified by unique IDs only
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Conversational Chat
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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