Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- anxiety_app/__init__.py +0 -2
- anxiety_app/static/app.css +191 -0
- anxiety_app/static/face.js +10 -0
- anxiety_app/static/phq9.js +43 -0
- anxiety_app/static/voice.js +3 -0
- anxiety_app/templates/base.html +38 -0
- anxiety_app/templates/face.html +29 -29
- anxiety_app/templates/index.html +32 -17
- anxiety_app/templates/phq9.html +48 -19
- anxiety_app/templates/voice.html +18 -25
- requirements-modern.txt +0 -1
anxiety_app/__init__.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
"""Application factory for the multimodal affect-screening app."""
|
| 2 |
from flask import Flask
|
| 3 |
-
from flask_bootstrap import Bootstrap
|
| 4 |
|
| 5 |
from .logging_config import configure_logging
|
| 6 |
|
|
@@ -8,7 +7,6 @@ from .logging_config import configure_logging
|
|
| 8 |
def create_app():
|
| 9 |
configure_logging()
|
| 10 |
app = Flask(__name__) # templates/ and static/ live inside this package
|
| 11 |
-
Bootstrap(app)
|
| 12 |
|
| 13 |
from .routes import main
|
| 14 |
app.register_blueprint(main)
|
|
|
|
| 1 |
"""Application factory for the multimodal affect-screening app."""
|
| 2 |
from flask import Flask
|
|
|
|
| 3 |
|
| 4 |
from .logging_config import configure_logging
|
| 5 |
|
|
|
|
| 7 |
def create_app():
|
| 8 |
configure_logging()
|
| 9 |
app = Flask(__name__) # templates/ and static/ live inside this package
|
|
|
|
| 10 |
|
| 11 |
from .routes import main
|
| 12 |
app.register_blueprint(main)
|
anxiety_app/static/app.css
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
--bg: #0b0f14;
|
| 3 |
+
--bg-soft: #0f151c;
|
| 4 |
+
--surface: #151c25;
|
| 5 |
+
--surface-2: #1b242f;
|
| 6 |
+
--border: #243040;
|
| 7 |
+
--text: #e6edf3;
|
| 8 |
+
--muted: #93a1b1;
|
| 9 |
+
--primary: #6366f1;
|
| 10 |
+
--primary-2: #8b5cf6;
|
| 11 |
+
--face: #38bdf8;
|
| 12 |
+
--voice: #fb7185;
|
| 13 |
+
--phq: #34d399;
|
| 14 |
+
--danger: #f87171;
|
| 15 |
+
--radius: 16px;
|
| 16 |
+
--shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
|
| 17 |
+
--maxw: 1080px;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
* { box-sizing: border-box; }
|
| 21 |
+
|
| 22 |
+
html, body { margin: 0; padding: 0; }
|
| 23 |
+
|
| 24 |
+
body {
|
| 25 |
+
background:
|
| 26 |
+
radial-gradient(900px 500px at 80% -10%, rgba(99, 102, 241, 0.18), transparent 60%),
|
| 27 |
+
radial-gradient(700px 500px at 0% 0%, rgba(139, 92, 246, 0.12), transparent 55%),
|
| 28 |
+
var(--bg);
|
| 29 |
+
color: var(--text);
|
| 30 |
+
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 31 |
+
line-height: 1.6;
|
| 32 |
+
min-height: 100vh;
|
| 33 |
+
display: flex;
|
| 34 |
+
flex-direction: column;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
|
| 38 |
+
|
| 39 |
+
/* ---------- header / nav ---------- */
|
| 40 |
+
.site-header {
|
| 41 |
+
position: sticky;
|
| 42 |
+
top: 0;
|
| 43 |
+
z-index: 50;
|
| 44 |
+
backdrop-filter: blur(10px);
|
| 45 |
+
background: rgba(11, 15, 20, 0.72);
|
| 46 |
+
border-bottom: 1px solid var(--border);
|
| 47 |
+
}
|
| 48 |
+
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
|
| 49 |
+
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); letter-spacing: -0.02em; }
|
| 50 |
+
.brand-mark { color: var(--primary-2); margin-right: 4px; }
|
| 51 |
+
.brand-accent { color: var(--muted); font-weight: 600; }
|
| 52 |
+
.nav { display: flex; gap: 4px; }
|
| 53 |
+
.nav a {
|
| 54 |
+
color: var(--muted);
|
| 55 |
+
text-decoration: none;
|
| 56 |
+
font-weight: 500;
|
| 57 |
+
font-size: 0.95rem;
|
| 58 |
+
padding: 8px 14px;
|
| 59 |
+
border-radius: 10px;
|
| 60 |
+
transition: all 0.15s ease;
|
| 61 |
+
}
|
| 62 |
+
.nav a:hover { color: var(--text); background: var(--surface); }
|
| 63 |
+
.nav a.active { color: var(--text); background: var(--surface-2); }
|
| 64 |
+
|
| 65 |
+
/* ---------- layout ---------- */
|
| 66 |
+
.main { flex: 1; padding: 40px 20px 64px; width: 100%; max-width: var(--maxw); margin: 0 auto; }
|
| 67 |
+
.page-title { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 6px; }
|
| 68 |
+
.page-sub { color: var(--muted); margin: 0 0 28px; }
|
| 69 |
+
|
| 70 |
+
/* ---------- hero ---------- */
|
| 71 |
+
.hero { text-align: center; padding: 48px 0 16px; }
|
| 72 |
+
.hero h1 { font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 800; letter-spacing: -0.03em; margin: 0 0 16px; }
|
| 73 |
+
.hero h1 .grad {
|
| 74 |
+
background: linear-gradient(120deg, var(--primary), var(--primary-2));
|
| 75 |
+
-webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
|
| 76 |
+
}
|
| 77 |
+
.hero p { color: var(--muted); font-size: 1.12rem; max-width: 640px; margin: 0 auto 28px; }
|
| 78 |
+
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
|
| 79 |
+
|
| 80 |
+
/* ---------- cards ---------- */
|
| 81 |
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-top: 40px; }
|
| 82 |
+
.card {
|
| 83 |
+
background: linear-gradient(180deg, var(--surface), var(--bg-soft));
|
| 84 |
+
border: 1px solid var(--border);
|
| 85 |
+
border-radius: var(--radius);
|
| 86 |
+
padding: 26px;
|
| 87 |
+
text-decoration: none;
|
| 88 |
+
color: var(--text);
|
| 89 |
+
display: block;
|
| 90 |
+
transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
|
| 91 |
+
}
|
| 92 |
+
a.card:hover { transform: translateY(-4px); border-color: #36506e; box-shadow: var(--shadow); }
|
| 93 |
+
.card .ic { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.5rem; margin-bottom: 14px; }
|
| 94 |
+
.ic.face { background: rgba(56, 189, 248, 0.15); }
|
| 95 |
+
.ic.voice { background: rgba(251, 113, 133, 0.15); }
|
| 96 |
+
.ic.phq { background: rgba(52, 211, 153, 0.15); }
|
| 97 |
+
.card h3 { margin: 0 0 6px; font-size: 1.2rem; }
|
| 98 |
+
.card p { margin: 0; color: var(--muted); font-size: 0.95rem; }
|
| 99 |
+
|
| 100 |
+
/* ---------- panel ---------- */
|
| 101 |
+
.panel {
|
| 102 |
+
background: linear-gradient(180deg, var(--surface), var(--bg-soft));
|
| 103 |
+
border: 1px solid var(--border);
|
| 104 |
+
border-radius: var(--radius);
|
| 105 |
+
padding: 28px;
|
| 106 |
+
box-shadow: var(--shadow);
|
| 107 |
+
}
|
| 108 |
+
.center { text-align: center; }
|
| 109 |
+
|
| 110 |
+
/* ---------- buttons ---------- */
|
| 111 |
+
.btn {
|
| 112 |
+
display: inline-flex; align-items: center; gap: 8px; justify-content: center;
|
| 113 |
+
font: inherit; font-weight: 600; font-size: 1rem;
|
| 114 |
+
padding: 12px 22px; border-radius: 12px; border: 1px solid transparent;
|
| 115 |
+
cursor: pointer; text-decoration: none; transition: all 0.15s ease; color: #fff;
|
| 116 |
+
}
|
| 117 |
+
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
|
| 118 |
+
.btn-primary { background: linear-gradient(120deg, var(--primary), var(--primary-2)); }
|
| 119 |
+
.btn-primary:not(:disabled):hover { filter: brightness(1.08); transform: translateY(-1px); }
|
| 120 |
+
.btn-face { background: linear-gradient(120deg, #0ea5e9, #38bdf8); }
|
| 121 |
+
.btn-voice { background: linear-gradient(120deg, #f43f5e, #fb7185); }
|
| 122 |
+
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); }
|
| 123 |
+
.btn-ghost:not(:disabled):hover { border-color: #3a5273; }
|
| 124 |
+
|
| 125 |
+
/* ---------- media capture ---------- */
|
| 126 |
+
.stage { position: relative; display: inline-block; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); max-width: 100%; }
|
| 127 |
+
.stage video { display: block; background: #000; width: 100%; height: auto; max-width: 640px; }
|
| 128 |
+
.stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
|
| 129 |
+
.controls { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 20px 0 8px; }
|
| 130 |
+
|
| 131 |
+
.status { color: var(--muted); min-height: 1.5em; margin: 8px 0; }
|
| 132 |
+
.result {
|
| 133 |
+
font-size: 1.5rem; font-weight: 800; margin: 12px 0 0; letter-spacing: -0.01em;
|
| 134 |
+
}
|
| 135 |
+
.result:empty { display: none; }
|
| 136 |
+
|
| 137 |
+
/* signal chips */
|
| 138 |
+
.chips { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
|
| 139 |
+
.chip { font-size: 0.85rem; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); }
|
| 140 |
+
.chip b { color: var(--text); }
|
| 141 |
+
|
| 142 |
+
/* mic pulse */
|
| 143 |
+
.mic-orb {
|
| 144 |
+
width: 92px; height: 92px; border-radius: 50%; margin: 6px auto 18px;
|
| 145 |
+
display: grid; place-items: center; font-size: 2rem;
|
| 146 |
+
background: rgba(251, 113, 133, 0.14); border: 1px solid rgba(251, 113, 133, 0.4);
|
| 147 |
+
}
|
| 148 |
+
.mic-orb.recording { animation: pulse 1.1s ease-in-out infinite; }
|
| 149 |
+
@keyframes pulse {
|
| 150 |
+
0% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.45); }
|
| 151 |
+
70% { box-shadow: 0 0 0 20px rgba(251, 113, 133, 0); }
|
| 152 |
+
100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0); }
|
| 153 |
+
}
|
| 154 |
+
audio { width: 100%; max-width: 420px; margin-top: 14px; }
|
| 155 |
+
|
| 156 |
+
/* ---------- PHQ-9 ---------- */
|
| 157 |
+
.q { border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; background: var(--surface); }
|
| 158 |
+
.q-text { font-weight: 600; margin-bottom: 12px; }
|
| 159 |
+
.q-text .num { color: var(--muted); margin-right: 8px; }
|
| 160 |
+
.opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
|
| 161 |
+
.opt { position: relative; }
|
| 162 |
+
.opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
|
| 163 |
+
.opt span {
|
| 164 |
+
display: block; text-align: center; padding: 10px 6px; border-radius: 10px;
|
| 165 |
+
border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
|
| 166 |
+
font-size: 0.85rem; cursor: pointer; transition: all 0.12s ease;
|
| 167 |
+
}
|
| 168 |
+
.opt input:checked + span { border-color: var(--phq); background: rgba(52, 211, 153, 0.16); color: var(--text); font-weight: 600; }
|
| 169 |
+
.opt:hover span { border-color: #3a5273; }
|
| 170 |
+
|
| 171 |
+
.scorecard { margin-top: 20px; padding: 22px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
|
| 172 |
+
.scorecard:empty { display: none; }
|
| 173 |
+
.score-num { font-size: 2.4rem; font-weight: 800; }
|
| 174 |
+
.sev { display: inline-block; padding: 4px 12px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; }
|
| 175 |
+
.sev-minimal { background: rgba(52,211,153,0.18); color: #6ee7b7; }
|
| 176 |
+
.sev-mild { background: rgba(250,204,21,0.16); color: #fde047; }
|
| 177 |
+
.sev-moderate { background: rgba(251,146,60,0.16); color: #fdba74; }
|
| 178 |
+
.sev-modsevere { background: rgba(248,113,113,0.16); color: #fca5a5; }
|
| 179 |
+
.sev-severe { background: rgba(239,68,68,0.22); color: #fecaca; }
|
| 180 |
+
.crisis { margin-top: 14px; padding: 14px 16px; border-radius: 12px; border: 1px solid rgba(248,113,113,0.4); background: rgba(248,113,113,0.1); color: #fecaca; font-size: 0.92rem; }
|
| 181 |
+
|
| 182 |
+
/* ---------- disclaimer / footer ---------- */
|
| 183 |
+
.note { color: var(--muted); font-size: 0.9rem; max-width: 640px; margin: 18px auto 0; }
|
| 184 |
+
.site-footer { border-top: 1px solid var(--border); padding: 22px 0; color: var(--muted); font-size: 0.88rem; }
|
| 185 |
+
.site-footer p { margin: 0; text-align: center; }
|
| 186 |
+
|
| 187 |
+
@media (max-width: 560px) {
|
| 188 |
+
.opts { grid-template-columns: repeat(2, 1fr); }
|
| 189 |
+
.brand-accent { display: none; }
|
| 190 |
+
.nav a { padding: 8px 10px; }
|
| 191 |
+
}
|
anxiety_app/static/face.js
CHANGED
|
@@ -8,15 +8,24 @@
|
|
| 8 |
const statusEl = document.getElementById("status");
|
| 9 |
const resultEl = document.getElementById("result");
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
const capture = document.createElement("canvas");
|
| 12 |
const counts = { Anxious: 0, Depressed: 0, Normal: 0 };
|
| 13 |
let stream = null, timer = null, busy = false;
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
startBtn.onclick = async () => {
|
| 16 |
try {
|
| 17 |
stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 18 |
video.srcObject = stream;
|
| 19 |
Object.keys(counts).forEach((k) => (counts[k] = 0));
|
|
|
|
| 20 |
resultEl.textContent = "";
|
| 21 |
startBtn.disabled = true;
|
| 22 |
stopBtn.disabled = false;
|
|
@@ -74,5 +83,6 @@
|
|
| 74 |
ctx.fillText(label, x * sx, y * sy > 20 ? y * sy - 6 : y * sy + 16);
|
| 75 |
if (counts[f.signal] !== undefined) counts[f.signal]++;
|
| 76 |
});
|
|
|
|
| 77 |
}
|
| 78 |
})();
|
|
|
|
| 8 |
const statusEl = document.getElementById("status");
|
| 9 |
const resultEl = document.getElementById("result");
|
| 10 |
|
| 11 |
+
const chip = { Anxious: document.getElementById("c-anx"),
|
| 12 |
+
Depressed: document.getElementById("c-dep"),
|
| 13 |
+
Normal: document.getElementById("c-nor") };
|
| 14 |
+
|
| 15 |
const capture = document.createElement("canvas");
|
| 16 |
const counts = { Anxious: 0, Depressed: 0, Normal: 0 };
|
| 17 |
let stream = null, timer = null, busy = false;
|
| 18 |
|
| 19 |
+
function renderChips() {
|
| 20 |
+
Object.keys(counts).forEach((k) => { if (chip[k]) chip[k].textContent = counts[k]; });
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
startBtn.onclick = async () => {
|
| 24 |
try {
|
| 25 |
stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 26 |
video.srcObject = stream;
|
| 27 |
Object.keys(counts).forEach((k) => (counts[k] = 0));
|
| 28 |
+
renderChips();
|
| 29 |
resultEl.textContent = "";
|
| 30 |
startBtn.disabled = true;
|
| 31 |
stopBtn.disabled = false;
|
|
|
|
| 83 |
ctx.fillText(label, x * sx, y * sy > 20 ? y * sy - 6 : y * sy + 16);
|
| 84 |
if (counts[f.signal] !== undefined) counts[f.signal]++;
|
| 85 |
});
|
| 86 |
+
renderChips();
|
| 87 |
}
|
| 88 |
})();
|
anxiety_app/static/phq9.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// PHQ-9 scoring (client-side). Sums 9 items (0-3 each) -> severity band.
|
| 2 |
+
(function () {
|
| 3 |
+
const form = document.getElementById("phq-form");
|
| 4 |
+
const card = document.getElementById("scorecard");
|
| 5 |
+
|
| 6 |
+
function severity(s) {
|
| 7 |
+
if (s <= 4) return { label: "Minimal", cls: "sev-minimal", desc: "Minimal or no depression symptoms." };
|
| 8 |
+
if (s <= 9) return { label: "Mild", cls: "sev-mild", desc: "Mild symptoms — keeping an eye on how you feel may help." };
|
| 9 |
+
if (s <= 14) return { label: "Moderate", cls: "sev-moderate", desc: "Moderate symptoms — consider speaking with a clinician." };
|
| 10 |
+
if (s <= 19) return { label: "Moderately severe", cls: "sev-modsevere", desc: "Moderately severe symptoms — professional support is recommended." };
|
| 11 |
+
return { label: "Severe", cls: "sev-severe", desc: "Severe symptoms — please reach out for professional support." };
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
form.addEventListener("submit", function (e) {
|
| 15 |
+
e.preventDefault();
|
| 16 |
+
let total = 0, answered = 0, q9 = 0;
|
| 17 |
+
for (let i = 0; i < 9; i++) {
|
| 18 |
+
const sel = form.querySelector('input[name="q' + i + '"]:checked');
|
| 19 |
+
if (sel) { answered++; const v = +sel.value; total += v; if (i === 8) q9 = v; }
|
| 20 |
+
}
|
| 21 |
+
if (answered < 9) {
|
| 22 |
+
card.innerHTML = '<p class="status">Please answer all 9 questions (' + answered + "/9 answered).</p>";
|
| 23 |
+
card.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
| 24 |
+
return;
|
| 25 |
+
}
|
| 26 |
+
const band = severity(total);
|
| 27 |
+
let html =
|
| 28 |
+
'<div class="score-num">' + total + '<span style="font-size:1rem;color:var(--muted)"> / 27</span></div>' +
|
| 29 |
+
'<p><span class="sev ' + band.cls + '">' + band.label + "</span></p>" +
|
| 30 |
+
'<p class="status">' + band.desc + "</p>";
|
| 31 |
+
if (q9 > 0) {
|
| 32 |
+
html +=
|
| 33 |
+
'<div class="crisis">⚠️ You indicated thoughts that you would be better off dead or of hurting ' +
|
| 34 |
+
"yourself. Please talk to someone now. India: iCall +91 9152987821, AASRA +91 9820466726. " +
|
| 35 |
+
"US: call or text <strong>988</strong>. If you are in immediate danger, contact local emergency services.</div>";
|
| 36 |
+
}
|
| 37 |
+
html += '<p class="note">This is a screening aid, not a diagnosis. Please discuss results with a clinician.</p>';
|
| 38 |
+
card.innerHTML = html;
|
| 39 |
+
card.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
form.addEventListener("reset", function () { card.innerHTML = ""; });
|
| 43 |
+
})();
|
anxiety_app/static/voice.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
const statusEl = document.getElementById("vstatus");
|
| 5 |
const resultEl = document.getElementById("vresult");
|
| 6 |
const player = document.getElementById("player");
|
|
|
|
| 7 |
const SECONDS = 4;
|
| 8 |
|
| 9 |
recBtn.onclick = async () => {
|
|
@@ -18,6 +19,7 @@
|
|
| 18 |
const recorder = new MediaRecorder(stream);
|
| 19 |
recorder.ondataavailable = (e) => e.data.size && chunks.push(e.data);
|
| 20 |
recorder.onstop = async () => {
|
|
|
|
| 21 |
stream.getTracks().forEach((t) => t.stop());
|
| 22 |
const type = recorder.mimeType || "audio/webm";
|
| 23 |
const blob = new Blob(chunks, { type });
|
|
@@ -42,6 +44,7 @@
|
|
| 42 |
recBtn.disabled = true;
|
| 43 |
resultEl.textContent = "";
|
| 44 |
statusEl.textContent = "Recording " + SECONDS + "s…";
|
|
|
|
| 45 |
recorder.start();
|
| 46 |
setTimeout(() => recorder.state !== "inactive" && recorder.stop(), SECONDS * 1000);
|
| 47 |
};
|
|
|
|
| 4 |
const statusEl = document.getElementById("vstatus");
|
| 5 |
const resultEl = document.getElementById("vresult");
|
| 6 |
const player = document.getElementById("player");
|
| 7 |
+
const orb = document.getElementById("orb");
|
| 8 |
const SECONDS = 4;
|
| 9 |
|
| 10 |
recBtn.onclick = async () => {
|
|
|
|
| 19 |
const recorder = new MediaRecorder(stream);
|
| 20 |
recorder.ondataavailable = (e) => e.data.size && chunks.push(e.data);
|
| 21 |
recorder.onstop = async () => {
|
| 22 |
+
if (orb) orb.classList.remove("recording");
|
| 23 |
stream.getTracks().forEach((t) => t.stop());
|
| 24 |
const type = recorder.mimeType || "audio/webm";
|
| 25 |
const blob = new Blob(chunks, { type });
|
|
|
|
| 44 |
recBtn.disabled = true;
|
| 45 |
resultEl.textContent = "";
|
| 46 |
statusEl.textContent = "Recording " + SECONDS + "s…";
|
| 47 |
+
if (orb) orb.classList.add("recording");
|
| 48 |
recorder.start();
|
| 49 |
setTimeout(() => recorder.state !== "inactive" && recorder.stop(), SECONDS * 1000);
|
| 50 |
};
|
anxiety_app/templates/base.html
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>{% block title %}AffectScreening{% endblock %}</title>
|
| 7 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
| 10 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='app.css') }}">
|
| 11 |
+
{% block head %}{% endblock %}
|
| 12 |
+
</head>
|
| 13 |
+
<body>
|
| 14 |
+
<header class="site-header">
|
| 15 |
+
<div class="container header-inner">
|
| 16 |
+
<a class="brand" href="{{ url_for('main.index') }}"><span class="brand-mark">◐</span>Affect<span class="brand-accent">Screening</span></a>
|
| 17 |
+
<nav class="nav">
|
| 18 |
+
<a href="{{ url_for('main.index') }}" class="{% if request.endpoint == 'main.index' %}active{% endif %}">Home</a>
|
| 19 |
+
<a href="{{ url_for('main.face') }}" class="{% if request.endpoint == 'main.face' %}active{% endif %}">Face</a>
|
| 20 |
+
<a href="{{ url_for('main.voice') }}" class="{% if request.endpoint == 'main.voice' %}active{% endif %}">Voice</a>
|
| 21 |
+
<a href="{{ url_for('main.phq') }}" class="{% if request.endpoint == 'main.phq' %}active{% endif %}">PHQ-9</a>
|
| 22 |
+
</nav>
|
| 23 |
+
</div>
|
| 24 |
+
</header>
|
| 25 |
+
|
| 26 |
+
<main class="main">
|
| 27 |
+
{% block content %}{% endblock %}
|
| 28 |
+
</main>
|
| 29 |
+
|
| 30 |
+
<footer class="site-footer">
|
| 31 |
+
<div class="container">
|
| 32 |
+
<p>⚠️ Educational demo — emotion signals are <strong>not a clinical diagnosis</strong>. The PHQ-9 is a screening aid, not a diagnosis. If you're struggling, please reach out to a professional.</p>
|
| 33 |
+
</div>
|
| 34 |
+
</footer>
|
| 35 |
+
|
| 36 |
+
{% block scripts %}{% endblock %}
|
| 37 |
+
</body>
|
| 38 |
+
</html>
|
anxiety_app/templates/face.html
CHANGED
|
@@ -1,36 +1,36 @@
|
|
| 1 |
-
{% extends "
|
| 2 |
-
{% block
|
| 3 |
-
{{super()}}
|
| 4 |
-
<link rel="stylesheet" href="{{url_for('static', filename='styles.css')}}">
|
| 5 |
-
<link rel="preconnect" href="https://fonts.gstatic.com">
|
| 6 |
-
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@900&display=swap" rel="stylesheet">
|
| 7 |
-
{% endblock %}
|
| 8 |
|
| 9 |
{% block content %}
|
| 10 |
-
<
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
</
|
| 16 |
-
|
| 17 |
-
<h2 class="heading">Facial Emotion Detection</h2>
|
| 18 |
-
|
| 19 |
-
<div style="text-align:center;">
|
| 20 |
-
<div style="position:relative; display:inline-block;">
|
| 21 |
-
<video id="video" autoplay playsinline muted width="640" height="480" style="background:#000;border-radius:8px;"></video>
|
| 22 |
-
<canvas id="overlay" width="640" height="480" style="position:absolute; left:0; top:0;"></canvas>
|
| 23 |
</div>
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
<button id="
|
|
|
|
| 27 |
</div>
|
| 28 |
-
|
| 29 |
-
<
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
</div>
|
| 34 |
|
| 35 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
{% endblock %}
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}Face — AffectScreening{% endblock %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
{% block content %}
|
| 5 |
+
<h1 class="page-title">Facial emotion detection</h1>
|
| 6 |
+
<p class="page-sub">Allow webcam access, then we classify your expression live (FER2013 CNN).</p>
|
| 7 |
+
|
| 8 |
+
<div class="panel center">
|
| 9 |
+
<div class="stage">
|
| 10 |
+
<video id="video" autoplay playsinline muted width="640" height="480"></video>
|
| 11 |
+
<canvas id="overlay" width="640" height="480"></canvas>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
</div>
|
| 13 |
+
|
| 14 |
+
<div class="controls">
|
| 15 |
+
<button id="startBtn" class="btn btn-face">▶ Start camera</button>
|
| 16 |
+
<button id="stopBtn" class="btn btn-ghost" disabled>■ Stop & get result</button>
|
| 17 |
</div>
|
| 18 |
+
|
| 19 |
+
<p id="status" class="status">Click “Start camera” and allow webcam access.</p>
|
| 20 |
+
|
| 21 |
+
<div class="chips">
|
| 22 |
+
<span class="chip">Anxious <b id="c-anx">0</b></span>
|
| 23 |
+
<span class="chip">Depressed <b id="c-dep">0</b></span>
|
| 24 |
+
<span class="chip">Normal <b id="c-nor">0</b></span>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<h3 id="result" class="result"></h3>
|
| 28 |
</div>
|
| 29 |
|
| 30 |
+
<p class="note center">“fear” → Anxious and “sad” → Depressed are shown as supplementary cues,
|
| 31 |
+
<strong>not a diagnosis</strong>.</p>
|
| 32 |
+
{% endblock %}
|
| 33 |
+
|
| 34 |
+
{% block scripts %}
|
| 35 |
+
<script src="{{ url_for('static', filename='face.js') }}"></script>
|
| 36 |
{% endblock %}
|
anxiety_app/templates/index.html
CHANGED
|
@@ -1,20 +1,35 @@
|
|
| 1 |
-
{% extends "
|
|
|
|
| 2 |
|
| 3 |
-
{% block
|
| 4 |
-
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
{
|
| 11 |
-
<
|
| 12 |
-
|
| 13 |
-
<li><a href="face">Face</a></li>
|
| 14 |
-
<li><a href="voice">Voice</a></li>
|
| 15 |
-
</ul>
|
| 16 |
-
<h2>Anxiety and Depression Detection</h2>
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}AffectScreening — multimodal well-being demo{% endblock %}
|
| 3 |
|
| 4 |
+
{% block content %}
|
| 5 |
+
<section class="hero">
|
| 6 |
+
<h1>Multimodal <span class="grad">Affect</span> & Well-being Screening</h1>
|
| 7 |
+
<p>Recognize emotional cues from your face and voice with deep learning, alongside the
|
| 8 |
+
clinically validated PHQ-9 questionnaire — all running in your browser.</p>
|
| 9 |
+
<div class="hero-cta">
|
| 10 |
+
<a class="btn btn-primary" href="{{ url_for('main.face') }}">Try face detection</a>
|
| 11 |
+
<a class="btn btn-ghost" href="{{ url_for('main.phq') }}">Take the PHQ-9</a>
|
| 12 |
+
</div>
|
| 13 |
+
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
<div class="grid">
|
| 16 |
+
<a class="card" href="{{ url_for('main.face') }}">
|
| 17 |
+
<div class="ic face">🙂</div>
|
| 18 |
+
<h3>Facial emotion</h3>
|
| 19 |
+
<p>Stream your webcam and a CNN (FER2013) classifies expressions in real time.</p>
|
| 20 |
+
</a>
|
| 21 |
+
<a class="card" href="{{ url_for('main.voice') }}">
|
| 22 |
+
<div class="ic voice">🎙️</div>
|
| 23 |
+
<h3>Speech emotion</h3>
|
| 24 |
+
<p>Record a few seconds and a 1-D CNN (RAVDESS) predicts gender + emotion from your voice.</p>
|
| 25 |
+
</a>
|
| 26 |
+
<a class="card" href="{{ url_for('main.phq') }}">
|
| 27 |
+
<div class="ic phq">📋</div>
|
| 28 |
+
<h3>PHQ-9 screening</h3>
|
| 29 |
+
<p>Answer the standard 9-item depression-screening questionnaire and get a scored result.</p>
|
| 30 |
+
</a>
|
| 31 |
+
</div>
|
| 32 |
|
| 33 |
+
<p class="note center">Emotion recognition is a supplementary cue, <strong>not a diagnosis</strong>.
|
| 34 |
+
The PHQ-9 is the only clinically validated component here.</p>
|
| 35 |
+
{% endblock %}
|
anxiety_app/templates/phq9.html
CHANGED
|
@@ -1,23 +1,52 @@
|
|
| 1 |
-
|
| 2 |
-
{% block
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
-
{% endblock %}
|
| 8 |
|
| 9 |
-
|
| 10 |
-
<
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}PHQ-9 — AffectScreening{% endblock %}
|
| 3 |
+
|
| 4 |
+
{% block content %}
|
| 5 |
+
<h1 class="page-title">PHQ-9 depression screening</h1>
|
| 6 |
+
<p class="page-sub">Over the last 2 weeks, how often have you been bothered by the following problems?</p>
|
|
|
|
| 7 |
|
| 8 |
+
<div class="panel">
|
| 9 |
+
<form id="phq-form">
|
| 10 |
+
{% set questions = [
|
| 11 |
+
"Little interest or pleasure in doing things",
|
| 12 |
+
"Feeling down, depressed, or hopeless",
|
| 13 |
+
"Trouble falling or staying asleep, or sleeping too much",
|
| 14 |
+
"Feeling tired or having little energy",
|
| 15 |
+
"Poor appetite or overeating",
|
| 16 |
+
"Feeling bad about yourself — or that you are a failure or have let yourself or your family down",
|
| 17 |
+
"Trouble concentrating on things, such as reading or watching television",
|
| 18 |
+
"Moving or speaking so slowly that others could notice — or being so fidgety/restless that you move around a lot more than usual",
|
| 19 |
+
"Thoughts that you would be better off dead, or of hurting yourself in some way"
|
| 20 |
+
] %}
|
| 21 |
+
{% set options = ["Not at all", "Several days", "More than half the days", "Nearly every day"] %}
|
| 22 |
+
{% for q in questions %}
|
| 23 |
+
{% set qi = loop.index0 %}
|
| 24 |
+
<div class="q">
|
| 25 |
+
<div class="q-text"><span class="num">{{ loop.index }}.</span>{{ q }}</div>
|
| 26 |
+
<div class="opts">
|
| 27 |
+
{% for opt in options %}
|
| 28 |
+
<label class="opt">
|
| 29 |
+
<input type="radio" name="q{{ qi }}" value="{{ loop.index0 }}">
|
| 30 |
+
<span>{{ opt }}</span>
|
| 31 |
+
</label>
|
| 32 |
+
{% endfor %}
|
| 33 |
+
</div>
|
| 34 |
+
</div>
|
| 35 |
+
{% endfor %}
|
| 36 |
|
| 37 |
+
<div class="controls" style="justify-content:flex-start; margin-top:6px;">
|
| 38 |
+
<button type="submit" class="btn btn-primary">Calculate score</button>
|
| 39 |
+
<button type="reset" class="btn btn-ghost">Reset</button>
|
| 40 |
+
</div>
|
| 41 |
+
</form>
|
| 42 |
|
| 43 |
+
<div id="scorecard" class="scorecard"></div>
|
| 44 |
+
</div>
|
| 45 |
|
| 46 |
+
<p class="note">The PHQ-9 is a validated screening aid for depression severity. It does
|
| 47 |
+
<strong>not</strong> provide a diagnosis — discuss any concerns with a qualified clinician.</p>
|
| 48 |
+
{% endblock %}
|
| 49 |
+
|
| 50 |
+
{% block scripts %}
|
| 51 |
+
<script src="{{ url_for('static', filename='phq9.js') }}"></script>
|
| 52 |
+
{% endblock %}
|
anxiety_app/templates/voice.html
CHANGED
|
@@ -1,33 +1,26 @@
|
|
| 1 |
-
{% extends "
|
| 2 |
-
{% block
|
| 3 |
-
{{super()}}
|
| 4 |
-
<link rel="stylesheet" href="{{url_for('static', filename='styles.css')}}">
|
| 5 |
-
<link rel="preconnect" href="https://fonts.gstatic.com">
|
| 6 |
-
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@900&display=swap" rel="stylesheet">
|
| 7 |
-
{% endblock %}
|
| 8 |
|
| 9 |
{% block content %}
|
| 10 |
-
<
|
| 11 |
-
|
| 12 |
-
<li style="float: left;"><a href="face" style="display: block; color: white;padding: 14px 16px;">Face</a></li>
|
| 13 |
-
<li style="float: left;"><a href="voice" style="display: block; color: white;padding: 14px 16px;">Voice</a></li>
|
| 14 |
-
<li style="float: left;"><a href="qstn" style="display: block; color: white;padding: 14px 16px;">PHQ-9</a></li>
|
| 15 |
-
</ul>
|
| 16 |
|
| 17 |
-
<
|
|
|
|
| 18 |
|
| 19 |
-
<div
|
| 20 |
-
|
| 21 |
-
<div style="margin:14px;">
|
| 22 |
-
<button id="recBtn" class="voice_detect_btn">Record 4s</button>
|
| 23 |
</div>
|
| 24 |
-
|
| 25 |
-
<
|
| 26 |
-
<
|
| 27 |
-
<
|
| 28 |
-
Predicts gender + emotion from your voice. A demo cue, <strong>not a diagnosis</strong>.
|
| 29 |
-
</p>
|
| 30 |
</div>
|
| 31 |
|
| 32 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
{% endblock %}
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}Voice — AffectScreening{% endblock %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
{% block content %}
|
| 5 |
+
<h1 class="page-title">Speech emotion detection</h1>
|
| 6 |
+
<p class="page-sub">Record a few seconds of speech; a 1-D CNN (RAVDESS) predicts gender + emotion.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
<div class="panel center">
|
| 9 |
+
<div id="orb" class="mic-orb">🎙️</div>
|
| 10 |
|
| 11 |
+
<div class="controls">
|
| 12 |
+
<button id="recBtn" class="btn btn-voice">● Record 4s</button>
|
|
|
|
|
|
|
| 13 |
</div>
|
| 14 |
+
|
| 15 |
+
<p id="vstatus" class="status">{{ data }}</p>
|
| 16 |
+
<h3 id="vresult" class="result"></h3>
|
| 17 |
+
<audio id="player" controls style="display:none;"></audio>
|
|
|
|
|
|
|
| 18 |
</div>
|
| 19 |
|
| 20 |
+
<p class="note center">Predicts a combined gender + emotion class from your voice — a demo cue,
|
| 21 |
+
<strong>not a diagnosis</strong>.</p>
|
| 22 |
+
{% endblock %}
|
| 23 |
+
|
| 24 |
+
{% block scripts %}
|
| 25 |
+
<script src="{{ url_for('static', filename='voice.js') }}"></script>
|
| 26 |
{% endblock %}
|
requirements-modern.txt
CHANGED
|
@@ -18,5 +18,4 @@ pandas
|
|
| 18 |
scikit-learn
|
| 19 |
soundfile
|
| 20 |
flask
|
| 21 |
-
flask-bootstrap
|
| 22 |
gunicorn
|
|
|
|
| 18 |
scikit-learn
|
| 19 |
soundfile
|
| 20 |
flask
|
|
|
|
| 21 |
gunicorn
|