File size: 36,682 Bytes
d4bef91 | 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | """
recommendations.py
==================
Bilingual (EN + AR) recommendation system.
Uses:
- primary disease (anxiety / depression / stress)
- severity (mild / moderate / severe) from DASS-42 scores
- cause (extracted from user text)
- suicidal flag (extracted from user text)
"""
import re
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 1. SEVERITY FROM DASS-42 SCORES
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# DASS-42 official cutoffs (raw sum, not percentage)
DASS_CUTOFFS = {
"depression": [(0, 9, "normal"), (10, 13, "mild"), (14, 20, "moderate"),
(21, 27, "severe"), (28, 999, "extremely_severe")],
"anxiety": [(0, 7, "normal"), (8, 9, "mild"), (10, 14, "moderate"),
(15, 19, "severe"), (20, 999, "extremely_severe")],
"stress": [(0, 14, "normal"),(15, 18, "mild"),(19, 25, "moderate"),
(26, 33, "severe"), (34, 999, "extremely_severe")],
}
def get_severity(disease: str, raw_score: float, max_score: float = 1.0) -> str:
"""
raw_score: ุฅู
ุง ูุณุจุฉ (0-1) ู
ู ุงูู
ูุฏููุ ูุฅู
ุง raw DASS score
ุจูุญููู ุงููุณุจุฉ ูู raw score ุชูุฑูุจู ุนุดุงู ููุฏุฑ ูุณุชุฎุฏู
ุงูู cutoffs
"""
# ูู ุฌุงู ู
ู ุงูู
ูุฏูู ููุณุจุฉ (0-1)ุ ูุญูููู ูู raw score ุชูุฑูุจู
if max_score == 1.0:
# DASS-42 depression max=84, anxiety max=72, stress max=84
max_raw = {"depression": 84, "anxiety": 72, "stress": 84}
score = int(raw_score * max_raw.get(disease, 84))
else:
score = int(raw_score)
for low, high, label in DASS_CUTOFFS.get(disease, []):
if low <= score <= high:
return label
return "severe"
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 2. CAUSE EXTRACTION FROM TEXT
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
CAUSE_KEYWORDS = {
"work": [
"ุดุบู", "ุนู
ู", "ูุธููุฉ", "ู
ุฏูุฑ", "boss", "deadline", "ู
ุดุฑูุน", "project",
"office", "ู
ูุชุจ", "ุฑุงุชุจ", "salary", "overtime", "job", "work", "career",
"ูุซูุฑ ุดุบู", "ุถุบุท ุดุบู", "ู
ุด ูุงุฏุฑ ุฃูู
ู ุดุบู", "tired from work",
],
"relationships": [
"ุญุจูุจ", "ุญุจูุจุฉ", "ุฒูุฌ", "ุฒูุฌุฉ", "ุฌูุฒ", "ู
ุฑุงุชู", "ุนูุงูุฉ", "relationship",
"ุฃูู", "ุนููุฉ", "family", "ุตุงุญุจ", "ุตุญุงุจ", "friend", "ุฎูุงูุฉ", "betrayal",
"ูุฑุงู", "breakup", "ุทูุงู", "divorce", "ูุญูุฏ", "lonely", "ุฎูุงู", "conflict",
],
"financial": [
"ูููุณ", "ู
ุงู", "money", "ุฏูู", "debt", "ููุฑ", "ู
ุตุงุฑูู", "broke",
"ุฅูุฌุงุฑ", "rent", "ู
ุฏููู", "financial", "ุจุทุงูุฉ", "unemployment",
],
"academic": [
"ุฏุฑุงุณุฉ", "ุงู
ุชุญุงู", "exam", "ุฌุงู
ุนุฉ", "university", "ู
ุฏุฑุณุฉ", "school",
"ุฏุฑุฌุงุช", "grades", "ุฑุณูุจ", "fail", "ู
ุฐุงูุฑุฉ", "study", "ุชุฎุฑุฌ",
],
"health": [
"ู
ุฑุถ", "ูุฌุน", "pain", "ุตุญุฉ", "health", "doctor", "ุฏูุชูุฑ", "ู
ุณุชุดูู",
"hospital", "ุนูุงุฌ", "treatment", "ุฏูุงุก", "medication", "ููู
", "sleep",
],
"social": [
"ูุงุณ", "people", "ู
ุฌุชู
ุน", "ุญูู
", "judgment", "ุฎุฌู", "shy", "ู
ูุนุฒู",
"isolated", "ุฎุงูู", "scared", "ู
ุด ูุงุฏุฑ ุฃุชููู
", "can't talk",
],
"self_worth": [
"ูุงุดู", "failure", "ู
ุด ูุงูู", "not enough", "ุถุนูู", "weak", "worthless",
"ูุง ููู
ุฉ", "ู
ุง ูููุนุด", "ู
ุด ุนุงุฑู ุฃูุฌุญ", "can't succeed", "loser",
],
"trauma": [
"ุตุฏู
ุฉ", "trauma", "ุญุงุฏุซุฉ", "accident", "ุฎุณุงุฑุฉ", "loss", "ููุงุฉ", "death",
"ู
ุงุช", "died", "ุฅุณุงุกุฉ", "abuse", "ููุงุจูุณ", "nightmares", "ุฐูุฑูุงุช",
],
}
def extract_cause(text: str) -> str:
text_lower = text.lower()
text_lower = re.sub(r'[^\w\s\u0600-\u06FF]', ' ', text_lower)
scores = {}
for cause, keywords in CAUSE_KEYWORDS.items():
count = sum(1 for kw in keywords if kw.lower() in text_lower)
if count > 0:
scores[cause] = count
if not scores:
return "general"
return max(scores, key=scores.get)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 3. SUICIDAL IDEATION DETECTION
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
SUICIDAL_KEYWORDS = [
"ุงูุชุญุงุฑ", "suicide", "ุฃูุชู ููุณู", "kill myself", "ุฃู
ูุช", "want to die",
"ุนุงูุฒ ุฃู
ูุช", "ู
ุด ุนุงูุฒ ุฃุนูุด", "don't want to live", "ููุงูุฉ ุญูุงุชู",
"end my life", "ุฃุฑูุญ ููุณู", "rest forever", "ู
ููุด ูุงูุฏุฉ ู
ู ุงูุญูุงุฉ",
"life is not worth", "ุฃุฐู ููุณู", "hurt myself", "ุฅูุฐุงุก ุงูููุณ",
"self harm", "ู
ุด ูุงุฏุฑ ุฃูู
ู", "can't go on", "ุนุงูุฒ ุฃุฎุชูู",
"want to disappear", "ูู ู
ุช", "if i die", "ูู ุงุฎุชููุช",
]
def detect_suicidal(text: str) -> bool:
text_lower = text.lower()
return any(kw.lower() in text_lower for kw in SUICIDAL_KEYWORDS)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 4. RECOMMENDATIONS DATABASE (Bilingual)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Structure: disease โ cause โ severity_group โ {tips, resources, referral}
# severity_group: "mild_moderate" | "severe"
REC_DB = {
# โโ ANXIETY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
"anxiety": {
"work": {
"mild_moderate": {
"tips_en": [
"Break your tasks into small steps and focus on one at a time",
"Take a 5-minute breathing break every hour",
"Communicate your workload clearly with your manager",
"Set clear boundaries between work time and rest time",
],
"tips_ar": [
"ูุณูู
ู
ูุงู
ู ูุฎุทูุงุช ุตุบูุฑุฉ ูุฑูุฒ ุนูู ุฎุทูุฉ ูุงุญุฏุฉ ูู ูู ู
ุฑุฉ",
"ุฎุฐ ุงุณุชุฑุงุญุฉ ุชููุณ 5 ุฏูุงุฆู ูู ุณุงุนุฉ",
"ุชุญุฏุซ ุจูุถูุญ ู
ุน ู
ุฏูุฑู ุนู ุญุฌู
ุนู
ูู",
"ุญุฏุฏ ุญุฏูุฏุงู ูุงุถุญุฉ ุจูู ููุช ุงูุนู
ู ูุงูุฑุงุญุฉ",
],
"resources_en": ["App: Calm or Headspace for quick work breaks",
"Technique: 4-7-8 breathing (inhale 4s, hold 7s, exhale 8s)"],
"resources_ar": ["ุชุทุจูู: Calm ุฃู Headspace ููุชุฑุงุช ุงูุฑุงุญุฉ ุงูุณุฑูุนุฉ",
"ุชูููุฉ: ุงูุชููุณ 4-7-8 (ุงุณุชูุดู 4 ุซูุงููุ ุงุญุจุณ 7ุ ุงุทุฑุฏ 8)"],
"referral_en": "If work anxiety persists for more than 2 weeks, consider speaking with a mental health professional.",
"referral_ar": "ูู ููู ุงูุนู
ู ู
ุณุชู
ุฑ ุฃูุซุฑ ู
ู ุฃุณุจูุนููุ ูููุฑ ูู ุงูุชุญุฏุซ ู
ุน ู
ุชุฎุตุต ููุณู.",
},
"severe": {
"tips_en": [
"Consider taking a short leave if possible โ your mental health comes first",
"Talk to HR or a trusted colleague about your situation",
"Avoid making major work decisions when anxiety is high",
],
"tips_ar": [
"ูููุฑ ูู ุฃุฎุฐ ุฅุฌุงุฒุฉ ูุตูุฑุฉ ูู ู
ู
ูู โ ุตุญุชู ุงูููุณูุฉ ุฃููุงู",
"ุชุญุฏุซ ู
ุน ูุณู
ุงูู
ูุงุฑุฏ ุงูุจุดุฑูุฉ ุฃู ุฒู
ูู ู
ูุซูู ุนู ูุถุนู",
"ุชุฌูุจ ุงุชุฎุงุฐ ูุฑุงุฑุงุช ุนู
ู ูุจูุฑุฉ ูู ููุช ุงูููู ุงูุดุฏูุฏ",
],
"resources_en": ["Cognitive Behavioral Therapy (CBT) is highly effective for work anxiety",
"Book: 'Anxiety at Work' by Adrian Gostick"],
"resources_ar": ["ุงูุนูุงุฌ ุงูู
ุนุฑูู ุงูุณูููู (CBT) ูุนูุงู ุฌุฏุงู ูููู ุงูุนู
ู",
"ูุชุงุจ: 'Anxiety at Work' ูู Adrian Gostick"],
"referral_en": "Severe work-related anxiety requires professional support. Please consult a therapist or psychiatrist.",
"referral_ar": "ููู ุงูุนู
ู ุงูุดุฏูุฏ ูุญุชุงุฌ ุฏุนู
ุงู ู
ุชุฎุตุตุงู. ู
ู ูุถูู ุงุณุชุดุฑ ู
ุนุงูุฌุงู ููุณูุงู ุฃู ุทุจูุจุงู ููุณูุงู.",
},
},
"relationships": {
"mild_moderate": {
"tips_en": [
"Express your feelings calmly using 'I feel...' statements",
"Set healthy boundaries in your relationships",
"Don't try to solve everything at once",
],
"tips_ar": [
"ุนุจูุฑ ุนู ู
ุดุงุนุฑู ุจูุฏูุก ุจุงุณุชุฎุฏุงู
ุนุจุงุฑุงุช 'ุฃูุง ุฃุดุนุฑ...'",
"ุญุฏุฏ ุญุฏูุฏุงู ุตุญูุฉ ูู ุนูุงูุงุชู",
"ูุง ุชุญุงูู ุญู ูู ุดูุก ุฏูุนุฉ ูุงุญุฏุฉ",
],
"resources_en": ["Book: 'Attached' by Amir Levine โ understanding relationship patterns",
"Couples or individual counseling can help significantly"],
"resources_ar": ["ูุชุงุจ: 'Attached' ูู Amir Levine โ ูููู
ุฃูู
ุงุท ุงูุนูุงูุงุช",
"ุงูุฅุฑุดุงุฏ ุงููุฑุฏู ุฃู ููุฃุฒูุงุฌ ุจูุณุงุนุฏ ูุชูุฑ"],
"referral_en": "If relationship anxiety is affecting your sleep or daily function, a therapist can help.",
"referral_ar": "ูู ููู ุงูุนูุงูุงุช ุจูุฃุซุฑ ุนูู ููู
ู ุฃู ุญูุงุชู ุงูููู
ูุฉุ ู
ุนุงูุฌ ููุณู ููุฏุฑ ูุณุงุนุฏ.",
},
"severe": {
"tips_en": [
"Create some distance if the relationship is causing constant distress",
"Reach out to a trusted family member or friend for support",
"Journaling your feelings daily can help process the anxiety",
],
"tips_ar": [
"ุฎูู ู
ุณุงูุฉ ู
ุคูุชุฉ ูู ุงูุนูุงูุฉ ุจุชุณุจุจ ุถููุงู ู
ุณุชู
ุฑุงู",
"ุชูุงุตู ู
ุน ูุฑุฏ ู
ู ุงูุนุงุฆูุฉ ุฃู ุตุฏูู ู
ูุซูู ููุฏุนู
",
"ูุชุงุจุฉ ู
ุดุงุนุฑู ููู
ูุงู ูู ุฏูุชุฑ ุจูุณุงุนุฏ ุนูู ู
ุนุงูุฌุฉ ุงูููู",
],
"resources_en": ["CBT or DBT therapy is recommended for severe relationship anxiety"],
"resources_ar": ["ุงูุนูุงุฌ ุงูู
ุนุฑูู ุงูุณูููู ุฃู DBT ู
ูุตู ุจู ูููู ุงูุนูุงูุงุช ุงูุดุฏูุฏ"],
"referral_en": "Please consult a mental health professional. Severe relationship anxiety is treatable.",
"referral_ar": "ู
ู ูุถูู ุงุณุชุดุฑ ู
ุชุฎุตุตุงู ููุณูุงู. ููู ุงูุนูุงูุงุช ุงูุดุฏูุฏ ูุงุจู ููุนูุงุฌ.",
},
},
"general": {
"mild_moderate": {
"tips_en": [
"Practice 4-7-8 breathing daily",
"Reduce caffeine intake โ it worsens anxiety",
"Exercise for at least 20 minutes a day",
"Limit news and social media consumption",
],
"tips_ar": [
"ู
ุงุฑุณ ุชููุณ 4-7-8 ููู
ูุงู",
"ููู ุงููุงูููู โ ุจูุฒูุฏ ุงูููู",
"ู
ุงุฑุณ ุงูุฑูุงุถุฉ 20 ุฏูููุฉ ุนูู ุงูุฃูู ููู
ูุงู",
"ููู ุงุณุชููุงู ุงูุฃุฎุจุงุฑ ููุณุงุฆู ุงูุชูุงุตู ุงูุงุฌุชู
ุงุนู",
],
"resources_en": ["App: Calm or Insight Timer",
"Book: 'Dare' by Barry McDonagh",
"YouTube: Progressive Muscle Relaxation guided sessions"],
"resources_ar": ["ุชุทุจูู: Calm ุฃู Insight Timer",
"ูุชุงุจ: 'Dare' ูู Barry McDonagh",
"YouTube: ุฌูุณุงุช Progressive Muscle Relaxation ู
ูุฌููุฉ"],
"referral_en": "If anxiety persists for more than 2 weeks, consider speaking with a professional.",
"referral_ar": "ูู ุงูููู ู
ุณุชู
ุฑ ุฃูุซุฑ ู
ู ุฃุณุจูุนููุ ูููุฑ ูู ุงูุชุญุฏุซ ู
ุน ู
ุชุฎุตุต.",
},
"severe": {
"tips_en": [
"Do not isolate yourself โ stay connected with safe people",
"Try grounding: name 5 things you see, 4 you hear, 3 you touch",
"Avoid making big decisions when anxiety peaks",
],
"tips_ar": [
"ูุง ุชุนุฒู ููุณู โ ุงุจูู ุนูู ุชูุงุตู ู
ุน ุงููุงุณ ุงูุขู
ููู",
"ุฌุฑุจ ุชูููุฉ ุงูุชุฃุฑูุถ: ุงุฐูุฑ 5 ุฃุดูุงุก ุชุฑุงูุงุ 4 ุชุณู
ุนูุงุ 3 ุชูู
ุณูุง",
"ุชุฌูุจ ุงุชุฎุงุฐ ูุฑุงุฑุงุช ูุจูุฑุฉ ูู ููุช ุฐุฑูุฉ ุงูููู",
],
"resources_en": ["CBT is the gold standard for severe anxiety",
"Medication may help โ consult a psychiatrist"],
"resources_ar": ["CBT ูู ุงูู
ุนูุงุฑ ุงูุฐูุจู ูุนูุงุฌ ุงูููู ุงูุดุฏูุฏ",
"ุงูุฏูุงุก ูุฏ ูุณุงุนุฏ โ ุงุณุชุดุฑ ุทุจูุจุงู ููุณูุงู"],
"referral_en": "Severe anxiety requires professional treatment. Please reach out to a therapist or psychiatrist soon.",
"referral_ar": "ุงูููู ุงูุดุฏูุฏ ูุญุชุงุฌ ุนูุงุฌุงู ู
ุชุฎุตุตุงู. ู
ู ูุถูู ุชูุงุตู ู
ุน ู
ุนุงูุฌ ููุณู ุฃู ุทุจูุจ ููุณู ูู ุฃูุฑุจ ููุช.",
},
},
},
# โโ DEPRESSION โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
"depression": {
"work": {
"mild_moderate": {
"tips_en": [
"Try to find one small meaningful task at work each day",
"Take short walks outside during your lunch break",
"Talk to a trusted colleague โ connection helps",
],
"tips_ar": [
"ุญุงูู ุชูุงูู ู
ูู
ุฉ ุตุบูุฑุฉ ุฐุงุช ู
ุนูู ูู ุงูุนู
ู ูู ููู
",
"ุงุฎุฑุฌ ูู ูุฒูุฉ ูุตูุฑุฉ ุฃุซูุงุก ุงุณุชุฑุงุญุฉ ุงูุบุฏุงุก",
"ุชุญุฏุซ ู
ุน ุฒู
ูู ู
ูุซูู โ ุงูุชูุงุตู ุจูุณุงุนุฏ",
],
"resources_en": ["Book: 'Lost Connections' by Johann Hari",
"Technique: Behavioral Activation โ schedule small enjoyable activities"],
"resources_ar": ["ูุชุงุจ: 'Lost Connections' ูู Johann Hari",
"ุชูููุฉ: ุงูุชูุดูุท ุงูุณูููู โ ุฌุฏููู ุฃูุดุทุฉ ุตุบูุฑุฉ ู
ู
ุชุนุฉ"],
"referral_en": "Work-related depression responds well to therapy. Consider reaching out to a professional.",
"referral_ar": "ุงูุงูุชุฆุงุจ ุงูู
ุฑุชุจุท ุจุงูุนู
ู ูุณุชุฌูุจ ุฌูุฏุงู ููุนูุงุฌ. ูููุฑ ูู ุงูุชูุงุตู ู
ุน ู
ุชุฎุตุต.",
},
"severe": {
"tips_en": [
"Take medical leave if possible โ you need recovery time",
"Maintain a basic daily routine even if it feels hard",
"Tell one trusted person how you truly feel",
],
"tips_ar": [
"ุฎุฐ ุฅุฌุงุฒุฉ ุทุจูุฉ ูู ู
ู
ูู โ ุชุญุชุงุฌ ููุชุงู ููุชุนุงูู",
"ุญุงูุธ ุนูู ุฑูุชูู ููู
ู ุฃุณุงุณู ุญุชู ูู ุตุนุจ",
"ุฃุฎุจุฑ ุดุฎุตุงู ู
ูุซููุงู ูุงุญุฏุงู ุจู
ุดุงุนุฑู ุงูุญููููุฉ",
],
"resources_en": ["Antidepressants combined with therapy show strong results",
"Contact a psychiatrist as soon as possible"],
"resources_ar": ["ู
ุถุงุฏุงุช ุงูุงูุชุฆุงุจ ู
ุน ุงูุนูุงุฌ ุงูููุณู ุจุชุนุทู ูุชุงุฆุฌ ูููุฉ",
"ุชูุงุตู ู
ุน ุทุจูุจ ููุณู ูู ุฃูุฑุจ ููุช ู
ู
ูู"],
"referral_en": "Severe depression is a medical condition. Please see a psychiatrist urgently.",
"referral_ar": "ุงูุงูุชุฆุงุจ ุงูุดุฏูุฏ ุญุงูุฉ ุทุจูุฉ. ู
ู ูุถูู ุฑุงุฌุน ุทุจูุจุงู ููุณูุงู ุจุดูู ุนุงุฌู.",
},
},
"self_worth": {
"mild_moderate": {
"tips_en": [
"Write 3 things you did well today โ no matter how small",
"The critical voice in your head is not the truth",
"Treat yourself with the same kindness you'd give a friend",
],
"tips_ar": [
"ุงูุชุจ 3 ุฃุดูุงุก ูู
ุช ุจูุง ุจุดูู ุฌูุฏ ุงูููู
โ ู
ูู
ุง ูุงูุช ุตุบูุฑุฉ",
"ุงูุตูุช ุงููุงูุฏ ูู ุฑุฃุณู ููุณ ุงูุญูููุฉ",
"ุชุนุงู
ู ู
ุน ููุณู ุจููุณ ุงููุทู ุงูุฐู ุชุนุทูู ูุตุฏูู",
],
"resources_en": ["Book: 'Feeling Good' by David Burns",
"Book: 'Self-Compassion' by Kristin Neff"],
"resources_ar": ["ูุชุงุจ: 'Feeling Good' ูู David Burns",
"ูุชุงุจ: 'Self-Compassion' ูู Kristin Neff"],
"referral_en": "Low self-worth with depression responds very well to CBT therapy.",
"referral_ar": "ุถุนู ุงูุซูุฉ ู
ุน ุงูุงูุชุฆุงุจ ูุณุชุฌูุจ ุฌูุฏุงู ุฌุฏุงู ููุนูุงุฌ ุงูู
ุนุฑูู ุงูุณูููู.",
},
"severe": {
"tips_en": [
"You are not your worst thoughts โ please reach out for help",
"Start with one tiny act of self-care today",
"Connect with someone safe right now",
],
"tips_ar": [
"ุฃูุช ูุณุช ุฃููุงุฑู ุงูุณูุฆุฉ โ ู
ู ูุถูู ุงุทูุจ ุงูู
ุณุงุนุฏุฉ",
"ุงุจุฏุฃ ุจูุนู ุตุบูุฑ ุฌุฏุงู ู
ู ุงูุฑุนุงูุฉ ุงูุฐุงุชูุฉ ุงูููู
",
"ุชูุงุตู ู
ุน ุดุฎุต ุขู
ู ุงูุขู",
],
"resources_en": ["Urgent: Please contact a mental health professional",
"CBT and medication together are very effective"],
"resources_ar": ["ุนุงุฌู: ู
ู ูุถูู ุชูุงุตู ู
ุน ู
ุชุฎุตุต ููุณู",
"ุงูุนูุงุฌ ุงูู
ุนุฑูู ุงูุณูููู ูุงูุฏูุงุก ู
ุนุงู ูุนูุงูุงู ุฌุฏุงู"],
"referral_en": "Please seek professional help immediately. You deserve support and recovery.",
"referral_ar": "ู
ู ูุถูู ุงุทูุจ ู
ุณุงุนุฏุฉ ู
ุชุฎุตุตุฉ ููุฑุงู. ุฃูุช ุชุณุชุญู ุงูุฏุนู
ูุงูุชุนุงูู.",
},
},
"general": {
"mild_moderate": {
"tips_en": [
"Maintain a consistent daily routine",
"Get 15 minutes of sunlight every day โ it genuinely helps",
"Light exercise (a 30-minute walk) is clinically proven to reduce mild depression",
"Connect with at least one person daily",
],
"tips_ar": [
"ุญุงูุธ ุนูู ุฑูุชูู ููู
ู ุซุงุจุช",
"ุงุญุตู ุนูู 15 ุฏูููุฉ ู
ู ุฃุดุนุฉ ุงูุดู
ุณ ูู ููู
โ ุจูุณุงุนุฏ ูุนูุงู",
"ุงูุฑูุงุถุฉ ุงูุฎูููุฉ (ู
ุดู 30 ุฏูููุฉ) ุซุจุช ุนูู
ูุงู ุฅููุง ุจุชููู ุงูุงูุชุฆุงุจ ุงูุฎููู",
"ุชูุงุตู ู
ุน ุดุฎุต ูุงุญุฏ ุนูู ุงูุฃูู ููู
ูุงู",
],
"resources_en": ["App: Woebot for daily mental health support",
"Book: 'The Depression Cure' by Stephen Ilardi",
"Book: 'Feeling Good' by David Burns"],
"resources_ar": ["ุชุทุจูู: Woebot ููุฏุนู
ุงูููุณู ุงูููู
ู",
"ูุชุงุจ: 'The Depression Cure' ูู Stephen Ilardi",
"ูุชุงุจ: 'Feeling Good' ูู David Burns"],
"referral_en": "If symptoms persist more than 2 weeks, please speak with a doctor or therapist.",
"referral_ar": "ูู ุงูุฃุนุฑุงุถ ู
ุณุชู
ุฑุฉ ุฃูุซุฑ ู
ู ุฃุณุจูุนููุ ู
ู ูุถูู ุชุญุฏุซ ู
ุน ุทุจูุจ ุฃู ู
ุนุงูุฌ.",
},
"severe": {
"tips_en": [
"Do not be alone โ stay with safe people",
"Focus only on the next hour, not the whole day",
"Even getting out of bed is an achievement today",
],
"tips_ar": [
"ูุง ุชูู ูุญุฏู โ ุงุจูู ู
ุน ุฃุดุฎุงุต ุขู
ููู",
"ุฑูุฒ ุนูู ุงูุณุงุนุฉ ุงููุงุฏู
ุฉ ููุทุ ููุณ ุงูููู
ููู",
"ุญุชู ุงููููุถ ู
ู ุงูุณุฑูุฑ ุฅูุฌุงุฒ ุงูููู
",
],
"resources_en": ["Combination of therapy and medication is most effective for severe depression",
"Please contact a psychiatrist as soon as possible"],
"resources_ar": ["ู
ุฒูุฌ ุงูุนูุงุฌ ุงูููุณู ูุงูุฏูุงุก ูู ุงูุฃูุซุฑ ูุนุงููุฉ ููุงูุชุฆุงุจ ุงูุดุฏูุฏ",
"ู
ู ูุถูู ุชูุงุตู ู
ุน ุทุจูุจ ููุณู ูู ุฃูุฑุจ ููุช ู
ู
ูู"],
"referral_en": "Severe depression is a serious medical condition. Please seek help urgently.",
"referral_ar": "ุงูุงูุชุฆุงุจ ุงูุดุฏูุฏ ุญุงูุฉ ุทุจูุฉ ุฎุทูุฑุฉ. ู
ู ูุถูู ุงุทูุจ ุงูู
ุณุงุนุฏุฉ ุจุดูู ุนุงุฌู.",
},
},
},
# โโ STRESS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
"stress": {
"work": {
"mild_moderate": {
"tips_en": [
"Use the Pomodoro technique: 25 min work + 5 min break",
"Write your top 3 priorities each morning and stick to them",
"Learn to say no to extra tasks when overloaded",
"Disconnect from work emails after working hours",
],
"tips_ar": [
"ุงุณุชุฎุฏู
ุชูููุฉ Pomodoro: 25 ุฏูููุฉ ุนู
ู + 5 ุฏูุงุฆู ุฑุงุญุฉ",
"ุงูุชุจ ุฃูู
3 ุฃููููุงุช ูู ุตุจุงุญ ูุงูุชุฒู
ุจูุง",
"ุชุนููู
ููู 'ูุง' ููู
ูุงู
ุงูุฅุถุงููุฉ ุนูุฏ ุงูุถุบุท ุงูุฒุงุฆุฏ",
"ุงูุตู ููุณู ุนู ุฅูู
ููุงุช ุงูุนู
ู ุจุนุฏ ุณุงุนุงุช ุงูุนู
ู",
],
"resources_en": ["App: Todoist or Notion for task management",
"Book: 'Deep Work' by Cal Newport"],
"resources_ar": ["ุชุทุจูู: Todoist ุฃู Notion ูุฅุฏุงุฑุฉ ุงูู
ูุงู
",
"ูุชุงุจ: 'Deep Work' ูู Cal Newport"],
"referral_en": "If work stress is causing physical symptoms, consult a doctor.",
"referral_ar": "ูู ุถุบุท ุงูุนู
ู ุจูุณุจุจ ุฃุนุฑุงุถุงู ุฌุณู
ุงููุฉุ ุงุณุชุดุฑ ุทุจูุจุงู.",
},
"severe": {
"tips_en": [
"You may be experiencing burnout โ this is a real medical condition",
"Take urgent time off if possible",
"Talk to your manager or HR about workload redistribution",
],
"tips_ar": [
"ูุฏ ุชููู ุชุนุงูู ู
ู ุงูุฅุฑูุงู ุงููุธููู (Burnout) โ ููุฐู ุญุงูุฉ ุทุจูุฉ ุญููููุฉ",
"ุฎุฐ ุฅุฌุงุฒุฉ ุนุงุฌูุฉ ูู ู
ู
ูู",
"ุชุญุฏุซ ู
ุน ู
ุฏูุฑู ุฃู ุงูู
ูุงุฑุฏ ุงูุจุดุฑูุฉ ุนู ุฅุนุงุฏุฉ ุชูุฒูุน ุนุจุก ุงูุนู
ู",
],
"resources_en": ["Book: 'Burnout' by Emily Nagoski",
"Urgent: Consult an occupational health specialist"],
"resources_ar": ["ูุชุงุจ: 'Burnout' ูู Emily Nagoski",
"ุนุงุฌู: ุงุณุชุดุฑ ุฃุฎุตุงุฆู ุงูุตุญุฉ ุงูู
ูููุฉ"],
"referral_en": "Severe burnout requires professional support. Please consult a doctor or therapist.",
"referral_ar": "ุงูุฅุฑูุงู ุงููุธููู ุงูุดุฏูุฏ ูุญุชุงุฌ ุฏุนู
ุงู ู
ุชุฎุตุตุงู. ู
ู ูุถูู ุงุณุชุดุฑ ุทุจูุจุงู ุฃู ู
ุนุงูุฌุงู.",
},
},
"academic": {
"mild_moderate": {
"tips_en": [
"Plan your study schedule in advance โ avoid last-minute cramming",
"Use Active Recall and Spaced Repetition for effective studying",
"Sleep is more valuable than all-nighters before exams",
],
"tips_ar": [
"ุฎุทุท ุฌุฏูู ู
ุฐุงูุฑุชู ู
ุณุจูุงู โ ุชุฌูุจ ุงูุฏุฑุงุณุฉ ูู ุงููุญุธุฉ ุงูุฃุฎูุฑุฉ",
"ุงุณุชุฎุฏู
Active Recall ูSpaced Repetition ููู
ุฐุงูุฑุฉ ุงููุนูุงูุฉ",
"ุงูููู
ุฃูู
ู
ู ุงูุณูุฑ ูุจู ุงูุงู
ุชุญุงูุงุช",
],
"resources_en": ["App: Anki for Spaced Repetition",
"App: Forest to block distractions while studying"],
"resources_ar": ["ุชุทุจูู: Anki ูู Spaced Repetition",
"ุชุทุจูู: Forest ูู
ูุน ุงูุชุดุชูุช ุฃุซูุงุก ุงูู
ุฐุงูุฑุฉ"],
"referral_en": "If academic stress is severely impacting you, talk to your university counselor.",
"referral_ar": "ูู ุถุบุท ุงูุฏุฑุงุณุฉ ุจูุฃุซุฑ ุนููู ุจุดูู ูุจูุฑุ ุชุญุฏุซ ู
ุน ุงูู
ุฑุดุฏ ุงูุฃูุงุฏูู
ู ูู ุฌุงู
ุนุชู.",
},
"severe": {
"tips_en": [
"Your worth is not defined by your grades",
"Talk to your academic advisor โ they can offer real solutions",
"Seek your university's mental health support services",
],
"tips_ar": [
"ููู
ุชู ูุง ุชูุญุฏูุฏ ุจุฏุฑุฌุงุชู",
"ุชุญุฏุซ ู
ุน ู
ุฑุดุฏู ุงูุฃูุงุฏูู
ู โ ุจููุฏุฑ ููุฏู
ุญูููุงู ุญููููุฉ",
"ุงุทูุจ ุฎุฏู
ุงุช ุงูุฏุนู
ุงูููุณู ูู ุฌุงู
ุนุชู",
],
"resources_en": ["Most universities offer free mental health counseling"],
"resources_ar": ["ู
ุนุธู
ุงูุฌุงู
ุนุงุช ุชูุฏู
ุฅุฑุดุงุฏุงู ููุณูุงู ู
ุฌุงููุงู"],
"referral_en": "Please reach out to a counselor or therapist. Academic stress at this level needs support.",
"referral_ar": "ู
ู ูุถูู ุชูุงุตู ู
ุน ู
ุฑุดุฏ ุฃู ู
ุนุงูุฌ. ุถุบุท ุงูุฏุฑุงุณุฉ ุจูุฐุง ุงูู
ุณุชูู ูุญุชุงุฌ ุฏุนู
ุงู.",
},
},
"general": {
"mild_moderate": {
"tips_en": [
"Exercise for 20 minutes daily โ it reduces cortisol significantly",
"Write your thoughts in a daily journal",
"Focus on what you can control, let go of what you can't",
"Schedule genuine rest time โ it's not wasted time",
],
"tips_ar": [
"ู
ุงุฑุณ ุงูุฑูุงุถุฉ 20 ุฏูููุฉ ููู
ูุงู โ ุจูููู ุงูููุฑุชูุฒูู ุจุดูู ู
ูุญูุธ",
"ุงูุชุจ ุฃููุงุฑู ูู ุฏูุชุฑ ููู
ู",
"ุฑูุฒ ุนูู ู
ุง ุชูุฏุฑ ุชุชุญูู
ูููุ ูุงุชุฑู ู
ุง ูุง ุชูุฏุฑ",
"ุฌุฏููู ููุช ุฑุงุญุฉ ุญูููู โ ูู ู
ุด ููุช ุถุงุฆุน",
],
"resources_en": ["App: Insight Timer for short meditation sessions",
"Book: 'The Stress Solution' by Rangan Chatterjee",
"Technique: Progressive Muscle Relaxation before sleep"],
"resources_ar": ["ุชุทุจูู: Insight Timer ูุฌูุณุงุช ุชุฃู
ู ูุตูุฑุฉ",
"ูุชุงุจ: 'The Stress Solution' ูู Rangan Chatterjee",
"ุชูููุฉ: Progressive Muscle Relaxation ูุจู ุงูููู
"],
"referral_en": "Chronic stress (over 1 month) is worth discussing with a professional.",
"referral_ar": "ุงูุถุบุท ุงูู
ุฒู
ู (ุฃูุซุฑ ู
ู ุดูุฑ) ูุณุชุญู ุงูุชุญุฏุซ ุนูู ู
ุน ู
ุชุฎุตุต.",
},
"severe": {
"tips_en": [
"Your body is sending serious signals โ please listen to them",
"Eliminate one major stressor if possible",
"Ask for help โ carrying everything alone is not sustainable",
],
"tips_ar": [
"ุฌุณู
ู ูุฑุณู ุฅุดุงุฑุงุช ุฎุทูุฑุฉ โ ู
ู ูุถูู ุงุณุชู
ุน ุฅูููุง",
"ุฃุฒู ู
ุตุฏุฑ ุถุบุท ุฑุฆูุณู ูุงุญุฏ ูู ู
ู
ูู",
"ุงุทูุจ ุงูู
ุณุงุนุฏุฉ โ ุญู
ู ูู ุดูุก ูุญุฏู ููุณ ู
ุณุชุฏุงู
ุงู",
],
"resources_en": ["Severe chronic stress can cause physical illness โ see a doctor",
"Therapy (CBT or mindfulness-based) is highly effective"],
"resources_ar": ["ุงูุถุบุท ุงูู
ุฒู
ู ุงูุดุฏูุฏ ูุฏ ูุณุจุจ ุฃู
ุฑุงุถุงู ุฌุณุฏูุฉ โ ุฑุงุฌุน ุทุจูุจุงู",
"ุงูุนูุงุฌ ุงูููุณู (CBT ุฃู ุงููุงุฆู
ุนูู ุงูููุธุฉ ุงูุฐูููุฉ) ูุนูุงู ุฌุฏุงู"],
"referral_en": "Please consult a doctor or therapist. Severe stress at this level needs professional attention.",
"referral_ar": "ู
ู ูุถูู ุงุณุชุดุฑ ุทุจูุจุงู ุฃู ู
ุนุงูุฌุงู. ุงูุถุบุท ุงูุดุฏูุฏ ุจูุฐุง ุงูู
ุณุชูู ูุญุชุงุฌ ุงูุชู
ุงู
ุงู ู
ุชุฎุตุตุงู.",
},
},
},
}
# Suicidal crisis โ overrides everything
SUICIDAL_REC = {
"tips_en": [
"You are not alone โ help is available right now",
"Please reach out to someone you trust immediately",
"Remove access to any means of self-harm if possible",
"Stay with another person โ do not be alone right now",
],
"tips_ar": [
"ุฃูุช ูุณุช ูุญุฏู โ ุงูู
ุณุงุนุฏุฉ ู
ุชุงุญุฉ ุงูุขู",
"ู
ู ูุถูู ุชูุงุตู ู
ุน ุดุฎุต ุชุซู ุจู ููุฑุงู",
"ุงุจุชุนุฏ ุนู ุฃู ูุณููุฉ ูุฏ ุชุคุฐู ุจูุง ููุณู",
"ุงุจูู ู
ุน ุดุฎุต ุขุฎุฑ โ ูุง ุชูู ูุญุฏู ุงูุขู",
],
"resources_en": [
"๐ International Association for Suicide Prevention: https://www.iasp.info/resources/Crisis_Centres/",
"๐ Crisis Text Line (US): Text HOME to 741741",
"๐ Befrienders Worldwide: https://www.befrienders.org",
],
"resources_ar": [
"๐ ุงูุฑุงุจุทุฉ ุงูุฏูููุฉ ููููุงูุฉ ู
ู ุงูุงูุชุญุงุฑ: https://www.iasp.info/resources/Crisis_Centres/",
"๐ ุฎุท ุฃุฒู
ุงุช ุฅูู
ูุฌ (ู
ุตุฑ): 08008880700",
"๐ ุฎุท ู
ุณุงูุฏุฉ (ุงูุณุนูุฏูุฉ): 920033360",
"๐ ู
ููุน Befrienders ุงูุนุงูู
ู: https://www.befrienders.org",
],
"referral_en": "๐จ URGENT: Please contact a mental health crisis line or go to the nearest emergency room immediately. Your life has value and help is available.",
"referral_ar": "๐จ ุนุงุฌู ุฌุฏุงู: ู
ู ูุถูู ุชูุงุตู ู
ุน ุฎุท ุฃุฒู
ุงุช ุงูุตุญุฉ ุงูููุณูุฉ ุฃู ุงุฐูุจ ูุฃูุฑุจ ุทูุงุฑุฆ ููุฑุงู. ุญูุงุชู ููุง ููู
ุฉ ูุงูู
ุณุงุนุฏุฉ ู
ุชุงุญุฉ.",
}
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 5. MAIN FUNCTION
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def get_recommendations(
disease: str,
disease_score: float,
user_text: str,
) -> dict:
"""
disease : 'anxiety' | 'depression' | 'stress'
disease_score: float 0-1 ู
ู ุงูู
ูุฏูู
user_text : ุงููุต ุงูุฐู ูุชุจู ุงูู
ุณุชุฎุฏู
returns : dict ุจุงูุชูุตูุงุช ุงููุงู
ูุฉ
"""
is_suicidal = detect_suicidal(user_text)
if is_suicidal:
return {
"suicidal_flag": True,
"severity": "crisis",
"cause": "crisis",
**SUICIDAL_REC,
}
severity = get_severity(disease, disease_score)
severity_group = "severe" if severity in ("severe", "extremely_severe") else "mild_moderate"
cause = extract_cause(user_text)
disease_db = REC_DB.get(disease, REC_DB["stress"])
cause_db = disease_db.get(cause, disease_db.get("general", {}))
rec = cause_db.get(severity_group, cause_db.get("mild_moderate", {}))
return {
"suicidal_flag": False,
"severity": severity,
"cause": cause,
"tips_en": rec.get("tips_en", []),
"tips_ar": rec.get("tips_ar", []),
"resources_en": rec.get("resources_en", []),
"resources_ar": rec.get("resources_ar", []),
"referral_en": rec.get("referral_en", ""),
"referral_ar": rec.get("referral_ar", ""),
} |