MindCheck Bot commited on
Commit ·
8d3e440
1
Parent(s): 97a091b
Deploy Next.js and Flask backend
Browse files- .DS_Store +0 -0
- Dockerfile +41 -0
- NOTEBOOK&MODEL/Copy_of_NLP_AOL.ipynb +0 -0
- NOTEBOOK&MODEL/model.pt +3 -0
- README.md +87 -7
- backend/app.py +326 -0
- backend/requirements.txt +5 -0
- blueprint.md +76 -0
- example_answers.md +71 -0
- mindcheck-web/.gitignore +41 -0
- mindcheck-web/AGENTS.md +5 -0
- mindcheck-web/CLAUDE.md +1 -0
- mindcheck-web/README.md +36 -0
- mindcheck-web/eslint.config.mjs +18 -0
- mindcheck-web/next.config.ts +7 -0
- mindcheck-web/package-lock.json +0 -0
- mindcheck-web/package.json +26 -0
- mindcheck-web/postcss.config.mjs +7 -0
- mindcheck-web/public/file.svg +1 -0
- mindcheck-web/public/globe.svg +1 -0
- mindcheck-web/public/next.svg +1 -0
- mindcheck-web/public/vercel.svg +1 -0
- mindcheck-web/public/window.svg +1 -0
- mindcheck-web/src/app/api/predict/route.ts +32 -0
- mindcheck-web/src/app/chat/page.tsx +367 -0
- mindcheck-web/src/app/favicon.ico +0 -0
- mindcheck-web/src/app/globals.css +98 -0
- mindcheck-web/src/app/history/page.tsx +200 -0
- mindcheck-web/src/app/layout.tsx +30 -0
- mindcheck-web/src/app/page.tsx +175 -0
- mindcheck-web/src/app/result/page.tsx +304 -0
- mindcheck-web/tsconfig.json +34 -0
- start.sh +12 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
Dockerfile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# Install system dependencies including curl
|
| 4 |
+
RUN apt-get update && apt-get install -y curl git
|
| 5 |
+
# Install Node.js 20.x
|
| 6 |
+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
| 7 |
+
RUN apt-get install -y nodejs
|
| 8 |
+
|
| 9 |
+
# Set up user for Hugging Face Spaces (UID 1000 is required by HF Spaces)
|
| 10 |
+
RUN useradd -m -u 1000 user
|
| 11 |
+
USER user
|
| 12 |
+
ENV HOME=/home/user \
|
| 13 |
+
PATH=/home/user/.local/bin:$PATH
|
| 14 |
+
|
| 15 |
+
WORKDIR $HOME/app
|
| 16 |
+
|
| 17 |
+
# Copy the entire repository into the container and set ownership
|
| 18 |
+
COPY --chown=user . $HOME/app
|
| 19 |
+
|
| 20 |
+
# Install Python dependencies
|
| 21 |
+
RUN pip install --no-cache-dir -r backend/requirements.txt
|
| 22 |
+
|
| 23 |
+
# Pre-download the Hugging Face MPNet tokenizer/model so it doesn't download on boot
|
| 24 |
+
RUN python -c "from transformers import AutoTokenizer, AutoModel; AutoTokenizer.from_pretrained('sentence-transformers/all-mpnet-base-v2'); AutoModel.from_pretrained('sentence-transformers/all-mpnet-base-v2')"
|
| 25 |
+
|
| 26 |
+
# Install Node.js dependencies and build Next.js
|
| 27 |
+
WORKDIR $HOME/app/mindcheck-web
|
| 28 |
+
RUN npm install
|
| 29 |
+
RUN npm run build
|
| 30 |
+
|
| 31 |
+
# Return to app root
|
| 32 |
+
WORKDIR $HOME/app
|
| 33 |
+
|
| 34 |
+
# Make start script executable
|
| 35 |
+
RUN chmod +x start.sh
|
| 36 |
+
|
| 37 |
+
# Hugging Face Spaces expects the app to run on port 7860
|
| 38 |
+
EXPOSE 7860
|
| 39 |
+
|
| 40 |
+
# Run the supervisor script
|
| 41 |
+
CMD ["./start.sh"]
|
NOTEBOOK&MODEL/Copy_of_NLP_AOL.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
NOTEBOOK&MODEL/model.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb4ce3fa322504fbc982c0f170961dd76bd9ac2e49085bc2f07bca59dc54b1e6
|
| 3 |
+
size 440193281
|
README.md
CHANGED
|
@@ -1,10 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
+
# 🧠 MindCheck
|
| 2 |
+
|
| 3 |
+
**MindCheck** adalah aplikasi web *full-stack* berbasis kecerdasan buatan (AI) yang dirancang untuk melakukan *screening* kesehatan mental (depresi) menggunakan standar kuisioner **PHQ-8** secara interaktif.
|
| 4 |
+
|
| 5 |
+
Alih-alih menyuruh pengguna mengisi formulir pilihan ganda yang kaku, MindCheck mensimulasikan sebuah **wawancara virtual**. Pengguna dapat mengetik jawaban secara bebas dan bercerita. Model *Deep Learning* di balik aplikasi ini akan menganalisa transkrip teks tersebut (baik secara semantik maupun dari ekstraksi fitur linguistik) untuk memprediksi skor keparahan depresi.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## 📊 Dataset: DAIC-WOZ
|
| 10 |
+
Model AI pada MindCheck dilatih menggunakan **DAIC-WOZ Database** (Distress Analysis Interview Corpus - Wizard of Oz).
|
| 11 |
+
Dataset ini dirilis oleh *Institute for Creative Technologies, University of Southern California (USC)*. Dataset DAIC-WOZ berisi rekaman audio, video, dan transkrip wawancara klinis ekstensif antara agen virtual (Ellie) dan pasien, lengkap dengan label skor kejiwaan PHQ-8.
|
| 12 |
+
|
| 13 |
+
MindCheck memanfaatkan data **transkrip teks** dari DAIC-WOZ untuk melatih model `MPNetMultiOutputRegressor` agar mampu memahami pola bahasa, rasio sentimen negatif, dan penggunaan *filler words* dari orang yang mengalami gejala depresi.
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## 🚀 Fitur Utama
|
| 18 |
+
* **Conversational Interface:** Wawancara 8 langkah berbasis pertanyaan terbuka.
|
| 19 |
+
* **AI-Powered Analysis:** Analisis teks mendalam menggunakan arsitektur MPNet dari *Hugging Face* yang di-*finetune* secara kustom.
|
| 20 |
+
* **Instant Dashboard:** Hasil prediksi langsung diakumulasi menjadi skor PHQ-8, kategori keparahan (Minimal hingga Severe), serta statistik deteksi kata negatif.
|
| 21 |
+
* **Privacy First:** Semua pemrosesan data (jika tidak menggunakan cloud backend) terjadi secara anonim. History disimpan di `localStorage` perangkat pengguna.
|
| 22 |
+
* **Graceful Fallback:** Jika server AI mati atau tidak bisa dijangkau, sistem otomatis beralih menggunakan algoritma *Keyword & Sentiment Matching* lokal yang tertanam di frontend.
|
| 23 |
+
|
| 24 |
---
|
| 25 |
+
|
| 26 |
+
## 🛠️ Cara Penggunaan & Instalasi
|
| 27 |
+
|
| 28 |
+
Untuk menjalankan MindCheck di komputermu sendiri (baik untuk *development* atau penggunaan langsung), ikuti langkah-langkah berikut:
|
| 29 |
+
|
| 30 |
+
### 1. Request Dataset DAIC-WOZ (Opsional)
|
| 31 |
+
Jika kamu ingin melatih ulang (retrain) atau melihat data aslinya:
|
| 32 |
+
1. Kunjungi website resmi [DAIC-WOZ (USC ICT)](http://dcapswoz.ict.usc.edu/).
|
| 33 |
+
2. Tanda tangani *Data Use Agreement* (EULA) yang disediakan untuk keperluan riset non-komersial.
|
| 34 |
+
3. Setelah disetujui, kamu akan diberikan akses link repositori untuk mendownload dataset aslinya.
|
| 35 |
+
|
| 36 |
+
### 2. Clone Repositori
|
| 37 |
+
Tarik repositori proyek MindCheck ini ke komputer lokalmu:
|
| 38 |
+
```bash
|
| 39 |
+
git clone <url-repositori-ini>
|
| 40 |
+
cd NLP_AOL
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
### 3. Menjalankan Backend API (Model AI)
|
| 44 |
+
Backend menggunakan Python dan Flask untuk melakukan inferensi model PyTorch.
|
| 45 |
+
|
| 46 |
+
1. Buka terminal baru dan masuk ke folder `backend`:
|
| 47 |
+
```bash
|
| 48 |
+
cd backend
|
| 49 |
+
```
|
| 50 |
+
2. Buat *Virtual Environment* (VENV) agar package tidak bentrok:
|
| 51 |
+
```bash
|
| 52 |
+
# Di macOS/Linux
|
| 53 |
+
python3 -m venv venv
|
| 54 |
+
source venv/bin/activate
|
| 55 |
+
|
| 56 |
+
# Di Windows
|
| 57 |
+
python -m venv venv
|
| 58 |
+
venv\Scripts\activate
|
| 59 |
+
```
|
| 60 |
+
3. Install dependencies:
|
| 61 |
+
```bash
|
| 62 |
+
pip install -r requirements.txt
|
| 63 |
+
```
|
| 64 |
+
4. Jalankan server Flask (secara default akan berjalan di `http://127.0.0.1:8000`):
|
| 65 |
+
```bash
|
| 66 |
+
python app.py
|
| 67 |
+
```
|
| 68 |
+
*(Catatan: Saat dijalankan pertama kali, aplikasi akan mendownload base-model tokenizer MPNet dari Hugging Face ke cache komputermu).*
|
| 69 |
+
|
| 70 |
+
### 4. Menjalankan Frontend Web (Next.js)
|
| 71 |
+
Frontend ini adalah tampilan antarmuka (UI) dari MindCheck.
|
| 72 |
+
|
| 73 |
+
1. Buka terminal baru (biarkan terminal backend tetap menyala) dan masuk ke folder `mindcheck-web`:
|
| 74 |
+
```bash
|
| 75 |
+
cd mindcheck-web
|
| 76 |
+
```
|
| 77 |
+
2. Install dependencies dari Node.js:
|
| 78 |
+
```bash
|
| 79 |
+
npm install
|
| 80 |
+
```
|
| 81 |
+
3. Jalankan server *Development* Next.js:
|
| 82 |
+
```bash
|
| 83 |
+
npm run dev
|
| 84 |
+
```
|
| 85 |
+
4. Buka browser dan kunjungi: **`http://localhost:3000`**
|
| 86 |
+
|
| 87 |
---
|
| 88 |
|
| 89 |
+
## 📁 Struktur Aplikasi
|
| 90 |
+
Untuk melihat penjelasan sangat mendetail mengenai setiap folder, direktori, dan bagaimana file-file ini saling terhubung, silakan baca **[`blueprint.md`](blueprint.md)**.
|
backend/app.py
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MindCheck Flask Backend — serves PHQ-8 predictions from the trained
|
| 3 |
+
MPNetMultiOutputRegressor model.
|
| 4 |
+
|
| 5 |
+
Endpoints:
|
| 6 |
+
POST /predict — accepts {"answers": ["...", ...]} (8 text answers)
|
| 7 |
+
GET /health — health check
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
import torch.nn as nn
|
| 15 |
+
from flask import Flask, request, jsonify
|
| 16 |
+
from flask_cors import CORS
|
| 17 |
+
from transformers import AutoTokenizer, AutoModel
|
| 18 |
+
|
| 19 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 20 |
+
# 1. CONFIG
|
| 21 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 22 |
+
|
| 23 |
+
MODEL_PATH = os.environ.get(
|
| 24 |
+
"MODEL_PATH",
|
| 25 |
+
os.path.join(os.path.dirname(__file__), "..", "NOTEBOOK&MODEL", "model.pt"),
|
| 26 |
+
)
|
| 27 |
+
MODEL_NAME = "sentence-transformers/all-mpnet-base-v2"
|
| 28 |
+
MAX_LEN = 512
|
| 29 |
+
HEAD_TOKENS = 256
|
| 30 |
+
TAIL_TOKENS = 256
|
| 31 |
+
NV_SIZE = 18
|
| 32 |
+
N_TARGETS = 8
|
| 33 |
+
DEVICE = "cpu" # keep on CPU for serving
|
| 34 |
+
|
| 35 |
+
PHQ_ITEM_NAMES = [
|
| 36 |
+
"NoInterest",
|
| 37 |
+
"Depressed",
|
| 38 |
+
"Sleep",
|
| 39 |
+
"Tired",
|
| 40 |
+
"Appetite",
|
| 41 |
+
"Failure",
|
| 42 |
+
"Concentration",
|
| 43 |
+
"Psychomotor",
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
NEGATIVE_WORDS = {
|
| 47 |
+
"hopeless", "worthless", "empty", "tired", "sad", "lonely",
|
| 48 |
+
"fail", "useless", "burden", "numb", "anxious", "hate",
|
| 49 |
+
"depressed", "miserable", "terrible", "awful", "horrible",
|
| 50 |
+
"struggling", "suffering", "pain", "hurt", "crying",
|
| 51 |
+
"helpless", "frustrated", "angry", "guilty", "ashamed",
|
| 52 |
+
"exhausted", "overwhelmed", "stressed", "worried", "afraid",
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
POSITIVE_WORDS = {
|
| 56 |
+
"happy", "good", "fine", "great", "better", "enjoy",
|
| 57 |
+
"love", "hope", "okay", "well", "improving", "grateful",
|
| 58 |
+
"excited", "motivated", "confident", "peaceful", "calm",
|
| 59 |
+
"cheerful", "satisfied", "content", "wonderful", "amazing",
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
FILLER_PATTERN = re.compile(r"\b(um|uh|uhm|hmm|hm|erm|er|ah|like|you know)\b", re.I)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 66 |
+
# 2. MODEL DEFINITION (must match the notebook exactly)
|
| 67 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 68 |
+
|
| 69 |
+
class MPNetMultiOutputRegressor(nn.Module):
|
| 70 |
+
"""
|
| 71 |
+
MPNet encoder with attention pooling + 8-head multi-output regressor.
|
| 72 |
+
|
| 73 |
+
Architecture:
|
| 74 |
+
Encoder → last_hidden_state (B, L, 768)
|
| 75 |
+
AttnPool → pooled (B, 768)
|
| 76 |
+
Concat → [pooled, nv] (B, 768 + NV_SIZE)
|
| 77 |
+
SharedMLP → shared_repr (B, 256)
|
| 78 |
+
Heads → [h1..h8] 8 × Linear(256 → 1)
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
def __init__(self, model_name=MODEL_NAME, nv_size=NV_SIZE,
|
| 82 |
+
n_targets=N_TARGETS, dropout=0.1):
|
| 83 |
+
super().__init__()
|
| 84 |
+
self.encoder = AutoModel.from_pretrained(model_name)
|
| 85 |
+
hidden = self.encoder.config.hidden_size # 768
|
| 86 |
+
|
| 87 |
+
# Attention pooling
|
| 88 |
+
self.token_attn = nn.Linear(hidden, 1)
|
| 89 |
+
|
| 90 |
+
# Shared representation
|
| 91 |
+
self.shared_mlp = nn.Sequential(
|
| 92 |
+
nn.Linear(hidden + nv_size, 512),
|
| 93 |
+
nn.LayerNorm(512),
|
| 94 |
+
nn.GELU(),
|
| 95 |
+
nn.Dropout(dropout),
|
| 96 |
+
nn.Linear(512, 256),
|
| 97 |
+
nn.LayerNorm(256),
|
| 98 |
+
nn.GELU(),
|
| 99 |
+
nn.Dropout(dropout),
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# 8 independent heads for each PHQ-8 item
|
| 103 |
+
self.heads = nn.ModuleList([nn.Linear(256, 1) for _ in range(n_targets)])
|
| 104 |
+
self.dropout = nn.Dropout(dropout)
|
| 105 |
+
|
| 106 |
+
def forward(self, input_ids, attention_mask, nv_features):
|
| 107 |
+
out = self.encoder(input_ids=input_ids, attention_mask=attention_mask)
|
| 108 |
+
hidden = out.last_hidden_state # (B, L, H)
|
| 109 |
+
|
| 110 |
+
# Attention pooling
|
| 111 |
+
scores = self.token_attn(hidden).squeeze(-1) # (B, L)
|
| 112 |
+
scores = scores.masked_fill(attention_mask == 0, -1e9)
|
| 113 |
+
weights = torch.softmax(scores, dim=1).unsqueeze(-1) # (B, L, 1)
|
| 114 |
+
pooled = (hidden * weights).sum(dim=1) # (B, H)
|
| 115 |
+
pooled = self.dropout(pooled)
|
| 116 |
+
|
| 117 |
+
# Concat NV features + shared MLP
|
| 118 |
+
x = torch.cat([pooled, nv_features], dim=-1) # (B, H+NV)
|
| 119 |
+
x = self.shared_mlp(x) # (B, 256)
|
| 120 |
+
|
| 121 |
+
# Multi-output heads
|
| 122 |
+
preds = torch.cat([head(x) for head in self.heads], dim=-1) # (B, 8)
|
| 123 |
+
return preds
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# ════════════════════════════════════════════════════════════════════════════���══
|
| 127 |
+
# 3. TOKENIZATION (Head-Tail truncation — matches notebook)
|
| 128 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 129 |
+
|
| 130 |
+
def tokenize_head_tail(text, tokenizer, max_len=MAX_LEN,
|
| 131 |
+
head=HEAD_TOKENS, tail=TAIL_TOKENS):
|
| 132 |
+
"""Tokenize with head-tail truncation strategy."""
|
| 133 |
+
ids = tokenizer(
|
| 134 |
+
text,
|
| 135 |
+
add_special_tokens=False,
|
| 136 |
+
return_attention_mask=False,
|
| 137 |
+
return_token_type_ids=False,
|
| 138 |
+
)["input_ids"]
|
| 139 |
+
|
| 140 |
+
bos = tokenizer.cls_token_id or tokenizer.bos_token_id
|
| 141 |
+
eos = tokenizer.sep_token_id or tokenizer.eos_token_id
|
| 142 |
+
inner = max_len - 2
|
| 143 |
+
|
| 144 |
+
if len(ids) > inner:
|
| 145 |
+
h = min(head, inner // 2)
|
| 146 |
+
t = inner - h
|
| 147 |
+
ids = ids[:h] + ids[-t:]
|
| 148 |
+
|
| 149 |
+
ids = [bos] + ids + [eos]
|
| 150 |
+
pad = max_len - len(ids)
|
| 151 |
+
mask = [1] * len(ids) + [0] * pad
|
| 152 |
+
ids = ids + [tokenizer.pad_token_id] * pad
|
| 153 |
+
|
| 154 |
+
return ids, mask
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 158 |
+
# 4. NV FEATURE EXTRACTION (adapted for chatbot text — no audio)
|
| 159 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 160 |
+
|
| 161 |
+
def extract_nv_features(text: str) -> np.ndarray:
|
| 162 |
+
"""
|
| 163 |
+
Extract the 18-dim NV feature vector from text input.
|
| 164 |
+
|
| 165 |
+
Since we're processing typed text (not DAIC-WOZ audio transcripts),
|
| 166 |
+
most nonverbal features will be zero. The lexical features (neg_ratio,
|
| 167 |
+
pos_ratio, sentiment_gap) and text length features are still informative.
|
| 168 |
+
|
| 169 |
+
Feature order (must match training):
|
| 170 |
+
[nv_laugh, nv_sigh, nv_cough, nv_breath, nv_sniff, nv_groan,
|
| 171 |
+
nv_pause, nv_um, nv_uh, nv_total, filler_count,
|
| 172 |
+
word_count, utterance_count, avg_utt_len, response_brevity,
|
| 173 |
+
neg_ratio, pos_ratio, sentiment_gap]
|
| 174 |
+
"""
|
| 175 |
+
words = text.lower().split()
|
| 176 |
+
word_set = set(words)
|
| 177 |
+
total_words = len(words) + 1 # avoid div-by-zero
|
| 178 |
+
|
| 179 |
+
# Nonverbal tags: all zero for typed text (no <laugh>, <sigh> etc.)
|
| 180 |
+
nv_tags = [0.0] * 9 # laugh, sigh, cough, breath, sniff, groan, pause, um, uh
|
| 181 |
+
nv_total = 0.0
|
| 182 |
+
|
| 183 |
+
# Filler words
|
| 184 |
+
filler_count = len(FILLER_PATTERN.findall(text))
|
| 185 |
+
|
| 186 |
+
# Length features
|
| 187 |
+
sentences = [s.strip() for s in re.split(r"[.!?\n]+", text) if s.strip()]
|
| 188 |
+
word_count = len(words)
|
| 189 |
+
utterance_count = max(len(sentences), 1)
|
| 190 |
+
avg_utt_len = word_count / utterance_count
|
| 191 |
+
response_brevity = 1.0 if utterance_count < 50 else 0.0
|
| 192 |
+
|
| 193 |
+
# Lexical features
|
| 194 |
+
neg_count = len(word_set & NEGATIVE_WORDS)
|
| 195 |
+
pos_count = len(word_set & POSITIVE_WORDS)
|
| 196 |
+
neg_ratio = neg_count / total_words
|
| 197 |
+
pos_ratio = pos_count / total_words
|
| 198 |
+
sentiment_gap = (neg_count - pos_count) / total_words
|
| 199 |
+
|
| 200 |
+
features = np.array(
|
| 201 |
+
nv_tags + [nv_total, filler_count,
|
| 202 |
+
word_count, utterance_count, avg_utt_len, response_brevity,
|
| 203 |
+
neg_ratio, pos_ratio, sentiment_gap],
|
| 204 |
+
dtype=np.float32,
|
| 205 |
+
)
|
| 206 |
+
return features # shape (18,)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def severity_category(score: float) -> dict:
|
| 210 |
+
"""Return severity category info based on PHQ-8 total score."""
|
| 211 |
+
score = round(score)
|
| 212 |
+
if score <= 4:
|
| 213 |
+
return {"label": "Minimal", "color": "green", "description": "Minimal depression — no treatment typically needed."}
|
| 214 |
+
elif score <= 9:
|
| 215 |
+
return {"label": "Mild", "color": "amber", "description": "Mild depression — watchful waiting; repeat screening at follow-up."}
|
| 216 |
+
elif score <= 14:
|
| 217 |
+
return {"label": "Moderate", "color": "orange", "description": "Moderate depression — consultation with a mental health professional is recommended."}
|
| 218 |
+
elif score <= 19:
|
| 219 |
+
return {"label": "Moderately Severe", "color": "red-orange", "description": "Moderately severe depression — active treatment with pharmacotherapy and/or psychotherapy is recommended."}
|
| 220 |
+
else:
|
| 221 |
+
return {"label": "Severe", "color": "red", "description": "Severe depression — immediate initiation of pharmacotherapy and referral to a mental health specialist."}
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 225 |
+
# 5. LOAD MODEL & TOKENIZER
|
| 226 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 227 |
+
|
| 228 |
+
print(f"Loading tokenizer: {MODEL_NAME}")
|
| 229 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 230 |
+
|
| 231 |
+
print(f"Building model architecture...")
|
| 232 |
+
model = MPNetMultiOutputRegressor(
|
| 233 |
+
model_name=MODEL_NAME,
|
| 234 |
+
nv_size=NV_SIZE,
|
| 235 |
+
n_targets=N_TARGETS,
|
| 236 |
+
dropout=0.0, # no dropout at inference
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
print(f"Loading weights from: {MODEL_PATH}")
|
| 240 |
+
state_dict = torch.load(MODEL_PATH, map_location=DEVICE, weights_only=True)
|
| 241 |
+
model.load_state_dict(state_dict)
|
| 242 |
+
model.eval()
|
| 243 |
+
model.to(DEVICE)
|
| 244 |
+
print("✅ Model loaded successfully!")
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 248 |
+
# 6. FLASK APP
|
| 249 |
+
# ═══════════════════════════════════════════════════════════════════════════════
|
| 250 |
+
|
| 251 |
+
app = Flask(__name__)
|
| 252 |
+
CORS(app)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
@app.route("/health", methods=["GET"])
|
| 256 |
+
def health():
|
| 257 |
+
return jsonify({"status": "ok", "model": MODEL_NAME, "targets": N_TARGETS})
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
@app.route("/predict", methods=["POST"])
|
| 261 |
+
def predict():
|
| 262 |
+
"""
|
| 263 |
+
Predict PHQ-8 scores from 8 interview answers.
|
| 264 |
+
|
| 265 |
+
Request body:
|
| 266 |
+
{"answers": ["answer1", "answer2", ..., "answer8"]}
|
| 267 |
+
|
| 268 |
+
Response:
|
| 269 |
+
{
|
| 270 |
+
"scores": [0-3, ...], # 8 per-item scores
|
| 271 |
+
"total_score": 0-24, # sum of items
|
| 272 |
+
"severity": {...}, # category info
|
| 273 |
+
"filler_count": int,
|
| 274 |
+
"negative_words": [str, ...],
|
| 275 |
+
"positive_words": [str, ...],
|
| 276 |
+
"item_names": [str, ...]
|
| 277 |
+
}
|
| 278 |
+
"""
|
| 279 |
+
data = request.get_json(force=True)
|
| 280 |
+
answers = data.get("answers", [])
|
| 281 |
+
|
| 282 |
+
if len(answers) != 8:
|
| 283 |
+
return jsonify({"error": "Exactly 8 answers required"}), 400
|
| 284 |
+
|
| 285 |
+
# Combine all answers into one transcript (DAIC-WOZ style)
|
| 286 |
+
transcript = " ".join(answers)
|
| 287 |
+
|
| 288 |
+
# Tokenize
|
| 289 |
+
ids, mask = tokenize_head_tail(transcript, tokenizer)
|
| 290 |
+
input_ids = torch.tensor([ids], dtype=torch.long, device=DEVICE)
|
| 291 |
+
attention_mask = torch.tensor([mask], dtype=torch.long, device=DEVICE)
|
| 292 |
+
|
| 293 |
+
# Extract NV features
|
| 294 |
+
nv = extract_nv_features(transcript)
|
| 295 |
+
nv_tensor = torch.tensor([nv], dtype=torch.float, device=DEVICE)
|
| 296 |
+
|
| 297 |
+
# Inference
|
| 298 |
+
with torch.no_grad():
|
| 299 |
+
preds = model(input_ids, attention_mask, nv_tensor) # (1, 8)
|
| 300 |
+
|
| 301 |
+
# Post-process
|
| 302 |
+
scores_raw = preds[0].cpu().numpy()
|
| 303 |
+
scores_clipped = np.clip(scores_raw, 0, 3).tolist()
|
| 304 |
+
scores_rounded = [round(s, 2) for s in scores_clipped]
|
| 305 |
+
total_score = round(sum(scores_rounded), 2)
|
| 306 |
+
severity = severity_category(total_score)
|
| 307 |
+
|
| 308 |
+
# Detect filler and sentiment words in the transcript
|
| 309 |
+
words_lower = set(transcript.lower().split())
|
| 310 |
+
detected_neg = sorted(words_lower & NEGATIVE_WORDS)
|
| 311 |
+
detected_pos = sorted(words_lower & POSITIVE_WORDS)
|
| 312 |
+
filler_count = len(FILLER_PATTERN.findall(transcript))
|
| 313 |
+
|
| 314 |
+
return jsonify({
|
| 315 |
+
"scores": scores_rounded,
|
| 316 |
+
"total_score": total_score,
|
| 317 |
+
"severity": severity,
|
| 318 |
+
"filler_count": filler_count,
|
| 319 |
+
"negative_words": detected_neg,
|
| 320 |
+
"positive_words": detected_pos,
|
| 321 |
+
"item_names": PHQ_ITEM_NAMES,
|
| 322 |
+
})
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
if __name__ == "__main__":
|
| 326 |
+
app.run(host="0.0.0.0", port=8000, debug=False)
|
backend/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask==3.1.1
|
| 2 |
+
flask-cors==5.0.1
|
| 3 |
+
torch>=2.0.0
|
| 4 |
+
transformers>=4.30.0
|
| 5 |
+
numpy>=1.24.0
|
blueprint.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MindCheck Blueprint
|
| 2 |
+
|
| 3 |
+
Dokumen ini menjelaskan struktur lengkap dan arsitektur dari repositori MindCheck. Aplikasi ini dibagi menjadi dua bagian utama: **Frontend (Next.js)** dan **Backend (Flask + PyTorch)**.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 📂 Struktur Repositori
|
| 8 |
+
|
| 9 |
+
```text
|
| 10 |
+
NLP_AOL/
|
| 11 |
+
├── NOTEBOOK&MODEL/
|
| 12 |
+
│ ├── model.pt # 🧠 Model Weights: Hasil fine-tuning MPNet (multi-output regressor)
|
| 13 |
+
│ └── Copy_of_NLP_AOL.ipynb # 📓 Jupyter Notebook: Berisi tahapan EDA, ekstraksi fitur DAIC-WOZ, training, dan evaluasi model
|
| 14 |
+
│
|
| 15 |
+
├── backend/
|
| 16 |
+
│ ├── app.py # ⚙️ Flask API Server: Menjalankan model AI dan memproses teks input
|
| 17 |
+
│ └── requirements.txt # 📦 Python Dependencies: Daftar library untuk backend (torch, flask, transformers, dll)
|
| 18 |
+
│
|
| 19 |
+
├── mindcheck-web/ # 🖥️ Frontend Directory (Next.js)
|
| 20 |
+
│ ├── node_modules/ # 📦 NPM Dependencies: Folder hasil instalasi library JavaScript/TypeScript (jangan dimodifikasi manual)
|
| 21 |
+
│ ├── public/ # 🖼️ Static Assets: Berisi gambar, icon, font, atau file statis lain yang dapat diakses publik
|
| 22 |
+
│ ├── tailwind.config.ts # 🎨 Konfigurasi Tailwind CSS (warna, font, breakpoint)
|
| 23 |
+
│ ├── tsconfig.json # 🛠️ Konfigurasi TypeScript
|
| 24 |
+
│ ├── package.json # 📜 Daftar dependencies JavaScript dan script npm (dev, build, start)
|
| 25 |
+
│ │
|
| 26 |
+
│ └── src/
|
| 27 |
+
│ └── app/ # 🛣️ Next.js App Router
|
| 28 |
+
│ ├── globals.css # 💅 Global CSS & Tailwind Directives
|
| 29 |
+
│ ├── layout.tsx # 🧩 Root Layout: Struktur HTML utama yang menyelimuti semua halaman
|
| 30 |
+
│ ├── page.tsx # 🏠 Landing Page (/)
|
| 31 |
+
│ │
|
| 32 |
+
│ ├── chat/
|
| 33 |
+
│ │ └── page.tsx # 💬 Chatbot Interface (/chat): UI interaktif untuk wawancara 8 pertanyaan
|
| 34 |
+
│ │
|
| 35 |
+
│ ├── result/
|
| 36 |
+
│ │ └── page.tsx # 📊 Result Page (/result): Visualisasi skor PHQ-8, severity, dan rekomendasi
|
| 37 |
+
│ │
|
| 38 |
+
│ ├── history/
|
| 39 |
+
│ │ └── page.tsx # 🕰️ History Page (/history): Menampilkan riwayat screening yang tersimpan di localStorage
|
| 40 |
+
│ │
|
| 41 |
+
│ └── api/
|
| 42 |
+
│ └── predict/
|
| 43 |
+
│ └── route.ts # 🔌 API Proxy: Meneruskan request dari frontend Next.js ke backend Flask di port 8000
|
| 44 |
+
│
|
| 45 |
+
├── README.md # 📖 Dokumentasi utama proyek
|
| 46 |
+
├── blueprint.md # 🗺️ Dokumentasi struktur direktori (file ini)
|
| 47 |
+
└── example_answers.md # 📝 Skenario jawaban contoh untuk testing chatbot
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
## 🧩 Penjelasan Komponen
|
| 53 |
+
|
| 54 |
+
### 1. 🧠 AI Model (`NOTEBOOK&MODEL/model.pt`)
|
| 55 |
+
Ini adalah *core* kecerdasan buatan dari aplikasi. Model ini dibangun menggunakan arsitektur `sentence-transformers/all-mpnet-base-v2` yang telah di-finetune menggunakan dataset **DAIC-WOZ**.
|
| 56 |
+
Model menerima 2 bentuk input:
|
| 57 |
+
- **Teks transkrip** (di-tokenisasi menjadi `input_ids` dan `attention_mask` dengan strategi pemotongan Head-Tail).
|
| 58 |
+
- **Fitur Non-Verbal (NV)** berupa vektor 18 dimensi (rasio kata negatif, hitungan *filler words*, kecepatan bicara, dll).
|
| 59 |
+
|
| 60 |
+
Model ini bersifat **Multi-Output Regressor**, artinya ia langsung mengeluarkan 8 nilai prediksi secara bersamaan (satu untuk setiap item pertanyaan PHQ-8).
|
| 61 |
+
|
| 62 |
+
### 2. ⚙️ Backend API (`backend/`)
|
| 63 |
+
Ditulis menggunakan **Python** dan **Flask**. Bertugas sebagai jembatan antara aplikasi web dan model AI.
|
| 64 |
+
- Membaca request JSON berisi 8 jawaban teks dari user.
|
| 65 |
+
- Menggabungkannya menjadi satu transkrip panjang.
|
| 66 |
+
- Melakukan tokenisasi dan ekstraksi fitur menggunakan fungsi `extract_nv_features`.
|
| 67 |
+
- Menjalankan inferensi model PyTorch.
|
| 68 |
+
- Mengembalikan response JSON berisi array skor, skor total, kategori depresi (Minimal - Severe), dan daftar kata negatif/filler yang terdeteksi.
|
| 69 |
+
- Berjalan di **Port 8000** secara default untuk menghindari bentrok dengan port sistem operasi (seperti AirPlay macOS di port 5000).
|
| 70 |
+
|
| 71 |
+
### 3. 🖥️ Frontend Web (`mindcheck-web/`)
|
| 72 |
+
Ditulis menggunakan **Next.js 14 (App Router)**, **TypeScript**, dan **Tailwind CSS**.
|
| 73 |
+
- **`/` (Landing Page):** Penjelasan aplikasi, edukasi tentang apa itu tes PHQ-8, dan instruksi cara kerja.
|
| 74 |
+
- **`/chat` (Screening Interface):** Menyimulasikan wawancara klinis. User diwajibkan mengetik bebas untuk menjawab 8 pertanyaan terbuka. Terdapat sistem *fallback scoring* berbasis keyword & sentimen yang aktif otomatis jika backend AI sedang mati.
|
| 75 |
+
- **`/api/predict` (API Proxy):** Membantu mengatasi masalah CORS. Frontend tidak menembak langsung ke Flask, melainkan menembak ke *route internal* Next.js ini, yang kemudian meneruskannya ke Flask (`http://127.0.0.1:8000/predict`).
|
| 76 |
+
- **Data Storage:** Semua riwayat hasil prediksi disimpan secara lokal di browser menggunakan `localStorage` (`mindcheck_latest_result` dan `mindcheck_history`). Data anonim dan tidak ada database cloud yang digunakan demi privasi.
|
example_answers.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MindCheck — Example Answers for Testing
|
| 2 |
+
|
| 3 |
+
Berikut 3 skenario contoh jawaban yang bisa kamu coba di chatbot.
|
| 4 |
+
Buka **http://localhost:3000** → klik **Start Screening** → jawab 8 pertanyaan.
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## 🟢 Skenario 1: Minimal Depression (Expected Score: 0-4)
|
| 9 |
+
|
| 10 |
+
| # | Question | Answer (copy-paste or type) |
|
| 11 |
+
|---|----------|-----------------------------|
|
| 12 |
+
| 1 | Little interest or pleasure? | Not at all. I've been enjoying my hobbies and spending time with friends as usual. |
|
| 13 |
+
| 2 | Feeling down or depressed? | No, I've been feeling pretty good lately. Life has been going well. |
|
| 14 |
+
| 3 | Trouble sleeping? | Not at all. I sleep well every night and wake up feeling refreshed. |
|
| 15 |
+
| 4 | Tired or little energy? | I feel energetic and motivated most days. I exercise regularly. |
|
| 16 |
+
| 5 | Poor appetite or overeating? | My appetite is normal. I eat three healthy meals a day. |
|
| 17 |
+
| 6 | Feeling bad about yourself? | No, I feel good about myself and my accomplishments. |
|
| 18 |
+
| 7 | Trouble concentrating? | Not at all. I can focus well on my work and reading. |
|
| 19 |
+
| 8 | Moving slowly or being restless? | No, I feel normal. My energy level is consistent throughout the day. |
|
| 20 |
+
|
| 21 |
+
**Expected result**: Total score ≈ 0-4, Severity = **Minimal** 🟢
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 🟡 Skenario 2: Moderate Depression (Expected Score: 10-14)
|
| 26 |
+
|
| 27 |
+
| # | Question | Answer (copy-paste or type) |
|
| 28 |
+
|---|----------|-----------------------------|
|
| 29 |
+
| 1 | Little interest or pleasure? | More than half the days I just don't feel like doing anything. Things I used to enjoy don't interest me anymore. |
|
| 30 |
+
| 2 | Feeling down or depressed? | I feel sad and hopeless quite often. Several days a week I just feel down and empty inside. |
|
| 31 |
+
| 3 | Trouble sleeping? | Nearly every day I struggle with sleep. I wake up at 3am and can't fall back asleep. I feel exhausted. |
|
| 32 |
+
| 4 | Tired or little energy? | I'm tired all the time. Even small tasks feel overwhelming and I have to push myself to get through the day. |
|
| 33 |
+
| 5 | Poor appetite or overeating? | Several days I just don't feel like eating. I've been skipping meals and lost some weight. |
|
| 34 |
+
| 6 | Feeling bad about yourself? | I often feel like a failure. I keep thinking about all the things I should have done better. I feel worthless sometimes. |
|
| 35 |
+
| 7 | Trouble concentrating? | More than half the days I can't focus. I read the same paragraph over and over. My mind keeps wandering. |
|
| 36 |
+
| 8 | Moving slowly or being restless? | Several days I notice I'm moving slower than usual. Everything feels like it takes more effort. |
|
| 37 |
+
|
| 38 |
+
**Expected result**: Total score ≈ 10-14, Severity = **Moderate** 🟡
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## 🔴 Skenario 3: Severe Depression (Expected Score: 18-24)
|
| 43 |
+
|
| 44 |
+
| # | Question | Answer (copy-paste or type) |
|
| 45 |
+
|---|----------|-----------------------------|
|
| 46 |
+
| 1 | Little interest or pleasure? | Nearly every day I feel numb. Nothing brings me joy anymore. I've stopped doing everything I used to love. I feel empty and hopeless. |
|
| 47 |
+
| 2 | Feeling down or depressed? | I feel depressed and miserable constantly. Every day feels like a struggle. I feel worthless and hopeless about the future. I can't see things getting better. |
|
| 48 |
+
| 3 | Trouble sleeping? | I barely sleep at all. Nearly every night I lie awake feeling anxious and overwhelmed. When I do sleep, I have terrible nightmares. I'm exhausted all the time. |
|
| 49 |
+
| 4 | Tired or little energy? | I have absolutely no energy. Nearly every day I can barely get out of bed. Even taking a shower feels exhausting. I feel completely drained and useless. |
|
| 50 |
+
| 5 | Poor appetite or overeating? | I've completely lost my appetite. Nearly every day I force myself to eat but nothing tastes good. I've lost a lot of weight and feel weak. |
|
| 51 |
+
| 6 | Feeling bad about yourself? | I hate myself. Nearly every day I feel like a complete failure and a burden to everyone around me. I feel guilty about everything and ashamed of who I am. |
|
| 52 |
+
| 7 | Trouble concentrating? | I can't concentrate on anything at all. Nearly every day my mind is foggy and confused. I can't make simple decisions. I feel like I'm losing my mind. |
|
| 53 |
+
| 8 | Moving slowly or being restless? | Nearly every day I feel like I'm moving through mud. Everything is slow and heavy. Sometimes I just sit and stare at nothing for hours. People have noticed and asked if I'm okay. |
|
| 54 |
+
|
| 55 |
+
**Expected result**: Total score ≈ 18-24, Severity = **Severe** 🔴
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## 💡 Tips
|
| 60 |
+
|
| 61 |
+
- Kamu bisa **klik chip cepat** ("Not at all", "Several days", dll.) atau **ketik jawaban sendiri** di text input
|
| 62 |
+
- Jawaban bebas dalam bahasa Inggris — model dilatih pada data wawancara DAIC-WOZ
|
| 63 |
+
- Kalau Flask backend belum jalan, chatbot tetap berfungsi pakai **keyword matching** sebagai fallback
|
| 64 |
+
- Untuk hasil paling akurat, jalankan Flask backend dulu:
|
| 65 |
+
```bash
|
| 66 |
+
cd backend
|
| 67 |
+
pip install -r requirements.txt
|
| 68 |
+
python app.py
|
| 69 |
+
```
|
| 70 |
+
- Setelah selesai, klik **Save Results** untuk simpan ke history
|
| 71 |
+
- Buka **History** untuk lihat semua screening sebelumnya
|
mindcheck-web/.gitignore
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
| 2 |
+
|
| 3 |
+
# dependencies
|
| 4 |
+
/node_modules
|
| 5 |
+
/.pnp
|
| 6 |
+
.pnp.*
|
| 7 |
+
.yarn/*
|
| 8 |
+
!.yarn/patches
|
| 9 |
+
!.yarn/plugins
|
| 10 |
+
!.yarn/releases
|
| 11 |
+
!.yarn/versions
|
| 12 |
+
|
| 13 |
+
# testing
|
| 14 |
+
/coverage
|
| 15 |
+
|
| 16 |
+
# next.js
|
| 17 |
+
/.next/
|
| 18 |
+
/out/
|
| 19 |
+
|
| 20 |
+
# production
|
| 21 |
+
/build
|
| 22 |
+
|
| 23 |
+
# misc
|
| 24 |
+
.DS_Store
|
| 25 |
+
*.pem
|
| 26 |
+
|
| 27 |
+
# debug
|
| 28 |
+
npm-debug.log*
|
| 29 |
+
yarn-debug.log*
|
| 30 |
+
yarn-error.log*
|
| 31 |
+
.pnpm-debug.log*
|
| 32 |
+
|
| 33 |
+
# env files (can opt-in for committing if needed)
|
| 34 |
+
.env*
|
| 35 |
+
|
| 36 |
+
# vercel
|
| 37 |
+
.vercel
|
| 38 |
+
|
| 39 |
+
# typescript
|
| 40 |
+
*.tsbuildinfo
|
| 41 |
+
next-env.d.ts
|
mindcheck-web/AGENTS.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- BEGIN:nextjs-agent-rules -->
|
| 2 |
+
# This is NOT the Next.js you know
|
| 3 |
+
|
| 4 |
+
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices.
|
| 5 |
+
<!-- END:nextjs-agent-rules -->
|
mindcheck-web/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
@AGENTS.md
|
mindcheck-web/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
| 2 |
+
|
| 3 |
+
## Getting Started
|
| 4 |
+
|
| 5 |
+
First, run the development server:
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
npm run dev
|
| 9 |
+
# or
|
| 10 |
+
yarn dev
|
| 11 |
+
# or
|
| 12 |
+
pnpm dev
|
| 13 |
+
# or
|
| 14 |
+
bun dev
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
| 18 |
+
|
| 19 |
+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
| 20 |
+
|
| 21 |
+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
| 22 |
+
|
| 23 |
+
## Learn More
|
| 24 |
+
|
| 25 |
+
To learn more about Next.js, take a look at the following resources:
|
| 26 |
+
|
| 27 |
+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
| 28 |
+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
| 29 |
+
|
| 30 |
+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
| 31 |
+
|
| 32 |
+
## Deploy on Vercel
|
| 33 |
+
|
| 34 |
+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
| 35 |
+
|
| 36 |
+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
mindcheck-web/eslint.config.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig, globalIgnores } from "eslint/config";
|
| 2 |
+
import nextVitals from "eslint-config-next/core-web-vitals";
|
| 3 |
+
import nextTs from "eslint-config-next/typescript";
|
| 4 |
+
|
| 5 |
+
const eslintConfig = defineConfig([
|
| 6 |
+
...nextVitals,
|
| 7 |
+
...nextTs,
|
| 8 |
+
// Override default ignores of eslint-config-next.
|
| 9 |
+
globalIgnores([
|
| 10 |
+
// Default ignores of eslint-config-next:
|
| 11 |
+
".next/**",
|
| 12 |
+
"out/**",
|
| 13 |
+
"build/**",
|
| 14 |
+
"next-env.d.ts",
|
| 15 |
+
]),
|
| 16 |
+
]);
|
| 17 |
+
|
| 18 |
+
export default eslintConfig;
|
mindcheck-web/next.config.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { NextConfig } from "next";
|
| 2 |
+
|
| 3 |
+
const nextConfig: NextConfig = {
|
| 4 |
+
/* config options here */
|
| 5 |
+
};
|
| 6 |
+
|
| 7 |
+
export default nextConfig;
|
mindcheck-web/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
mindcheck-web/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "mindcheck-web",
|
| 3 |
+
"version": "0.1.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"scripts": {
|
| 6 |
+
"dev": "next dev",
|
| 7 |
+
"build": "next build",
|
| 8 |
+
"start": "next start",
|
| 9 |
+
"lint": "eslint"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"next": "16.2.7",
|
| 13 |
+
"react": "19.2.4",
|
| 14 |
+
"react-dom": "19.2.4"
|
| 15 |
+
},
|
| 16 |
+
"devDependencies": {
|
| 17 |
+
"@tailwindcss/postcss": "^4",
|
| 18 |
+
"@types/node": "^20",
|
| 19 |
+
"@types/react": "^19",
|
| 20 |
+
"@types/react-dom": "^19",
|
| 21 |
+
"eslint": "^9",
|
| 22 |
+
"eslint-config-next": "16.2.7",
|
| 23 |
+
"tailwindcss": "^4",
|
| 24 |
+
"typescript": "^5"
|
| 25 |
+
}
|
| 26 |
+
}
|
mindcheck-web/postcss.config.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const config = {
|
| 2 |
+
plugins: {
|
| 3 |
+
"@tailwindcss/postcss": {},
|
| 4 |
+
},
|
| 5 |
+
};
|
| 6 |
+
|
| 7 |
+
export default config;
|
mindcheck-web/public/file.svg
ADDED
|
|
mindcheck-web/public/globe.svg
ADDED
|
|
mindcheck-web/public/next.svg
ADDED
|
|
mindcheck-web/public/vercel.svg
ADDED
|
|
mindcheck-web/public/window.svg
ADDED
|
|
mindcheck-web/src/app/api/predict/route.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextResponse } from "next/server";
|
| 2 |
+
|
| 3 |
+
const FLASK_URL = process.env.FLASK_BACKEND_URL || "http://127.0.0.1:8000";
|
| 4 |
+
|
| 5 |
+
export async function POST(request: Request) {
|
| 6 |
+
try {
|
| 7 |
+
const body = await request.json();
|
| 8 |
+
|
| 9 |
+
const res = await fetch(`${FLASK_URL}/predict`, {
|
| 10 |
+
method: "POST",
|
| 11 |
+
headers: { "Content-Type": "application/json" },
|
| 12 |
+
body: JSON.stringify(body),
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
if (!res.ok) {
|
| 16 |
+
const errText = await res.text();
|
| 17 |
+
return NextResponse.json(
|
| 18 |
+
{ error: `Flask backend error: ${errText}` },
|
| 19 |
+
{ status: res.status },
|
| 20 |
+
);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const data = await res.json();
|
| 24 |
+
return NextResponse.json(data);
|
| 25 |
+
} catch (error) {
|
| 26 |
+
console.error("Proxy error:", error);
|
| 27 |
+
return NextResponse.json(
|
| 28 |
+
{ error: "Failed to connect to prediction backend. Is the Flask server running?" },
|
| 29 |
+
{ status: 502 },
|
| 30 |
+
);
|
| 31 |
+
}
|
| 32 |
+
}
|
mindcheck-web/src/app/chat/page.tsx
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import Link from "next/link";
|
| 4 |
+
import { useState, useRef, useEffect, useCallback } from "react";
|
| 5 |
+
import { useRouter } from "next/navigation";
|
| 6 |
+
|
| 7 |
+
/* ── 8 PHQ-8 Interview Questions (DAIC-WOZ style) ───────────────────────── */
|
| 8 |
+
const QUESTIONS = [
|
| 9 |
+
"Let's start by talking about things you usually enjoy. Lately, have you felt like you've lost interest or pleasure in doing them? Tell me a bit about how you've been feeling about your hobbies or daily activities.",
|
| 10 |
+
"I'd like to hear about your mood recently. Over the past couple of weeks, have you been feeling down, depressed, or perhaps a bit hopeless? Could you share what's been on your mind?",
|
| 11 |
+
"Let's talk about your sleep. How have you been sleeping lately? Tell me if you've had any trouble falling asleep, staying asleep, or maybe even sleeping too much.",
|
| 12 |
+
"How has your energy level been? Do you find yourself feeling tired or exhausted often? Tell me about a typical day and how you feel physically.",
|
| 13 |
+
"What about your eating habits? Have you noticed any changes, like a poor appetite or perhaps overeating? Tell me how your relationship with food has been lately.",
|
| 14 |
+
"How have you been feeling about yourself? Have there been moments where you felt bad, or like you let yourself or your family down? Feel free to share your thoughts openly.",
|
| 15 |
+
"Can you tell me about your focus and concentration? For example, when you read or watch TV, do you find your mind wandering? Tell me how it's been for you.",
|
| 16 |
+
"Have you or others noticed any changes in how you move or speak? Like moving much slower than usual, or maybe the opposite—feeling restless and unable to sit still? Tell me about it.",
|
| 17 |
+
];
|
| 18 |
+
|
| 19 |
+
const QUICK_OPTIONS = [
|
| 20 |
+
"Not at all",
|
| 21 |
+
"Several days",
|
| 22 |
+
"More than half the days",
|
| 23 |
+
"Nearly every day",
|
| 24 |
+
];
|
| 25 |
+
|
| 26 |
+
const ITEM_SHORT_NAMES = [
|
| 27 |
+
"Loss of Interest",
|
| 28 |
+
"Feeling Depressed",
|
| 29 |
+
"Sleep Issues",
|
| 30 |
+
"Fatigue",
|
| 31 |
+
"Appetite Changes",
|
| 32 |
+
"Self-Criticism",
|
| 33 |
+
"Concentration",
|
| 34 |
+
"Psychomotor",
|
| 35 |
+
];
|
| 36 |
+
|
| 37 |
+
type Message = { role: "bot" | "user"; text: string };
|
| 38 |
+
|
| 39 |
+
export default function ChatScreening() {
|
| 40 |
+
const router = useRouter();
|
| 41 |
+
const [messages, setMessages] = useState<Message[]>([
|
| 42 |
+
{ role: "bot", text: "Hello! I'm going to ask you 8 short questions based on the PHQ-8 screening. Please answer honestly — all data stays anonymous and is not stored on any server.\n\nLet's begin." },
|
| 43 |
+
{ role: "bot", text: QUESTIONS[0] },
|
| 44 |
+
]);
|
| 45 |
+
const [currentStep, setCurrentStep] = useState(0);
|
| 46 |
+
const [answers, setAnswers] = useState<string[]>([]);
|
| 47 |
+
const [inputValue, setInputValue] = useState("");
|
| 48 |
+
const [isTyping, setIsTyping] = useState(false);
|
| 49 |
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
| 50 |
+
const chatEndRef = useRef<HTMLDivElement>(null);
|
| 51 |
+
const inputRef = useRef<HTMLInputElement>(null);
|
| 52 |
+
|
| 53 |
+
/* auto-scroll on new messages */
|
| 54 |
+
useEffect(() => {
|
| 55 |
+
chatEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
| 56 |
+
}, [messages, isTyping]);
|
| 57 |
+
|
| 58 |
+
/* focus input */
|
| 59 |
+
useEffect(() => {
|
| 60 |
+
if (!isSubmitting) inputRef.current?.focus();
|
| 61 |
+
}, [currentStep, isSubmitting]);
|
| 62 |
+
|
| 63 |
+
/* ── Submit all answers to backend ──────────────────────────────────── */
|
| 64 |
+
const submitToBackend = useCallback(
|
| 65 |
+
async (allAnswers: string[]) => {
|
| 66 |
+
setIsSubmitting(true);
|
| 67 |
+
setIsTyping(true);
|
| 68 |
+
setMessages((prev) => [
|
| 69 |
+
...prev,
|
| 70 |
+
{ role: "bot", text: "Thank you for completing all 8 questions! I'm now analyzing your responses..." },
|
| 71 |
+
]);
|
| 72 |
+
|
| 73 |
+
try {
|
| 74 |
+
const res = await fetch("/api/predict", {
|
| 75 |
+
method: "POST",
|
| 76 |
+
headers: { "Content-Type": "application/json" },
|
| 77 |
+
body: JSON.stringify({ answers: allAnswers }),
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
if (!res.ok) {
|
| 81 |
+
console.warn(`Backend returned ${res.status}, falling back to local scoring`);
|
| 82 |
+
throw "Fallback";
|
| 83 |
+
}
|
| 84 |
+
const data = await res.json();
|
| 85 |
+
|
| 86 |
+
/* Store result in localStorage */
|
| 87 |
+
const result = {
|
| 88 |
+
...data,
|
| 89 |
+
answers: allAnswers,
|
| 90 |
+
questions: QUESTIONS,
|
| 91 |
+
itemShortNames: ITEM_SHORT_NAMES,
|
| 92 |
+
date: new Date().toISOString(),
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
localStorage.setItem("mindcheck_latest_result", JSON.stringify(result));
|
| 96 |
+
|
| 97 |
+
setIsTyping(false);
|
| 98 |
+
setMessages((prev) => [
|
| 99 |
+
...prev,
|
| 100 |
+
{ role: "bot", text: "Analysis complete! Redirecting you to your results..." },
|
| 101 |
+
]);
|
| 102 |
+
|
| 103 |
+
setTimeout(() => router.push("/result"), 1200);
|
| 104 |
+
} catch (err) {
|
| 105 |
+
console.warn("Prediction error:", err);
|
| 106 |
+
setIsTyping(false);
|
| 107 |
+
|
| 108 |
+
/* ── Fallback: keyword-based scoring ────────────────── */
|
| 109 |
+
const fallbackScores: number[] = allAnswers.map((ans) => {
|
| 110 |
+
const a = ans.toLowerCase().trim();
|
| 111 |
+
if (/\b(not at all|never|no|none|tidak|ngga|ga|tidak pernah)\b/.test(a)) return 0;
|
| 112 |
+
if (/\b(several days|sometimes|a little|occasionally|kadang|jarang)\b/.test(a)) return 1;
|
| 113 |
+
if (/\b(more than half|often|frequently|most days|sering|lumayan sering)\b/.test(a)) return 2;
|
| 114 |
+
if (/\b(nearly every day|always|every day|constantly|everyday|selalu|tiap hari|hampir tiap hari)\b/.test(a)) return 3;
|
| 115 |
+
|
| 116 |
+
/* Sentiment-based fallback */
|
| 117 |
+
const negWords = ["hopeless","worthless","empty","tired","sad","lonely","fail","useless","burden","numb","anxious","hate","depressed","miserable","terrible","awful","struggling","suffering","exhausted","overwhelmed","stressed","worried", "sedih", "capek", "lelah", "hampa", "kesepian", "gagal", "beban", "benci", "stres", "bingung", "hancur", "buruk"];
|
| 118 |
+
const words = a.split(/\s+/);
|
| 119 |
+
const negCount = words.filter((w) => negWords.includes(w)).length;
|
| 120 |
+
if (negCount >= 3) return 3;
|
| 121 |
+
if (negCount >= 2) return 2;
|
| 122 |
+
if (negCount >= 1) return 1;
|
| 123 |
+
return 1; // default middle score for ambiguous text
|
| 124 |
+
|
| 125 |
+
});
|
| 126 |
+
|
| 127 |
+
const totalScore = fallbackScores.reduce((s, v) => s + v, 0);
|
| 128 |
+
let severity;
|
| 129 |
+
if (totalScore <= 4) severity = { label: "Minimal", color: "green", description: "Minimal depression — no treatment typically needed." };
|
| 130 |
+
else if (totalScore <= 9) severity = { label: "Mild", color: "amber", description: "Mild depression — watchful waiting recommended." };
|
| 131 |
+
else if (totalScore <= 14) severity = { label: "Moderate", color: "orange", description: "Moderate depression — consultation recommended." };
|
| 132 |
+
else if (totalScore <= 19) severity = { label: "Moderately Severe", color: "red-orange", description: "Moderately severe depression — active treatment recommended." };
|
| 133 |
+
else severity = { label: "Severe", color: "red", description: "Severe depression — immediate referral recommended." };
|
| 134 |
+
|
| 135 |
+
const combined = allAnswers.join(" ").toLowerCase();
|
| 136 |
+
const negWordsList = ["hopeless","worthless","empty","tired","sad","lonely","fail","useless","burden","numb","anxious","hate","depressed","miserable","terrible","awful","struggling","suffering","exhausted","overwhelmed","stressed","worried", "sedih", "capek", "lelah", "hampa", "kesepian", "gagal", "beban", "benci", "stres", "bingung", "hancur", "buruk"];
|
| 137 |
+
const foundNeg = negWordsList.filter((w) => combined.includes(w));
|
| 138 |
+
const fillerPattern = /\b(um|uh|uhm|hmm|hm|like|you know)\b/gi;
|
| 139 |
+
const fillerCount = (combined.match(fillerPattern) || []).length;
|
| 140 |
+
|
| 141 |
+
const result = {
|
| 142 |
+
scores: fallbackScores,
|
| 143 |
+
total_score: totalScore,
|
| 144 |
+
severity,
|
| 145 |
+
filler_count: fillerCount,
|
| 146 |
+
negative_words: foundNeg,
|
| 147 |
+
positive_words: [],
|
| 148 |
+
item_names: ITEM_SHORT_NAMES.map((n) => n.replace(/ /g, "")),
|
| 149 |
+
answers: allAnswers,
|
| 150 |
+
questions: QUESTIONS,
|
| 151 |
+
itemShortNames: ITEM_SHORT_NAMES,
|
| 152 |
+
date: new Date().toISOString(),
|
| 153 |
+
fallback: true,
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
localStorage.setItem("mindcheck_latest_result", JSON.stringify(result));
|
| 157 |
+
|
| 158 |
+
setMessages((prev) => [
|
| 159 |
+
...prev,
|
| 160 |
+
{ role: "bot", text: "Analysis complete (using local scoring as the model server is unavailable). Redirecting to your results..." },
|
| 161 |
+
]);
|
| 162 |
+
setTimeout(() => router.push("/result"), 1200);
|
| 163 |
+
}
|
| 164 |
+
},
|
| 165 |
+
[router],
|
| 166 |
+
);
|
| 167 |
+
|
| 168 |
+
/* ── Handle user answer ─────────────────────────────────────────────── */
|
| 169 |
+
const handleAnswer = useCallback(
|
| 170 |
+
(text: string) => {
|
| 171 |
+
if (isSubmitting || !text.trim()) return;
|
| 172 |
+
|
| 173 |
+
const newAnswers = [...answers, text.trim()];
|
| 174 |
+
setAnswers(newAnswers);
|
| 175 |
+
setMessages((prev) => [...prev, { role: "user", text: text.trim() }]);
|
| 176 |
+
setInputValue("");
|
| 177 |
+
|
| 178 |
+
const nextStep = currentStep + 1;
|
| 179 |
+
|
| 180 |
+
if (nextStep >= QUESTIONS.length) {
|
| 181 |
+
/* All questions answered → submit */
|
| 182 |
+
setCurrentStep(nextStep);
|
| 183 |
+
submitToBackend(newAnswers);
|
| 184 |
+
} else {
|
| 185 |
+
/* Show typing indicator, then next question */
|
| 186 |
+
setIsTyping(true);
|
| 187 |
+
setCurrentStep(nextStep);
|
| 188 |
+
setTimeout(() => {
|
| 189 |
+
setIsTyping(false);
|
| 190 |
+
setMessages((prev) => [
|
| 191 |
+
...prev,
|
| 192 |
+
{ role: "bot", text: QUESTIONS[nextStep] },
|
| 193 |
+
]);
|
| 194 |
+
}, 800);
|
| 195 |
+
}
|
| 196 |
+
},
|
| 197 |
+
[answers, currentStep, isSubmitting, submitToBackend],
|
| 198 |
+
);
|
| 199 |
+
|
| 200 |
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
| 201 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 202 |
+
e.preventDefault();
|
| 203 |
+
handleAnswer(inputValue);
|
| 204 |
+
}
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
const progress = Math.min(((currentStep) / QUESTIONS.length) * 100, 100);
|
| 208 |
+
const isDone = currentStep >= QUESTIONS.length;
|
| 209 |
+
|
| 210 |
+
return (
|
| 211 |
+
<>
|
| 212 |
+
{/* TopAppBar */}
|
| 213 |
+
<header className="bg-surface-bright dark:bg-surface-dim font-section-heading text-section-heading w-full sticky top-0 border-b border-outline-variant flex justify-between items-center h-14 px-gutter z-50">
|
| 214 |
+
<div className="flex items-center gap-2">
|
| 215 |
+
<span className="material-symbols-outlined text-primary dark:text-primary-fixed" data-icon="psychology">psychology</span>
|
| 216 |
+
<span className="font-section-heading text-section-heading text-primary font-bold">MindCheck</span>
|
| 217 |
+
</div>
|
| 218 |
+
<div className="text-primary dark:text-primary-fixed text-sm">
|
| 219 |
+
{isDone ? "Complete" : `Question ${currentStep + 1} of ${QUESTIONS.length}`}
|
| 220 |
+
</div>
|
| 221 |
+
<Link href="/" className="text-secondary hover:opacity-80 transition-opacity active:opacity-70">
|
| 222 |
+
Exit
|
| 223 |
+
</Link>
|
| 224 |
+
</header>
|
| 225 |
+
|
| 226 |
+
<div className="flex-1 flex max-w-container-max mx-auto w-full h-[calc(100vh-3.5rem)]">
|
| 227 |
+
{/* LEFT SIDEBAR */}
|
| 228 |
+
<aside className="hidden md:flex flex-col w-[280px] border-r border-outline-variant bg-surface-container-lowest p-gutter justify-between h-full sticky top-14 overflow-y-auto">
|
| 229 |
+
<div>
|
| 230 |
+
<h2 className="font-section-heading text-section-heading text-on-surface mb-stack-md">Questions</h2>
|
| 231 |
+
<ul className="space-y-stack-sm flex flex-col">
|
| 232 |
+
{QUESTIONS.map((_, i) => {
|
| 233 |
+
const isCompleted = i < currentStep;
|
| 234 |
+
const isCurrent = i === currentStep && !isDone;
|
| 235 |
+
return (
|
| 236 |
+
<li
|
| 237 |
+
key={i}
|
| 238 |
+
className={`flex items-center gap-3 p-2 rounded transition-all duration-300 ${
|
| 239 |
+
isCurrent
|
| 240 |
+
? "text-primary bg-surface-container-low border border-outline-variant"
|
| 241 |
+
: isCompleted
|
| 242 |
+
? "text-secondary"
|
| 243 |
+
: "text-secondary"
|
| 244 |
+
}`}
|
| 245 |
+
>
|
| 246 |
+
<span className="material-symbols-outlined" data-icon={
|
| 247 |
+
isCompleted ? "check_circle" : isCurrent ? "radio_button_checked" : "radio_button_unchecked"
|
| 248 |
+
}>
|
| 249 |
+
{isCompleted ? "check_circle" : isCurrent ? "radio_button_checked" : "radio_button_unchecked"}
|
| 250 |
+
</span>
|
| 251 |
+
<span className={`font-caption-sm text-caption-sm ${
|
| 252 |
+
isCompleted ? "text-on-surface-variant" : isCurrent ? "font-bold" : "text-outline-variant"
|
| 253 |
+
}`}>
|
| 254 |
+
{ITEM_SHORT_NAMES[i]}
|
| 255 |
+
</span>
|
| 256 |
+
</li>
|
| 257 |
+
);
|
| 258 |
+
})}
|
| 259 |
+
</ul>
|
| 260 |
+
</div>
|
| 261 |
+
<div className="mt-stack-lg bg-surface-container-low border border-outline-variant rounded p-stack-md flex items-start gap-2 flex-col">
|
| 262 |
+
<span className="material-symbols-outlined text-primary text-[20px]" data-icon="info">info</span>
|
| 263 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant">Answer honestly, all data is anonymous and processed locally.</p>
|
| 264 |
+
<div className="w-full border-t border-outline-variant mt-4 pt-4 text-center">
|
| 265 |
+
<p className="text-[11px] text-on-surface-variant opacity-60">© 2023 MindCheck. All rights reserved.</p>
|
| 266 |
+
</div>
|
| 267 |
+
</div>
|
| 268 |
+
</aside>
|
| 269 |
+
|
| 270 |
+
{/* RIGHT MAIN */}
|
| 271 |
+
<main className="flex-1 flex flex-col relative h-full bg-surface-container-lowest">
|
| 272 |
+
{/* Progress Bar */}
|
| 273 |
+
<div className="w-full h-1 bg-surface-variant absolute top-0 left-0 z-10">
|
| 274 |
+
<div
|
| 275 |
+
className="h-full bg-primary transition-all duration-700 ease-out"
|
| 276 |
+
style={{ width: `${progress}%` }}
|
| 277 |
+
/>
|
| 278 |
+
</div>
|
| 279 |
+
|
| 280 |
+
{/* Chat Area */}
|
| 281 |
+
<div className="flex-1 overflow-y-auto p-gutter pt-[40px] space-y-stack-lg pb-56">
|
| 282 |
+
{messages.map((msg, i) => (
|
| 283 |
+
<div
|
| 284 |
+
key={i}
|
| 285 |
+
className={`flex gap-4 items-end ${msg.role === "user" ? "justify-end w-full" : "max-w-[80%]"}`}
|
| 286 |
+
style={{
|
| 287 |
+
animation: "fadeSlideIn 0.4s ease-out",
|
| 288 |
+
}}
|
| 289 |
+
>
|
| 290 |
+
{msg.role === "bot" && (
|
| 291 |
+
<div className="w-8 h-8 rounded-full bg-surface-container-high border border-outline-variant flex items-center justify-center shrink-0">
|
| 292 |
+
<span className="material-symbols-outlined text-primary text-[18px]" data-icon="psychology">psychology</span>
|
| 293 |
+
</div>
|
| 294 |
+
)}
|
| 295 |
+
<div
|
| 296 |
+
className={`${
|
| 297 |
+
msg.role === "bot"
|
| 298 |
+
? "bg-surface-container-lowest border border-outline-variant rounded-t-lg rounded-br-lg"
|
| 299 |
+
: "bg-[#EEEDFE] border border-outline-variant rounded-t-lg rounded-bl-lg max-w-[80%]"
|
| 300 |
+
} p-4`}
|
| 301 |
+
>
|
| 302 |
+
<p className="font-body-md text-body-md text-on-surface whitespace-pre-line">{msg.text}</p>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
))}
|
| 306 |
+
|
| 307 |
+
{/* Typing Indicator */}
|
| 308 |
+
{isTyping && (
|
| 309 |
+
<div className="flex gap-4 items-end max-w-[80%]">
|
| 310 |
+
<div className="w-8 h-8 rounded-full bg-surface-container-high border border-outline-variant flex items-center justify-center shrink-0">
|
| 311 |
+
<span className="material-symbols-outlined text-primary text-[18px]" data-icon="psychology">psychology</span>
|
| 312 |
+
</div>
|
| 313 |
+
<div className="bg-surface-container-lowest border border-outline-variant rounded-t-lg rounded-br-lg p-4 flex gap-1.5 items-center">
|
| 314 |
+
<span className="w-2 h-2 bg-primary rounded-full animate-bounce" style={{ animationDelay: "0ms" }} />
|
| 315 |
+
<span className="w-2 h-2 bg-primary rounded-full animate-bounce" style={{ animationDelay: "150ms" }} />
|
| 316 |
+
<span className="w-2 h-2 bg-primary rounded-full animate-bounce" style={{ animationDelay: "300ms" }} />
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
)}
|
| 320 |
+
|
| 321 |
+
<div ref={chatEndRef} />
|
| 322 |
+
</div>
|
| 323 |
+
|
| 324 |
+
{/* Input Area Fixed Bottom */}
|
| 325 |
+
{!isDone && (
|
| 326 |
+
<div className="absolute bottom-0 left-0 w-full bg-surface-container-lowest border-t border-outline-variant p-gutter">
|
| 327 |
+
{/* Text Input */}
|
| 328 |
+
<div className="relative flex items-center">
|
| 329 |
+
<input
|
| 330 |
+
ref={inputRef}
|
| 331 |
+
className="w-full h-12 pl-4 pr-12 rounded border border-outline-variant focus:border-primary focus:ring-0 focus:outline-none bg-surface-container-lowest text-on-surface placeholder:text-[#888780] font-body-md text-body-md transition-colors"
|
| 332 |
+
placeholder="Type your answer..."
|
| 333 |
+
type="text"
|
| 334 |
+
value={inputValue}
|
| 335 |
+
onChange={(e) => setInputValue(e.target.value)}
|
| 336 |
+
onKeyDown={handleKeyDown}
|
| 337 |
+
disabled={isTyping || isSubmitting}
|
| 338 |
+
/>
|
| 339 |
+
<button
|
| 340 |
+
onClick={() => handleAnswer(inputValue)}
|
| 341 |
+
disabled={!inputValue.trim() || isTyping || isSubmitting}
|
| 342 |
+
className="absolute right-2 top-1/2 -translate-y-1/2 w-8 h-8 flex items-center justify-center text-primary hover:text-on-primary-fixed-variant transition-all duration-200 disabled:opacity-30 disabled:cursor-not-allowed hover:scale-110 active:scale-90"
|
| 343 |
+
>
|
| 344 |
+
<span className="material-symbols-outlined" data-icon="send">send</span>
|
| 345 |
+
</button>
|
| 346 |
+
</div>
|
| 347 |
+
</div>
|
| 348 |
+
)}
|
| 349 |
+
</main>
|
| 350 |
+
</div>
|
| 351 |
+
|
| 352 |
+
{/* Inline animation keyframes */}
|
| 353 |
+
<style jsx global>{`
|
| 354 |
+
@keyframes fadeSlideIn {
|
| 355 |
+
from {
|
| 356 |
+
opacity: 0;
|
| 357 |
+
transform: translateY(12px);
|
| 358 |
+
}
|
| 359 |
+
to {
|
| 360 |
+
opacity: 1;
|
| 361 |
+
transform: translateY(0);
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
`}</style>
|
| 365 |
+
</>
|
| 366 |
+
);
|
| 367 |
+
}
|
mindcheck-web/src/app/favicon.ico
ADDED
|
|
mindcheck-web/src/app/globals.css
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import "tailwindcss";
|
| 2 |
+
|
| 3 |
+
@theme {
|
| 4 |
+
--color-surface-container: #f0ecf6;
|
| 5 |
+
--color-surface-bright: #fcf8ff;
|
| 6 |
+
--color-on-primary-fixed-variant: #3f35a3;
|
| 7 |
+
--color-inverse-primary: #c5c0ff;
|
| 8 |
+
--color-on-background: #1c1b22;
|
| 9 |
+
--color-tertiary-fixed-dim: #ffb77d;
|
| 10 |
+
--color-on-primary-fixed: #140067;
|
| 11 |
+
--color-primary: #3b309e;
|
| 12 |
+
--color-primary-fixed: #e3dfff;
|
| 13 |
+
--color-tertiary: #683500;
|
| 14 |
+
--color-surface-variant: #e5e1eb;
|
| 15 |
+
--color-on-secondary-fixed: #191a2a;
|
| 16 |
+
--color-on-tertiary-fixed: #2f1500;
|
| 17 |
+
--color-on-error: #ffffff;
|
| 18 |
+
--color-on-tertiary-container: #ffc69a;
|
| 19 |
+
--color-error: #ba1a1a;
|
| 20 |
+
--color-surface-container-low: #f6f2fc;
|
| 21 |
+
--color-surface-container-highest: #e5e1eb;
|
| 22 |
+
--color-on-secondary: #ffffff;
|
| 23 |
+
--color-on-tertiary-fixed-variant: #6e3900;
|
| 24 |
+
--color-tertiary-fixed: #ffdcc3;
|
| 25 |
+
--color-surface-container-lowest: #ffffff;
|
| 26 |
+
--color-outline: #787584;
|
| 27 |
+
--color-error-container: #ffdad6;
|
| 28 |
+
--color-outline-variant: #c8c4d5;
|
| 29 |
+
--color-on-tertiary: #ffffff;
|
| 30 |
+
--color-secondary: #5c5d6f;
|
| 31 |
+
--color-on-error-container: #93000a;
|
| 32 |
+
--color-surface-dim: #dcd8e2;
|
| 33 |
+
--color-on-secondary-container: #616174;
|
| 34 |
+
--color-surface-tint: #584fbc;
|
| 35 |
+
--color-surface-container-high: #ebe6f0;
|
| 36 |
+
--color-background: #fcf8ff;
|
| 37 |
+
--color-tertiary-container: #8a4900;
|
| 38 |
+
--color-primary-container: #534ab7;
|
| 39 |
+
--color-surface: #fcf8ff;
|
| 40 |
+
--color-on-secondary-fixed-variant: #454557;
|
| 41 |
+
--color-secondary-container: #dfdef4;
|
| 42 |
+
--color-on-surface-variant: #474553;
|
| 43 |
+
--color-on-surface: #1c1b22;
|
| 44 |
+
--color-inverse-surface: #312f37;
|
| 45 |
+
--color-secondary-fixed-dim: #c5c5da;
|
| 46 |
+
--color-on-primary-container: #d1ccff;
|
| 47 |
+
--color-on-primary: #ffffff;
|
| 48 |
+
--color-primary-fixed-dim: #c5c0ff;
|
| 49 |
+
--color-inverse-on-surface: #f3eff9;
|
| 50 |
+
--color-secondary-fixed: #e1e0f6;
|
| 51 |
+
|
| 52 |
+
--spacing-gutter: 24px;
|
| 53 |
+
--spacing-stack-lg: 40px;
|
| 54 |
+
--spacing-stack-sm: 8px;
|
| 55 |
+
--spacing-container-max: 1100px;
|
| 56 |
+
--spacing-stack-md: 16px;
|
| 57 |
+
--spacing-section-padding: 32px;
|
| 58 |
+
|
| 59 |
+
--text-caption-sm: 13px;
|
| 60 |
+
--text-caption-sm--line-height: 1.4;
|
| 61 |
+
--text-caption-sm--letter-spacing: 0.01em;
|
| 62 |
+
--text-caption-sm--font-weight: 500;
|
| 63 |
+
|
| 64 |
+
--text-hero-lg: 32px;
|
| 65 |
+
--text-hero-lg--line-height: 1.2;
|
| 66 |
+
--text-hero-lg--letter-spacing: -0.02em;
|
| 67 |
+
--text-hero-lg--font-weight: 500;
|
| 68 |
+
|
| 69 |
+
--text-body-md: 15px;
|
| 70 |
+
--text-body-md--line-height: 1.6;
|
| 71 |
+
--text-body-md--font-weight: 400;
|
| 72 |
+
|
| 73 |
+
--text-section-heading: 22px;
|
| 74 |
+
--text-section-heading--line-height: 1.4;
|
| 75 |
+
--text-section-heading--letter-spacing: -0.01em;
|
| 76 |
+
--text-section-heading--font-weight: 500;
|
| 77 |
+
|
| 78 |
+
--text-hero-lg-mobile: 28px;
|
| 79 |
+
--text-hero-lg-mobile--line-height: 1.2;
|
| 80 |
+
--text-hero-lg-mobile--font-weight: 500;
|
| 81 |
+
|
| 82 |
+
--text-label-uppercase: 11px;
|
| 83 |
+
--text-label-uppercase--line-height: 1;
|
| 84 |
+
--text-label-uppercase--letter-spacing: 0.05em;
|
| 85 |
+
--text-label-uppercase--font-weight: 600;
|
| 86 |
+
|
| 87 |
+
--font-caption-sm: Inter, sans-serif;
|
| 88 |
+
--font-hero-lg: Inter, sans-serif;
|
| 89 |
+
--font-body-md: Inter, sans-serif;
|
| 90 |
+
--font-section-heading: Inter, sans-serif;
|
| 91 |
+
--font-hero-lg-mobile: Inter, sans-serif;
|
| 92 |
+
--font-label-uppercase: Inter, sans-serif;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
body {
|
| 96 |
+
background-color: var(--color-background);
|
| 97 |
+
color: var(--color-on-background);
|
| 98 |
+
}
|
mindcheck-web/src/app/history/page.tsx
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import Link from "next/link";
|
| 4 |
+
import { useEffect, useState } from "react";
|
| 5 |
+
|
| 6 |
+
type SeverityInfo = {
|
| 7 |
+
label: string;
|
| 8 |
+
color: string;
|
| 9 |
+
description: string;
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
type ResultData = {
|
| 13 |
+
scores: number[];
|
| 14 |
+
total_score: number;
|
| 15 |
+
severity: SeverityInfo;
|
| 16 |
+
filler_count: number;
|
| 17 |
+
negative_words: string[];
|
| 18 |
+
positive_words: string[];
|
| 19 |
+
item_names: string[];
|
| 20 |
+
answers: string[];
|
| 21 |
+
questions: string[];
|
| 22 |
+
itemShortNames: string[];
|
| 23 |
+
date: string;
|
| 24 |
+
fallback?: boolean;
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
const SEVERITY_BADGE_STYLES: Record<string, string> = {
|
| 28 |
+
Minimal: "bg-green-100 text-green-800 border-green-200",
|
| 29 |
+
Mild: "bg-amber-100 text-amber-800 border-amber-200",
|
| 30 |
+
Moderate: "bg-orange-100 text-orange-800 border-orange-200",
|
| 31 |
+
"Moderately Severe": "bg-red-100 text-red-700 border-red-200",
|
| 32 |
+
Severe: "bg-red-200 text-red-900 border-red-300",
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
export default function HistoryPage() {
|
| 36 |
+
const [history, setHistory] = useState<ResultData[]>([]);
|
| 37 |
+
const [loaded, setLoaded] = useState(false);
|
| 38 |
+
|
| 39 |
+
useEffect(() => {
|
| 40 |
+
const raw = localStorage.getItem("mindcheck_history");
|
| 41 |
+
if (raw) {
|
| 42 |
+
try {
|
| 43 |
+
setHistory(JSON.parse(raw));
|
| 44 |
+
} catch { /* ignore */ }
|
| 45 |
+
}
|
| 46 |
+
setLoaded(true);
|
| 47 |
+
}, []);
|
| 48 |
+
|
| 49 |
+
const clearHistory = () => {
|
| 50 |
+
if (confirm("Are you sure you want to clear all history? This cannot be undone.")) {
|
| 51 |
+
localStorage.removeItem("mindcheck_history");
|
| 52 |
+
setHistory([]);
|
| 53 |
+
}
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
return (
|
| 57 |
+
<>
|
| 58 |
+
{/* TopNavBar */}
|
| 59 |
+
<nav className="bg-surface dark:bg-on-background w-full top-0 sticky border-b border-outline-variant z-50">
|
| 60 |
+
<div className="flex justify-between items-center h-16 px-gutter max-w-container-max mx-auto">
|
| 61 |
+
<Link href="/" className="font-hero-lg text-hero-lg font-bold text-primary dark:text-inverse-primary hidden md:block">
|
| 62 |
+
MindCheck
|
| 63 |
+
</Link>
|
| 64 |
+
<Link href="/" className="md:hidden text-primary flex items-center gap-2">
|
| 65 |
+
<span className="material-symbols-outlined">arrow_back</span>
|
| 66 |
+
</Link>
|
| 67 |
+
<div className="font-section-heading text-section-heading text-primary absolute left-1/2 -translate-x-1/2">
|
| 68 |
+
Screening History
|
| 69 |
+
</div>
|
| 70 |
+
<div className="flex items-center gap-4">
|
| 71 |
+
{history.length > 0 && (
|
| 72 |
+
<button
|
| 73 |
+
onClick={clearHistory}
|
| 74 |
+
className="text-error hover:opacity-80 transition-opacity font-caption-sm text-caption-sm flex items-center gap-1"
|
| 75 |
+
>
|
| 76 |
+
<span className="material-symbols-outlined text-[18px]">delete</span>
|
| 77 |
+
Clear
|
| 78 |
+
</button>
|
| 79 |
+
)}
|
| 80 |
+
<Link href="/" className="px-4 py-2 bg-surface-container-high hover:bg-surface-container text-on-surface rounded font-caption-sm text-caption-sm transition-colors border border-outline-variant flex items-center gap-1">
|
| 81 |
+
Back to Home
|
| 82 |
+
</Link>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
</nav>
|
| 86 |
+
|
| 87 |
+
{/* Main Content */}
|
| 88 |
+
<main className="flex-grow px-gutter py-section-padding max-w-container-max mx-auto w-full">
|
| 89 |
+
{!loaded ? (
|
| 90 |
+
/* Loading skeleton */
|
| 91 |
+
<div className="flex justify-center items-center py-24">
|
| 92 |
+
<div className="w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin" />
|
| 93 |
+
</div>
|
| 94 |
+
) : history.length === 0 ? (
|
| 95 |
+
/* Empty State */
|
| 96 |
+
<div className="flex flex-col items-center justify-center py-24 text-center" style={{ animation: "fadeSlideIn 0.5s ease-out" }}>
|
| 97 |
+
<span className="material-symbols-outlined text-outline-variant text-[64px] mb-4" data-icon="history">history</span>
|
| 98 |
+
<h2 className="font-section-heading text-section-heading text-on-surface mb-2">No History Yet</h2>
|
| 99 |
+
<p className="text-on-surface-variant mb-6 max-w-md">
|
| 100 |
+
Complete a screening and save your results to see them here. Your history is stored locally on this device.
|
| 101 |
+
</p>
|
| 102 |
+
<Link href="/chat" className="bg-primary-container text-on-primary px-5 py-3 rounded hover:opacity-90 transition-opacity active:scale-95">
|
| 103 |
+
Start Screening
|
| 104 |
+
</Link>
|
| 105 |
+
</div>
|
| 106 |
+
) : (
|
| 107 |
+
/* History Table */
|
| 108 |
+
<div className="bg-surface-container-lowest border border-outline-variant rounded-lg overflow-hidden" style={{ animation: "fadeSlideIn 0.5s ease-out" }}>
|
| 109 |
+
<div className="overflow-x-auto">
|
| 110 |
+
<table className="w-full text-left border-collapse">
|
| 111 |
+
<thead>
|
| 112 |
+
<tr className="border-b border-outline-variant bg-surface-container-low font-label-uppercase text-label-uppercase text-secondary">
|
| 113 |
+
<th className="py-4 px-6 font-semibold">#</th>
|
| 114 |
+
<th className="py-4 px-6 font-semibold">Date</th>
|
| 115 |
+
<th className="py-4 px-6 font-semibold">Score</th>
|
| 116 |
+
<th className="py-4 px-6 font-semibold">Category</th>
|
| 117 |
+
<th className="py-4 px-6 font-semibold">Method</th>
|
| 118 |
+
<th className="py-4 px-6 font-semibold text-right">Action</th>
|
| 119 |
+
</tr>
|
| 120 |
+
</thead>
|
| 121 |
+
<tbody className="font-body-md text-body-md text-on-surface">
|
| 122 |
+
{history.map((item, i) => {
|
| 123 |
+
const badgeStyle = SEVERITY_BADGE_STYLES[item.severity.label] || SEVERITY_BADGE_STYLES.Moderate;
|
| 124 |
+
return (
|
| 125 |
+
<tr
|
| 126 |
+
key={i}
|
| 127 |
+
className="border-b border-outline-variant hover:bg-surface-container-low transition-colors"
|
| 128 |
+
style={{ animation: `fadeSlideIn 0.4s ease-out ${i * 50}ms both` }}
|
| 129 |
+
>
|
| 130 |
+
<td className="py-4 px-6 text-on-surface-variant">{i + 1}</td>
|
| 131 |
+
<td className="py-4 px-6">
|
| 132 |
+
{new Date(item.date).toLocaleDateString("en-US", {
|
| 133 |
+
day: "numeric",
|
| 134 |
+
month: "short",
|
| 135 |
+
year: "numeric",
|
| 136 |
+
})}
|
| 137 |
+
</td>
|
| 138 |
+
<td className="py-4 px-6 font-medium">{Math.round(item.total_score)}</td>
|
| 139 |
+
<td className="py-4 px-6">
|
| 140 |
+
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium border ${badgeStyle}`}>
|
| 141 |
+
{item.severity.label}
|
| 142 |
+
</span>
|
| 143 |
+
</td>
|
| 144 |
+
<td className="py-4 px-6">
|
| 145 |
+
<span className={`text-xs ${item.fallback ? "text-[#F57C00]" : "text-primary"}`}>
|
| 146 |
+
{item.fallback ? "Keyword" : "AI Model"}
|
| 147 |
+
</span>
|
| 148 |
+
</td>
|
| 149 |
+
<td className="py-4 px-6 text-right">
|
| 150 |
+
<Link
|
| 151 |
+
className="text-primary hover:text-primary-container font-medium flex items-center justify-end gap-1"
|
| 152 |
+
href={`/result?id=${i}`}
|
| 153 |
+
>
|
| 154 |
+
Detail <span className="material-symbols-outlined text-[18px]">chevron_right</span>
|
| 155 |
+
</Link>
|
| 156 |
+
</td>
|
| 157 |
+
</tr>
|
| 158 |
+
);
|
| 159 |
+
})}
|
| 160 |
+
</tbody>
|
| 161 |
+
</table>
|
| 162 |
+
</div>
|
| 163 |
+
{/* Summary Footer */}
|
| 164 |
+
<div className="border-t border-outline-variant bg-surface-container-lowest px-6 py-4 flex items-center justify-between">
|
| 165 |
+
<div className="font-caption-sm text-caption-sm text-secondary">
|
| 166 |
+
{history.length} screening{history.length !== 1 ? "s" : ""} saved
|
| 167 |
+
</div>
|
| 168 |
+
<Link href="/chat" className="text-primary font-caption-sm text-caption-sm hover:underline flex items-center gap-1">
|
| 169 |
+
New Screening <span className="material-symbols-outlined text-[16px]">add</span>
|
| 170 |
+
</Link>
|
| 171 |
+
</div>
|
| 172 |
+
</div>
|
| 173 |
+
)}
|
| 174 |
+
</main>
|
| 175 |
+
|
| 176 |
+
{/* Footer */}
|
| 177 |
+
<footer className="bg-surface-container-lowest dark:bg-background w-full py-section-padding border-t border-outline-variant mt-auto">
|
| 178 |
+
<div className="flex flex-col items-center text-center px-gutter max-w-container-max mx-auto">
|
| 179 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant max-w-2xl">
|
| 180 |
+
MindCheck is not a substitute for professional medical diagnosis. Please contact a mental health professional if you are in an emergency.
|
| 181 |
+
</p>
|
| 182 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant mt-2">© 2023 MindCheck. All rights reserved.</p>
|
| 183 |
+
</div>
|
| 184 |
+
</footer>
|
| 185 |
+
|
| 186 |
+
<style jsx global>{`
|
| 187 |
+
@keyframes fadeSlideIn {
|
| 188 |
+
from {
|
| 189 |
+
opacity: 0;
|
| 190 |
+
transform: translateY(16px);
|
| 191 |
+
}
|
| 192 |
+
to {
|
| 193 |
+
opacity: 1;
|
| 194 |
+
transform: translateY(0);
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
`}</style>
|
| 198 |
+
</>
|
| 199 |
+
);
|
| 200 |
+
}
|
mindcheck-web/src/app/layout.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
import { Inter } from "next/font/google";
|
| 3 |
+
import "./globals.css";
|
| 4 |
+
|
| 5 |
+
const inter = Inter({ subsets: ["latin"] });
|
| 6 |
+
|
| 7 |
+
export const metadata: Metadata = {
|
| 8 |
+
title: "MindCheck",
|
| 9 |
+
description: "Understand your mental health",
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function RootLayout({
|
| 13 |
+
children,
|
| 14 |
+
}: Readonly<{
|
| 15 |
+
children: React.ReactNode;
|
| 16 |
+
}>) {
|
| 17 |
+
return (
|
| 18 |
+
<html lang="en">
|
| 19 |
+
<head>
|
| 20 |
+
<link
|
| 21 |
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL,GRAD,opsz@100..700,0..1,-50..200,20..48&display=swap"
|
| 22 |
+
rel="stylesheet"
|
| 23 |
+
/>
|
| 24 |
+
</head>
|
| 25 |
+
<body className={`${inter.className} min-h-screen flex flex-col font-body-md text-body-md`}>
|
| 26 |
+
{children}
|
| 27 |
+
</body>
|
| 28 |
+
</html>
|
| 29 |
+
);
|
| 30 |
+
}
|
mindcheck-web/src/app/page.tsx
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Link from "next/link";
|
| 2 |
+
|
| 3 |
+
export default function Home() {
|
| 4 |
+
return (
|
| 5 |
+
<>
|
| 6 |
+
{/* TopNavBar */}
|
| 7 |
+
<nav className="w-full top-0 sticky bg-surface dark:bg-on-background border-b border-outline-variant z-50">
|
| 8 |
+
<div className="flex justify-between items-center h-16 px-gutter max-w-container-max mx-auto">
|
| 9 |
+
<div className="flex items-center gap-2">
|
| 10 |
+
<span className="material-symbols-outlined text-primary font-bold text-2xl" data-icon="psychology">psychology</span>
|
| 11 |
+
<span className="font-hero-lg text-hero-lg font-bold text-primary dark:text-inverse-primary">MindCheck</span>
|
| 12 |
+
</div>
|
| 13 |
+
<div className="hidden md:flex gap-8">
|
| 14 |
+
<a className="font-body-md text-body-md text-on-surface-variant hover:text-primary transition-colors" href="#how-it-works">How it works</a>
|
| 15 |
+
<Link className="font-body-md text-body-md text-on-surface-variant hover:text-primary transition-colors" href="/history">History</Link>
|
| 16 |
+
</div>
|
| 17 |
+
<Link href="/chat" className="font-body-md text-body-md bg-primary-container text-on-primary px-5 py-3 rounded active:scale-95 duration-150 hover:opacity-90">
|
| 18 |
+
Start Screening
|
| 19 |
+
</Link>
|
| 20 |
+
</div>
|
| 21 |
+
</nav>
|
| 22 |
+
|
| 23 |
+
{/* Main Content */}
|
| 24 |
+
<main className="flex-grow flex flex-col items-center w-full max-w-container-max mx-auto px-gutter py-section-padding gap-stack-lg mt-8 md:mt-16">
|
| 25 |
+
{/* Hero Section */}
|
| 26 |
+
<section className="w-full grid grid-cols-1 md:grid-cols-12 gap-8 items-center">
|
| 27 |
+
{/* Left: Content (60%) */}
|
| 28 |
+
<div className="md:col-span-7 flex flex-col gap-stack-md">
|
| 29 |
+
<h1 className="font-hero-lg-mobile md:font-hero-lg text-hero-lg-mobile md:text-hero-lg text-on-surface">
|
| 30 |
+
Understand your mental health in 5 minutes
|
| 31 |
+
</h1>
|
| 32 |
+
<p className="font-body-md text-body-md text-on-surface-variant max-w-lg">
|
| 33 |
+
8 short PHQ-8 based questions. Anonymous, free, and does not replace professional diagnosis.
|
| 34 |
+
</p>
|
| 35 |
+
<div className="flex items-center gap-4 mt-4">
|
| 36 |
+
<Link href="/chat" className="font-body-md text-body-md bg-primary-container text-on-primary px-5 py-3 rounded active:scale-95 duration-150 hover:opacity-90">
|
| 37 |
+
Start Screening
|
| 38 |
+
</Link>
|
| 39 |
+
<a className="font-body-md text-body-md text-primary font-medium hover:underline flex items-center gap-1" href="#how-it-works">
|
| 40 |
+
How it works <span className="material-symbols-outlined text-sm" data-icon="arrow_forward">arrow_forward</span>
|
| 41 |
+
</a>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
{/* Right: Abstract Decorative Block (40%) */}
|
| 46 |
+
<div className="md:col-span-5 relative h-64 md:h-80 w-full flex justify-center items-center">
|
| 47 |
+
{/* Stacked Cards */}
|
| 48 |
+
<div className="absolute bg-surface w-4/5 h-48 border border-outline-variant rounded-lg rotate-6 opacity-60"></div>
|
| 49 |
+
<div className="absolute bg-surface w-4/5 h-48 border border-outline-variant rounded-lg -rotate-3 opacity-80"></div>
|
| 50 |
+
{/* Main Foreground Card */}
|
| 51 |
+
<div className="relative bg-surface w-4/5 h-48 border border-outline-variant rounded-lg p-6 flex flex-col justify-center items-center shadow-sm">
|
| 52 |
+
<span className="font-label-uppercase text-label-uppercase text-secondary mb-2">PHQ-8 SCORE</span>
|
| 53 |
+
<span className="text-5xl font-bold text-primary mb-4">14</span>
|
| 54 |
+
{/* Fake Bar Chart Snippet */}
|
| 55 |
+
<div className="w-full flex gap-2 h-10 items-end px-4">
|
| 56 |
+
<div className="w-1/4 bg-surface-variant h-1/2 rounded-t"></div>
|
| 57 |
+
<div className="w-1/4 bg-primary-fixed-dim h-3/4 rounded-t"></div>
|
| 58 |
+
<div className="w-1/4 bg-primary-container h-full rounded-t"></div>
|
| 59 |
+
<div className="w-1/4 bg-surface-variant h-1/4 rounded-t"></div>
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
</section>
|
| 64 |
+
|
| 65 |
+
{/* Feature Cards Row */}
|
| 66 |
+
<section id="how-it-works" className="w-full grid grid-cols-1 md:grid-cols-3 gap-6 mt-12 scroll-mt-24">
|
| 67 |
+
<div className="bg-surface border-[0.5px] border-outline-variant rounded-lg p-6 flex flex-col gap-2 hover:shadow-md transition-shadow duration-300">
|
| 68 |
+
<span className="material-symbols-outlined text-primary mb-2 text-[24px]" data-icon="visibility_off" style={{ fontVariationSettings: "'FILL' 0, 'wght' 300" }}>visibility_off</span>
|
| 69 |
+
<h3 className="font-section-heading text-section-heading text-on-surface">Anonymous & Free</h3>
|
| 70 |
+
<p className="font-body-md text-body-md text-on-surface-variant">Data is not stored permanently. All processing happens locally.</p>
|
| 71 |
+
</div>
|
| 72 |
+
<div className="bg-surface border-[0.5px] border-outline-variant rounded-lg p-6 flex flex-col gap-2 hover:shadow-md transition-shadow duration-300">
|
| 73 |
+
<span className="material-symbols-outlined text-primary mb-2 text-[24px]" data-icon="assignment" style={{ fontVariationSettings: "'FILL' 0, 'wght' 300" }}>assignment</span>
|
| 74 |
+
<h3 className="font-section-heading text-section-heading text-on-surface">PHQ-8 Based</h3>
|
| 75 |
+
<p className="font-body-md text-body-md text-on-surface-variant">Validated global medical questionnaire standard used by professionals.</p>
|
| 76 |
+
</div>
|
| 77 |
+
<div className="bg-surface border-[0.5px] border-outline-variant rounded-lg p-6 flex flex-col gap-2 hover:shadow-md transition-shadow duration-300">
|
| 78 |
+
<span className="material-symbols-outlined text-primary mb-2 text-[24px]" data-icon="bolt" style={{ fontVariationSettings: "'FILL' 0, 'wght' 300" }}>bolt</span>
|
| 79 |
+
<h3 className="font-section-heading text-section-heading text-on-surface">Instant Results</h3>
|
| 80 |
+
<p className="font-body-md text-body-md text-on-surface-variant">Get an immediate summary with AI-powered analysis of your responses.</p>
|
| 81 |
+
</div>
|
| 82 |
+
</section>
|
| 83 |
+
|
| 84 |
+
{/* PHQ-8 Educational Section */}
|
| 85 |
+
<section id="about-phq8" className="w-full mt-16 scroll-mt-24">
|
| 86 |
+
<div className="bg-surface-container-low border border-outline-variant rounded-2xl p-8 md:p-12 shadow-sm">
|
| 87 |
+
<div className="flex flex-col md:flex-row gap-12 items-center">
|
| 88 |
+
<div className="flex-1 flex flex-col gap-4">
|
| 89 |
+
<div className="inline-flex items-center gap-2 px-3 py-1 bg-primary-container text-on-primary-container rounded-full w-max mb-2">
|
| 90 |
+
<span className="material-symbols-outlined text-sm" data-icon="school">school</span>
|
| 91 |
+
<span className="font-label-uppercase text-label-uppercase font-bold">Clinical Standard</span>
|
| 92 |
+
</div>
|
| 93 |
+
<h2 className="font-hero-lg-mobile md:font-hero-lg text-hero-lg-mobile md:text-hero-lg text-on-surface font-semibold">
|
| 94 |
+
What is the PHQ-8?
|
| 95 |
+
</h2>
|
| 96 |
+
<p className="font-body-md text-body-md text-on-surface-variant leading-relaxed">
|
| 97 |
+
The <strong>Patient Health Questionnaire (PHQ-8)</strong> is a standardized diagnostic tool used by healthcare professionals worldwide to screen for and measure the severity of depression. It consists of 8 carefully formulated questions based on the DSM-5 criteria for major depressive disorder.
|
| 98 |
+
</p>
|
| 99 |
+
|
| 100 |
+
<h3 className="font-section-heading text-section-heading mt-4 font-semibold text-on-surface">Severity Categories</h3>
|
| 101 |
+
<ul className="space-y-3 font-body-md text-body-md text-on-surface-variant">
|
| 102 |
+
<li className="flex items-start gap-3">
|
| 103 |
+
<span className="w-3 h-3 rounded-full bg-green-500 mt-1.5 shrink-0"></span>
|
| 104 |
+
<div><strong>0-4: Minimal</strong> — No specific treatment typically needed. Normal emotional fluctuations.</div>
|
| 105 |
+
</li>
|
| 106 |
+
<li className="flex items-start gap-3">
|
| 107 |
+
<span className="w-3 h-3 rounded-full bg-amber-500 mt-1.5 shrink-0"></span>
|
| 108 |
+
<div><strong>5-9: Mild</strong> — Watchful waiting recommended. Mild symptoms that may not significantly impact daily life.</div>
|
| 109 |
+
</li>
|
| 110 |
+
<li className="flex items-start gap-3">
|
| 111 |
+
<span className="w-3 h-3 rounded-full bg-orange-500 mt-1.5 shrink-0"></span>
|
| 112 |
+
<div><strong>10-14: Moderate</strong> — Treatment plan and consultation with a mental health professional is recommended.</div>
|
| 113 |
+
</li>
|
| 114 |
+
<li className="flex items-start gap-3">
|
| 115 |
+
<span className="w-3 h-3 rounded-full bg-red-400 mt-1.5 shrink-0"></span>
|
| 116 |
+
<div><strong>15-19: Moderately Severe</strong> — Active treatment with pharmacotherapy and/or psychotherapy is highly recommended.</div>
|
| 117 |
+
</li>
|
| 118 |
+
<li className="flex items-start gap-3">
|
| 119 |
+
<span className="w-3 h-3 rounded-full bg-red-600 mt-1.5 shrink-0"></span>
|
| 120 |
+
<div><strong>20-24: Severe</strong> — Immediate initiation of treatment and referral to a specialist is strongly advised.</div>
|
| 121 |
+
</li>
|
| 122 |
+
</ul>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<div className="flex-1 w-full max-w-lg aspect-video rounded-xl overflow-hidden shadow-lg border border-outline-variant bg-black">
|
| 126 |
+
<iframe
|
| 127 |
+
width="100%"
|
| 128 |
+
height="100%"
|
| 129 |
+
src="https://www.youtube.com/embed/8Su5VtKeXU8"
|
| 130 |
+
title="What is depression? - Helen M. Farrell"
|
| 131 |
+
frameBorder="0"
|
| 132 |
+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
| 133 |
+
allowFullScreen
|
| 134 |
+
></iframe>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
+
</section>
|
| 139 |
+
|
| 140 |
+
{/* How It Works Steps */}
|
| 141 |
+
<section className="w-full mt-12">
|
| 142 |
+
<h2 className="font-section-heading text-section-heading text-on-surface mb-8 text-center">How It Works</h2>
|
| 143 |
+
<div className="grid grid-cols-1 md:grid-cols-4 gap-6">
|
| 144 |
+
{[
|
| 145 |
+
{ icon: "chat_bubble", title: "Answer 8 Questions", desc: "Our chatbot asks 8 PHQ-8 interview questions — answer via quick chips or type freely." },
|
| 146 |
+
{ icon: "psychology", title: "AI Analysis", desc: "Your responses are analyzed using a trained MPNet deep learning model from DAIC-WOZ research." },
|
| 147 |
+
{ icon: "analytics", title: "Get Your Score", desc: "Receive per-question scores (0-3), total PHQ-8 score, and severity classification." },
|
| 148 |
+
{ icon: "history", title: "Track Progress", desc: "Save results to your local history and track your mental health over time." },
|
| 149 |
+
].map((step, i) => (
|
| 150 |
+
<div key={i} className="flex flex-col items-center text-center gap-3 p-4">
|
| 151 |
+
<div className="w-12 h-12 rounded-full bg-primary-container flex items-center justify-center mb-2">
|
| 152 |
+
<span className="material-symbols-outlined text-on-primary text-[22px]" data-icon={step.icon}>{step.icon}</span>
|
| 153 |
+
</div>
|
| 154 |
+
<span className="font-label-uppercase text-label-uppercase text-secondary">Step {i + 1}</span>
|
| 155 |
+
<h3 className="font-body-md text-body-md font-semibold text-on-surface">{step.title}</h3>
|
| 156 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant">{step.desc}</p>
|
| 157 |
+
</div>
|
| 158 |
+
))}
|
| 159 |
+
</div>
|
| 160 |
+
</section>
|
| 161 |
+
</main>
|
| 162 |
+
|
| 163 |
+
{/* Footer */}
|
| 164 |
+
<footer className="w-full py-section-padding border-t border-outline-variant bg-surface-container-lowest dark:bg-background mt-auto">
|
| 165 |
+
<div className="flex flex-col items-center text-center px-gutter max-w-container-max mx-auto gap-4">
|
| 166 |
+
<span className="material-symbols-outlined text-primary text-[24px]" data-icon="favorite" style={{ fontVariationSettings: "'FILL' 1" }}>favorite</span>
|
| 167 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant max-w-2xl">
|
| 168 |
+
MindCheck is not a replacement for professional medical diagnosis. Please contact mental health professionals if you are in an emergency.
|
| 169 |
+
</p>
|
| 170 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant opacity-60">© 2023 MindCheck. All rights reserved.</p>
|
| 171 |
+
</div>
|
| 172 |
+
</footer>
|
| 173 |
+
</>
|
| 174 |
+
);
|
| 175 |
+
}
|
mindcheck-web/src/app/result/page.tsx
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import Link from "next/link";
|
| 4 |
+
import { Suspense, useEffect, useState } from "react";
|
| 5 |
+
import { useSearchParams } from "next/navigation";
|
| 6 |
+
|
| 7 |
+
type SeverityInfo = {
|
| 8 |
+
label: string;
|
| 9 |
+
color: string;
|
| 10 |
+
description: string;
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
type ResultData = {
|
| 14 |
+
scores: number[];
|
| 15 |
+
total_score: number;
|
| 16 |
+
severity: SeverityInfo;
|
| 17 |
+
filler_count: number;
|
| 18 |
+
negative_words: string[];
|
| 19 |
+
positive_words: string[];
|
| 20 |
+
item_names: string[];
|
| 21 |
+
answers: string[];
|
| 22 |
+
questions: string[];
|
| 23 |
+
itemShortNames: string[];
|
| 24 |
+
date: string;
|
| 25 |
+
fallback?: boolean;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
const SEVERITY_STYLES: Record<string, { bg: string; text: string; border: string }> = {
|
| 29 |
+
Minimal: { bg: "bg-green-50", text: "text-green-700", border: "border-green-200" },
|
| 30 |
+
Mild: { bg: "bg-amber-50", text: "text-amber-700", border: "border-amber-200" },
|
| 31 |
+
Moderate: { bg: "bg-orange-50", text: "text-orange-700", border: "border-orange-200" },
|
| 32 |
+
"Moderately Severe": { bg: "bg-red-50", text: "text-red-600", border: "border-red-200" },
|
| 33 |
+
Severe: { bg: "bg-red-100", text: "text-red-800", border: "border-red-300" },
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
const BAR_COLORS = [
|
| 37 |
+
"bg-primary",
|
| 38 |
+
"bg-primary-container",
|
| 39 |
+
"bg-[#F57C00]",
|
| 40 |
+
"bg-error",
|
| 41 |
+
];
|
| 42 |
+
|
| 43 |
+
function getBarColor(score: number): string {
|
| 44 |
+
const idx = Math.min(Math.round(score), 3);
|
| 45 |
+
return BAR_COLORS[idx];
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const SHORT_NAMES = [
|
| 49 |
+
"Loss of Interest",
|
| 50 |
+
"Feeling Depressed",
|
| 51 |
+
"Sleep Issues",
|
| 52 |
+
"Fatigue",
|
| 53 |
+
"Appetite Changes",
|
| 54 |
+
"Self-Criticism",
|
| 55 |
+
"Concentration",
|
| 56 |
+
"Psychomotor",
|
| 57 |
+
];
|
| 58 |
+
|
| 59 |
+
function ResultContent() {
|
| 60 |
+
const searchParams = useSearchParams();
|
| 61 |
+
const [result, setResult] = useState<ResultData | null>(null);
|
| 62 |
+
|
| 63 |
+
useEffect(() => {
|
| 64 |
+
const historyId = searchParams.get("id");
|
| 65 |
+
|
| 66 |
+
if (historyId !== null) {
|
| 67 |
+
/* Load from history */
|
| 68 |
+
const historyRaw = localStorage.getItem("mindcheck_history");
|
| 69 |
+
if (historyRaw) {
|
| 70 |
+
try {
|
| 71 |
+
const history = JSON.parse(historyRaw) as ResultData[];
|
| 72 |
+
const idx = parseInt(historyId, 10);
|
| 73 |
+
if (history[idx]) setResult(history[idx]);
|
| 74 |
+
} catch { /* ignore */ }
|
| 75 |
+
}
|
| 76 |
+
} else {
|
| 77 |
+
/* Load latest result */
|
| 78 |
+
const raw = localStorage.getItem("mindcheck_latest_result");
|
| 79 |
+
if (raw) {
|
| 80 |
+
try {
|
| 81 |
+
setResult(JSON.parse(raw));
|
| 82 |
+
} catch { /* ignore */ }
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}, [searchParams]);
|
| 86 |
+
|
| 87 |
+
const handleSave = () => {
|
| 88 |
+
if (!result) return;
|
| 89 |
+
const historyRaw = localStorage.getItem("mindcheck_history");
|
| 90 |
+
const history: ResultData[] = historyRaw ? JSON.parse(historyRaw) : [];
|
| 91 |
+
history.unshift(result);
|
| 92 |
+
localStorage.setItem("mindcheck_history", JSON.stringify(history));
|
| 93 |
+
alert("Results saved to history!");
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
if (!result) {
|
| 97 |
+
return (
|
| 98 |
+
<>
|
| 99 |
+
<header className="bg-surface border-b border-outline-variant w-full top-0 sticky z-50">
|
| 100 |
+
<div className="flex justify-between items-center h-16 px-gutter max-w-container-max mx-auto">
|
| 101 |
+
<Link href="/" className="font-hero-lg text-hero-lg font-bold text-primary">MindCheck</Link>
|
| 102 |
+
<div className="font-section-heading text-section-heading hidden md:block">Screening Results</div>
|
| 103 |
+
<Link href="/chat" className="px-[20px] py-[12px] bg-transparent border border-primary text-primary rounded hover:bg-surface-container transition-colors">
|
| 104 |
+
Start Screening
|
| 105 |
+
</Link>
|
| 106 |
+
</div>
|
| 107 |
+
</header>
|
| 108 |
+
<main className="flex-grow flex flex-col items-center justify-center px-gutter py-section-padding max-w-container-max mx-auto w-full">
|
| 109 |
+
<span className="material-symbols-outlined text-outline-variant text-[64px] mb-4" data-icon="assignment_late">assignment_late</span>
|
| 110 |
+
<h1 className="font-section-heading text-section-heading text-on-surface mb-2">No Results Available</h1>
|
| 111 |
+
<p className="text-on-surface-variant mb-6">Complete a screening first to see your results.</p>
|
| 112 |
+
<Link href="/chat" className="bg-primary-container text-on-primary px-5 py-3 rounded hover:opacity-90 transition-opacity">
|
| 113 |
+
Start Screening
|
| 114 |
+
</Link>
|
| 115 |
+
</main>
|
| 116 |
+
</>
|
| 117 |
+
);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
const sevStyle = SEVERITY_STYLES[result.severity.label] || SEVERITY_STYLES.Moderate;
|
| 121 |
+
const maxScore = 24;
|
| 122 |
+
|
| 123 |
+
return (
|
| 124 |
+
<>
|
| 125 |
+
{/* TopNavBar */}
|
| 126 |
+
<header className="bg-surface border-b border-outline-variant w-full top-0 sticky z-50">
|
| 127 |
+
<div className="flex justify-between items-center h-16 px-gutter max-w-container-max mx-auto">
|
| 128 |
+
<Link href="/" className="font-hero-lg text-hero-lg font-bold text-primary">MindCheck</Link>
|
| 129 |
+
<div className="font-section-heading text-section-heading hidden md:block">Screening Results</div>
|
| 130 |
+
<Link href="/chat" className="px-[20px] py-[12px] bg-transparent border border-primary text-primary rounded hover:bg-surface-container transition-colors">
|
| 131 |
+
Restart Screening
|
| 132 |
+
</Link>
|
| 133 |
+
</div>
|
| 134 |
+
</header>
|
| 135 |
+
|
| 136 |
+
{/* Main Content */}
|
| 137 |
+
<main className="flex-grow w-full max-w-container-max mx-auto px-gutter py-section-padding">
|
| 138 |
+
<div className="grid grid-cols-1 md:grid-cols-12 gap-gutter">
|
| 139 |
+
{/* Left Column: Core Results */}
|
| 140 |
+
<div className="md:col-span-7 flex flex-col gap-stack-lg">
|
| 141 |
+
{/* Score Section */}
|
| 142 |
+
<section className="flex flex-col gap-stack-md" style={{ animation: "fadeSlideIn 0.5s ease-out" }}>
|
| 143 |
+
<h1 className="font-section-heading text-section-heading text-on-surface">Your Result</h1>
|
| 144 |
+
<div className="flex items-center gap-4 mt-2">
|
| 145 |
+
<div className="flex items-baseline">
|
| 146 |
+
<span className="text-[56px] font-bold text-primary leading-none tracking-tight">
|
| 147 |
+
{Math.round(result.total_score)}
|
| 148 |
+
</span>
|
| 149 |
+
<span className="text-2xl text-on-surface-variant ml-1 font-medium">/{maxScore}</span>
|
| 150 |
+
</div>
|
| 151 |
+
<div className={`px-4 py-1.5 rounded-[20px] font-caption-sm text-caption-sm border-[0.5px] ${sevStyle.bg} ${sevStyle.text} ${sevStyle.border}`}>
|
| 152 |
+
{result.severity.label}
|
| 153 |
+
</div>
|
| 154 |
+
</div>
|
| 155 |
+
<p className="text-on-surface-variant max-w-md">{result.severity.description}</p>
|
| 156 |
+
{result.fallback && (
|
| 157 |
+
<div className="flex items-center gap-2 text-[#F57C00] bg-orange-50 border border-orange-200 rounded p-3 mt-2">
|
| 158 |
+
<span className="material-symbols-outlined text-[18px]" data-icon="warning">warning</span>
|
| 159 |
+
<span className="font-caption-sm text-caption-sm">Scored using keyword matching (model server unavailable)</span>
|
| 160 |
+
</div>
|
| 161 |
+
)}
|
| 162 |
+
<p className="text-on-surface-variant text-xs opacity-60">
|
| 163 |
+
Screened on {new Date(result.date).toLocaleDateString("en-US", { day: "numeric", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit" })}
|
| 164 |
+
</p>
|
| 165 |
+
</section>
|
| 166 |
+
|
| 167 |
+
{/* Bar Chart Section */}
|
| 168 |
+
<section
|
| 169 |
+
className="bg-surface-lowest border-[0.5px] border-outline-variant rounded-lg p-section-padding bg-white"
|
| 170 |
+
style={{ animation: "fadeSlideIn 0.6s ease-out 0.1s both" }}
|
| 171 |
+
>
|
| 172 |
+
<h2 className="font-body-md text-body-md font-semibold mb-6">Score per question</h2>
|
| 173 |
+
<div className="flex flex-col gap-4">
|
| 174 |
+
{result.scores.map((score, i) => {
|
| 175 |
+
const name = result.itemShortNames?.[i] || SHORT_NAMES[i] || `Q${i + 1}`;
|
| 176 |
+
const pct = Math.min((score / 3) * 100, 100);
|
| 177 |
+
return (
|
| 178 |
+
<div key={i} className="flex items-center gap-4 group">
|
| 179 |
+
<div className="w-[140px] truncate text-on-surface-variant text-sm" title={name}>
|
| 180 |
+
{name}
|
| 181 |
+
</div>
|
| 182 |
+
<div className="flex-grow h-2.5 bg-surface-container rounded-full overflow-hidden flex">
|
| 183 |
+
<div
|
| 184 |
+
className={`h-full rounded-full transition-all duration-1000 ease-out ${getBarColor(score)}`}
|
| 185 |
+
style={{ width: `${pct}%`, transitionDelay: `${i * 80}ms` }}
|
| 186 |
+
/>
|
| 187 |
+
</div>
|
| 188 |
+
<div className={`w-6 text-right font-medium ${score === 0 ? "text-outline" : ""}`}>
|
| 189 |
+
{score.toFixed(1)}
|
| 190 |
+
</div>
|
| 191 |
+
</div>
|
| 192 |
+
);
|
| 193 |
+
})}
|
| 194 |
+
</div>
|
| 195 |
+
</section>
|
| 196 |
+
|
| 197 |
+
{/* Disclaimer */}
|
| 198 |
+
<div className="bg-surface-container-low border-[0.5px] border-outline-variant rounded-lg p-4 flex gap-4 items-start">
|
| 199 |
+
<span className="material-symbols-outlined text-primary mt-0.5" data-icon="info">info</span>
|
| 200 |
+
<p className="font-caption-sm text-caption-sm text-on-surface-variant">
|
| 201 |
+
MindCheck is not a replacement for professional medical diagnosis. Please contact mental health professionals if you are in an emergency.
|
| 202 |
+
</p>
|
| 203 |
+
</div>
|
| 204 |
+
</div>
|
| 205 |
+
|
| 206 |
+
{/* Right Column: Metrics & Actions */}
|
| 207 |
+
<div className="md:col-span-5 flex flex-col gap-stack-lg mt-8 md:mt-0">
|
| 208 |
+
{/* 2x2 Metric Grid */}
|
| 209 |
+
<div
|
| 210 |
+
className="grid grid-cols-2 gap-4"
|
| 211 |
+
style={{ animation: "fadeSlideIn 0.5s ease-out 0.2s both" }}
|
| 212 |
+
>
|
| 213 |
+
<div className="bg-white border-[0.5px] border-outline-variant rounded-lg p-4 flex flex-col gap-2 hover:shadow-sm transition-shadow">
|
| 214 |
+
<span className="font-caption-sm text-caption-sm text-on-surface-variant">Total Score</span>
|
| 215 |
+
<span className="font-section-heading text-section-heading text-on-surface">{Math.round(result.total_score)}</span>
|
| 216 |
+
</div>
|
| 217 |
+
<div className="bg-white border-[0.5px] border-outline-variant rounded-lg p-4 flex flex-col gap-2 hover:shadow-sm transition-shadow">
|
| 218 |
+
<span className="font-caption-sm text-caption-sm text-on-surface-variant">Category</span>
|
| 219 |
+
<span className={`font-section-heading text-section-heading ${sevStyle.text}`}>{result.severity.label}</span>
|
| 220 |
+
</div>
|
| 221 |
+
<div className="bg-white border-[0.5px] border-outline-variant rounded-lg p-4 flex flex-col gap-2 hover:shadow-sm transition-shadow">
|
| 222 |
+
<span className="font-caption-sm text-caption-sm text-on-surface-variant">Negative Words</span>
|
| 223 |
+
<span className="font-section-heading text-section-heading text-on-surface">{result.negative_words.length}</span>
|
| 224 |
+
{result.negative_words.length > 0 && (
|
| 225 |
+
<div className="flex flex-wrap gap-1 mt-1">
|
| 226 |
+
{result.negative_words.slice(0, 5).map((w) => (
|
| 227 |
+
<span key={w} className="text-[10px] px-1.5 py-0.5 bg-red-50 text-red-600 rounded border border-red-100">{w}</span>
|
| 228 |
+
))}
|
| 229 |
+
{result.negative_words.length > 5 && (
|
| 230 |
+
<span className="text-[10px] px-1.5 py-0.5 text-on-surface-variant">+{result.negative_words.length - 5} more</span>
|
| 231 |
+
)}
|
| 232 |
+
</div>
|
| 233 |
+
)}
|
| 234 |
+
</div>
|
| 235 |
+
<div className="bg-white border-[0.5px] border-outline-variant rounded-lg p-4 flex flex-col gap-2 hover:shadow-sm transition-shadow">
|
| 236 |
+
<span className="font-caption-sm text-caption-sm text-on-surface-variant">Filler Words</span>
|
| 237 |
+
<span className="font-section-heading text-section-heading text-on-surface">{result.filler_count}</span>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
|
| 241 |
+
{/* Recommendation Card */}
|
| 242 |
+
<div
|
| 243 |
+
className="bg-white border-[0.5px] border-outline-variant border-l-4 border-l-primary rounded-lg p-section-padding flex flex-col gap-stack-sm"
|
| 244 |
+
style={{ animation: "fadeSlideIn 0.5s ease-out 0.3s both" }}
|
| 245 |
+
>
|
| 246 |
+
<h3 className="font-body-md text-body-md font-semibold">Recommended Next Steps</h3>
|
| 247 |
+
<p className="text-on-surface-variant font-caption-sm text-caption-sm">
|
| 248 |
+
{result.total_score <= 4
|
| 249 |
+
? "Your results suggest minimal symptoms. Continue monitoring your well-being and maintain healthy habits."
|
| 250 |
+
: result.total_score <= 9
|
| 251 |
+
? "Your results suggest mild symptoms. Consider speaking with a trusted friend or family member, and monitor your progress."
|
| 252 |
+
: result.total_score <= 14
|
| 253 |
+
? "Based on these results, we recommend scheduling a consultation with a mental health professional for further evaluation."
|
| 254 |
+
: "Based on these results, we strongly recommend seeking professional help immediately. Please contact a psychologist, psychiatrist, or your nearest mental health service."}
|
| 255 |
+
</p>
|
| 256 |
+
</div>
|
| 257 |
+
|
| 258 |
+
{/* Action Buttons */}
|
| 259 |
+
<div
|
| 260 |
+
className="flex flex-col sm:flex-row gap-4 mt-auto"
|
| 261 |
+
style={{ animation: "fadeSlideIn 0.5s ease-out 0.4s both" }}
|
| 262 |
+
>
|
| 263 |
+
<button
|
| 264 |
+
onClick={handleSave}
|
| 265 |
+
className="flex-1 px-[20px] py-[12px] bg-transparent border border-primary text-primary rounded hover:bg-surface-container transition-all duration-200 text-center justify-center flex items-center gap-2 active:scale-95"
|
| 266 |
+
>
|
| 267 |
+
<span className="material-symbols-outlined text-[20px]" data-icon="download">download</span>
|
| 268 |
+
Save Results
|
| 269 |
+
</button>
|
| 270 |
+
<Link href="/history" className="flex-1 px-[20px] py-[12px] bg-primary text-on-primary rounded hover:opacity-90 transition-all duration-200 text-center justify-center flex items-center active:scale-95">
|
| 271 |
+
View History
|
| 272 |
+
</Link>
|
| 273 |
+
</div>
|
| 274 |
+
</div>
|
| 275 |
+
</div>
|
| 276 |
+
</main>
|
| 277 |
+
|
| 278 |
+
<style jsx global>{`
|
| 279 |
+
@keyframes fadeSlideIn {
|
| 280 |
+
from {
|
| 281 |
+
opacity: 0;
|
| 282 |
+
transform: translateY(16px);
|
| 283 |
+
}
|
| 284 |
+
to {
|
| 285 |
+
opacity: 1;
|
| 286 |
+
transform: translateY(0);
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
`}</style>
|
| 290 |
+
</>
|
| 291 |
+
);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
export default function ResultPage() {
|
| 295 |
+
return (
|
| 296 |
+
<Suspense fallback={
|
| 297 |
+
<div className="flex-grow flex items-center justify-center">
|
| 298 |
+
<div className="w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin" />
|
| 299 |
+
</div>
|
| 300 |
+
}>
|
| 301 |
+
<ResultContent />
|
| 302 |
+
</Suspense>
|
| 303 |
+
);
|
| 304 |
+
}
|
mindcheck-web/tsconfig.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"target": "ES2017",
|
| 4 |
+
"lib": ["dom", "dom.iterable", "esnext"],
|
| 5 |
+
"allowJs": true,
|
| 6 |
+
"skipLibCheck": true,
|
| 7 |
+
"strict": true,
|
| 8 |
+
"noEmit": true,
|
| 9 |
+
"esModuleInterop": true,
|
| 10 |
+
"module": "esnext",
|
| 11 |
+
"moduleResolution": "bundler",
|
| 12 |
+
"resolveJsonModule": true,
|
| 13 |
+
"isolatedModules": true,
|
| 14 |
+
"jsx": "react-jsx",
|
| 15 |
+
"incremental": true,
|
| 16 |
+
"plugins": [
|
| 17 |
+
{
|
| 18 |
+
"name": "next"
|
| 19 |
+
}
|
| 20 |
+
],
|
| 21 |
+
"paths": {
|
| 22 |
+
"@/*": ["./src/*"]
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
"include": [
|
| 26 |
+
"next-env.d.ts",
|
| 27 |
+
"**/*.ts",
|
| 28 |
+
"**/*.tsx",
|
| 29 |
+
".next/types/**/*.ts",
|
| 30 |
+
".next/dev/types/**/*.ts",
|
| 31 |
+
"**/*.mts"
|
| 32 |
+
],
|
| 33 |
+
"exclude": ["node_modules"]
|
| 34 |
+
}
|
start.sh
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Start the Flask backend in the background (runs on port 8000)
|
| 4 |
+
cd backend
|
| 5 |
+
python app.py &
|
| 6 |
+
|
| 7 |
+
# Wait a few seconds to ensure Flask is up
|
| 8 |
+
sleep 3
|
| 9 |
+
|
| 10 |
+
# Start the Next.js frontend in the foreground (runs on port 7860)
|
| 11 |
+
cd ../mindcheck-web
|
| 12 |
+
PORT=7860 npm run start
|