Spaces:
Runtime error
Runtime error
File size: 8,424 Bytes
4d596f8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | ---
title: PsycheOS
emoji: π§
colorFrom: purple
colorTo: pink
sdk: streamlit
sdk_version: 1.32.0
app_file: app/streamlit_app.py
pinned: true
license: mit
tags:
- reinforcement-learning
- mental-health
- multi-agent
- openenv
- grpo
- hackathon
---
# π§ PsycheOS β Mental Health Crisis Operating System
> **Meta PyTorch OpenEnv Hackathon Γ Scaler School of Technology β Grand Finale**
> Solo submission Β· Mesa Sarah Vasantha Zephyr Β· April 25β26, 2026 Β· Bangalore
---
## π Links
| Resource | URL |
|----------|-----|
| π Live HF Space | https://huggingface.co/spaces/mesazephyr/psycheos |
| π Mini-blog (HuggingFace) | _[Add after training β April 25]_ |
| π₯ Demo video (YouTube, <2 min) | _[Add after training β April 25]_ |
| π» Training notebook (Colab) | [](https://colab.research.google.com/github/mesazephyr/psycheos/blob/main/training/colab_training.ipynb) |
| π€ LoRA weights | _[Add after training β mesazephyr/psycheos-lora]_ |
---
## The Problem
**197 million** Indians live with a mental disorder.
**9,000** psychiatrists exist for a population of 1.4 billion.
That is **one doctor for every 155,000 people** who need one.
**83%** receive zero care.
The gap is not just statistical β it is deadly. Delayed crisis identification and zero continuity between care interactions cost lives. PsycheOS is built to close that gap.
---
## What is PsycheOS?
PsycheOS is simultaneously:
1. **A real deployable app** β open it in your browser right now, talk to it
2. **An OpenEnv RL training environment** β Gymnasium-compatible POMDP with measurable reward signals
3. **A self-improving multi-agent system** β gets measurably better at crisis detection through GRPO + curriculum self-play
---
## How the Environment Works
### What the agent sees (observation space)
```
{
"message": "<patient's raw text>",
"session_history": [last 3 turns with distress labels],
"turn": <int>,
"session": <int>
}
```
### What the agent does (action space)
```
{
"distress_level": <1β5>, # classify severity
"response": "<text>", # generate empathetic reply
"escalate": <true/false> # route to human counselor?
}
```
### What the agent gets rewarded for
| Signal | Weight | Description |
|--------|--------|-------------|
| Detection F1 | 40% | Accuracy of distress severity classification |
| Empathy DPO | 40% | Psychiatrist preference margin on responses |
| Escalation P/R | 20% | Crisis routing precision β **10x penalty on false negatives** |
The reward is hard to game. An agent that always escalates scores β1 on false positives. An agent that never escalates scores β10 on every missed crisis. The only way to score well is to actually solve the task.
---
## The 5 Agents
```
User message
β
βΌ
βββββββββββββββ ββββββββββββββββ βββββββββββββββββββββ
β Memory ββββββΆβ Detector ββββββΆβ Empathy Agent β
β Retrieval β β Agent (1β5) β β (DPO fine-tuned) β
βββββββββββββββ ββββββββββββββββ βββββββββββββββββββββ
β
βΌ
ββββββββββββββββ βββββββββββββββββββββ
β Oversight βββββββ Crisis Escalator β
β Agent β β Agent β
ββββββββββββββββ βββββββββββββββββββββ
β
βΌ
Final response
(or crisis escalation)
```
| Agent | Role | Bonus prize target |
|-------|------|--------------------|
| π **Detector** | Classifies distress 1β5 from free text | β |
| π¬ **Empathy** | Generates responses (DPO fine-tuned on psychiatrist preferences) | β |
| π¨ **Crisis Escalator** | Routes to human counselor (10x FN penalty) | β |
| π **Oversight** | Monitors all agents for contradictions in real time | Fleet AI |
| π **Curriculum** | Auto-generates harder episodes when agents plateau | Snorkel AI |
---
## Self-Improvement Loop
```
Episode β Reward β Curriculum tracks rolling avg
β
improvement < 2% over 50 episodes?
YES βββββββββββββββββββββββββββΆ harder episodes generated
NO βββββββββββββββββββββββββββΆ continue current difficulty
β
DPO fine-tune empathy agent
on psychiatrist preference pairs
(preferences shift each epoch β
satisfies Snorkel AI requirement)
β
LoRA adapters updated via GRPO
```
---
## Training Results
> β οΈ _Placeholder β replace with real numbers and plots after onsite training April 25._

_Fig 1. Composite reward, detection F1, and DPO win-rate over 500 training episodes (baseline vs trained on same axes)._
| Metric | Baseline (untrained) | After training |
|--------|---------------------|----------------|
| Detection F1 | 0.61 | β |
| Escalation Precision | 0.71 | β |
| DPO Win-Rate vs baseline | 51% | β |
| Avg Composite Reward | 0.35 | β |
---
## Hackathon Theme Coverage
| Theme | Coverage |
|-------|----------|
| Theme 1 β Multi-Agent Interactions | β
5 agents cooperating, competing, overriding each other |
| Theme 3 β World Modeling (Personalized) | β
Dynamic patient world across multi-session POMDP |
| Theme 4 β Self-Improvement | β
Curriculum self-play + DPO adaptation per epoch |
| Theme 5 β Wild Card | β
First mental health crisis RL environment |
**Bonus prizes targeted:** Fleet AI Β· Snorkel AI Β· Halluminate
---
## Run Locally
```bash
git clone https://huggingface.co/spaces/mesazephyr/psycheos
cd psycheos
pip install -r requirements.txt
streamlit run app/streamlit_app.py
```
## Train (onsite with HF compute credits)
```bash
# GRPO training loop
python training/grpo_train.py --episodes 1000 --epochs 3
# DPO fine-tuning β empathy agent
python training/dpo_finetune.py
# Evaluate + generate reward curve plots
python eval/reward_curves.py
```
---
## Repository Structure
```
psycheos/
βββ openenv.yaml β OpenEnv manifest (required by judges)
βββ README.md β This file
βββ requirements.txt
βββ app/
β βββ streamlit_app.py β Live browser UI
βββ environment/
β βββ psycheos_env.py β OpenEnv POMDP environment
βββ agents/
β βββ agents.py β All 5 agent implementations
β βββ graph.py β LangGraph state machine
βββ memory/
β βββ faiss_store.py β FAISS + RAG cross-session memory
βββ reward/
β βββ reward_functions.py β 5 composable reward signals
βββ training/
β βββ grpo_train.py β GRPO training loop
β βββ dpo_finetune.py β DPO fine-tuning script
β βββ colab_training.ipynb β Runnable Colab notebook
βββ eval/
β βββ reward_curves.py β Evaluation + matplotlib plots
βββ plots/
βββ reward_curves.png β Added after training
```
---
## Technical Stack
| Layer | Tech |
|-------|------|
| Environment | OpenEnv + Gymnasium POMDP |
| Agents | LangGraph state machine |
| Memory | FAISS + sentence-transformers RAG |
| Training | GRPO Β· HuggingFace TRL Β· Unsloth |
| Adapters | LoRA (r=16) Β· 4-bit quantization |
| Self-improvement | DPO on psychiatrist preferences + curriculum self-play |
| UI | Streamlit Β· live agent activations |
---
*PsycheOS β Mesa Sarah Vasantha Zephyr β mesazephyr1516@gmail.com*
|