Spaces:
Sleeping
Sleeping
File size: 2,721 Bytes
16c08a4 e5067f3 16c08a4 e5067f3 16c08a4 e5067f3 a5917d0 e5067f3 a5917d0 e5067f3 a5917d0 e5067f3 a5917d0 e5067f3 a5917d0 5df45c4 a5917d0 e5067f3 a5917d0 e5067f3 a5917d0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | ---
title: VibeCheck MentalBERT API
emoji: 🧠
colorFrom: indigo
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: mit
---
# VibeCheck MentalBERT API
FastAPI proxy serving two fine-tuned MentalBERT models for mental health text classification: a fast flat 8-class head ("Quick Vibe") and a 5-stage hierarchical cascade ("Deep Dive") with optional sensitive-mode calibration.
## Endpoint
**POST** `/classify`
Request body:
```json
{ "text": "i have been feeling really overwhelmed lately", "model": "mentalbert", "sensitive_mode": false }
```
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `text` | string | yes | — | Input text. Max 4096 chars (configurable via `MAX_INPUT_CHARS`). |
| `model` | `"mentalbert" \| "longformer"` | no | `"mentalbert"` | `mentalbert` = Quick Vibe (single forward pass). `longformer` = Deep Dive (5-stage cascade). |
| `sensitive_mode` | bool | no | `false` | Only honored when `model="longformer"`. Lowers the cascade's Stage 0 / Stage 1A thresholds for higher crisis recall. |
Response:
```json
{ "classification": "stress", "confidence": 0.8731 }
```
## Classes (8)
`anxiety` · `bipolar` · `depression` · `normal` · `personality_disorder` · `stress` · `suicidal` · `unhinged`
(`unhinged` is the display key for the model label "Directed Aggression" — threats toward others.)
## Pre-filter
A small regex pre-filter short-circuits the model for unambiguous explicit threats (modal verb + violent verb + 2nd/3rd-person target). It only fires forward (never reroutes self-directed language to aggression) and returns `unhinged` at confidence `0.99`.
## Health check
**GET** `/` → `{ "status": "ok", "loaded": [...], "pid": ... }`
## Environment variables (Space secrets)
| Name | Default | Purpose |
|---|---|---|
| `HF_TOKEN` | — | **Required.** HuggingFace Read token, used by `snapshot_download` to pull the model repos. |
| `QUICK_VIBE_MODEL` | `itsLu/mentalbert-v6-flat` | Override the Quick Vibe model repo. |
| `DEEP_DIVE_MODEL` | `itsLu/mentalbert-v6-hierarchical` | Override the Deep Dive model repo. |
| `ALLOWED_ORIGINS` | `localhost:3000,localhost:3001,https://vibecheck-eosin.vercel.app,https://checkmyvibe.me,https://www.checkmyvibe.me` | Comma-separated CORS allowlist. |
| `MAX_INPUT_CHARS` | `4096` | Reject requests longer than this with HTTP 413. |
| `DEBUG_ENDPOINTS` | `false` | When `"true"`, registers `/diag` and `/debug_classify` for inspection. Off in prod. |
## Deployment
```bash
git push origin main
```
The Space rebuilds the Docker image and starts the container. Models are pulled lazily on first classify request (~30–60 s download per model, cached for the container's lifetime).
|