Spaces:
Running
title: BREATHE
emoji: π«
colorFrom: blue
colorTo: indigo
sdk: docker
app_file: app.py
pinned: false
π« BREATHE
Stress Intelligence Platform β understand your stress before it controls you.
BREATHE is a full-stack web app that fuses psychometric lifestyle data and free-text journaling through an ML pipeline to give you a personalised stress score, trend charts, and actionable advice β all in a clean, dark-themed React dashboard.
β¨ Features
Core
- Secure auth β sign up / log in with hashed passwords and server-side sessions
- Psychometric assessment β 12 lifestyle sliders (sleep, work hours, screen time, caffeine β¦) + 4 categorical cues
- Text journaling β write freely; RoBERTa NLP analyses the sentiment
- ML fusion β tabular ensemble (LightGBM / CatBoost / XGBoost / Stacking) + RoBERTa β weighted probability fusion β 5-class stress output
- Demo mode β app runs fully with rule-based heuristics when ML model files are absent
Dashboard
- Area timeline chart of stress scores
- Pie distribution of stress levels
- Stat cards (total assessments, latest level, average score, trend)
- Recent assessments with per-assessment detail modal
- Stress relief activity panel (accordion)
Profile
- Upload a profile photo (JPG/PNG/GIF/WebP, max 2 MB)
- Set gender, working status, and date of birth
- Write a short bio
- Anonymous mode β toggle to hide your name in shared/exported views
Gratitude Journal
- Write 3 prompted daily gratitude items + optional mood tag + free-text reflection
- All entries saved to your account with timestamps
- Paginated history view with expand/collapse and per-entry delete
Daily To-Do
- Add tasks with High / Medium / Low priority
- Filter by All / Active / Done; bulk-clear completed tasks
- Stored in browser localStorage only β never sent to the server
Breathe Hub
- Full-screen activity centre (no sidebar) β opens on login
- 6 activity cards: Gratitude Journal, Box Breathing, Daily To-Do, Body Scan, Sound Bath, Progressive Relaxation
- Guided exercise modal with step-through progress dots for breathing and relaxation exercises
- Quick nav buttons to Dashboard and Profile
π₯οΈ Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 18, Vite 5, React Router v6, Recharts 2 |
| Backend | Python 3.10+, Flask 3, Flask-SQLAlchemy |
| Database | SQLite (dev) / PostgreSQL (prod) |
| Auth | Server-side sessions, Werkzeug password hashing |
| ML β Tabular | LightGBM / CatBoost / XGBoost / Stacking ensemble |
| ML β Text | RoBERTa-base fine-tuned on mental-health dataset |
| ML β Fusion | Weighted probability fusion β Minimal / Mild / Moderate / Severe / Critical |
π Quick Start
Full instructions are in SETUP.md. This is the short version.
Prerequisites
- Python β₯ 3.10
- Node.js β₯ 18 + npm β₯ 9
1 β Install Python deps
cd breathe-app
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\Activate.ps1
pip install -r requirements.txt
2 β Configure environment
cp .env.example .env
# edit .env β set SECRET_KEY at minimum
3 β Install frontend deps
cd frontend && npm install && cd ..
3.1 β Docker deployment support
This repo includes a root-level Dockerfile so you can build the app as a single container for Hugging Face Spaces or any Docker host.
4 β Run (two terminals)
Terminal 1 β Flask API (port 5000)
source venv/bin/activate
python app.py
Terminal 2 β React dev server (port 5173)
cd frontend
npm run dev
Open http://localhost:5173 β after login you land on the Breathe hub π
π Project Structure
breathe-app/
βββ app.py # WSGI entry-point
βββ requirements.txt
βββ .env.example
βββ backend/
β βββ __init__.py # Flask app factory
β βββ models/
β β βββ user.py # User ORM (incl. profile fields)
β β βββ assessment.py # Assessment ORM
β β βββ gratitude.py # GratitudeEntry ORM
β βββ routes/
β β βββ auth.py # /api/auth/*
β β βββ assessments.py # /api/assessments/*
β β βββ profile.py # /api/profile/*
β β βββ gratitude.py # /api/gratitude/*
β βββ ml/ml_engine.py # Inference wrapper + demo fallback
βββ frontend/
β βββ vite.config.js # Proxies /api β Flask :5000
β βββ src/
β βββ pages/
β β βββ LandingPage.jsx
β β βββ AuthPage.jsx
β β βββ BreathePage.jsx # Activity hub (post-login home)
β β βββ DashboardPage.jsx
β β βββ AssessPage.jsx
β β βββ HistoryPage.jsx
β β βββ ProfilePage.jsx
β β βββ GratitudePage.jsx
β β βββ TodoPage.jsx
β βββ components/Layout.jsx # Sidebar shell
β βββ context/AuthContext.jsx
β βββ api/client.js # Fetch wrapper (get/post/put/del)
βββ models/
β βββ psychometric/ # .pkl files from notebook
β βββ text/ # roberta-model.pt
βββ instance/
βββ breathe.db # SQLite DB (auto-created)
π§ ML Pipeline
Lifestyle cues (12 numeric + 4 categorical)
β
βΌ
Feature engineering (PolynomialFeatures, scaling, label encoding)
β
βΌ
Stacking ensemble βββββββββββββββββββββββββββββββ
(LightGBM + CatBoost + XGBoost + RF + MLP) β
β β
βΌ βΌ
psycho_score (0β1) text_score (0β1) β RoBERTa fine-tuned
β β
βββββββββββββ fusion (50/50) ββββββββββββββββ
β
βΌ
fused_score β stress label
[Minimal | Mild | Moderate | Severe | Critical]
The engine falls back to Demo mode (rule-based heuristics) if model files are missing.
π API Reference
Auth
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/signup |
Register (username, email, password) |
| POST | /api/auth/login |
Login (email or username, password) |
| POST | /api/auth/logout |
Logout |
| GET | /api/auth/me |
Current user |
Assessments
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/assessments |
Submit assessment |
| GET | /api/assessments |
List (paginated ?page=1&per_page=20) |
| GET | /api/assessments/<id> |
Single assessment |
| GET | /api/assessments/summary |
Dashboard data + timeline |
Profile
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/profile |
Get current profile |
| PUT | /api/profile |
Update bio, gender, working status, DOB, anonymous flag |
| POST | /api/profile/avatar |
Upload / remove avatar (base64 data-url) |
Gratitude Journal
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/gratitude |
Save entry (items[], content, mood) |
| GET | /api/gratitude |
List entries (paginated ?page=1) |
| DELETE | /api/gratitude/<id> |
Delete entry |
πΊοΈ Page Routes
| URL | Page | Auth |
|---|---|---|
/ |
Landing page | Public |
/auth |
Login / Signup | Public |
/app/breathe |
Breathe hub (post-login home) | Protected |
/app/dashboard |
Stress dashboard | Protected |
/app/assess |
New assessment | Protected |
/app/history |
Assessment history | Protected |
/app/profile |
User profile | Protected |
/app/gratitude |
Gratitude journal | Protected |
/app/todo |
Daily to-do list | Protected |
π¦ Production Build
# Build React bundle (output β frontend/dist/)
cd frontend && npm run build && cd ..
# Flask auto-serves frontend/dist/ β no Node process needed
gunicorn "app:app" --workers 2 --bind 0.0.0.0:5000 --timeout 120
π License
MIT β see LICENSE for details.
π₯οΈ Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 18, Vite 5, React Router v6, Recharts 2 |
| Backend | Python 3.10+, Flask 3, Flask-SQLAlchemy |
| Database | SQLite (dev) / PostgreSQL (prod) |
| Auth | Server-side sessions, Werkzeug password hashing |
| ML β Tabular | LightGBM / CatBoost / XGBoost / Stacking ensemble |
| ML β Text | RoBERTa-base fine-tuned on mental-health dataset |
| ML β Fusion | Weighted probability fusion β Minimal / Mild / Moderate / Severe / Critical |
π Quick Start
Full instructions are in SETUP.md. This is the short version.
Prerequisites
- Python β₯ 3.10
- Node.js β₯ 18 + npm β₯ 9
1 β Install Python deps
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\Activate.ps1
pip install -r requirements.txt
2 β Configure environment
cp .env.example .env
# edit .env β set SECRET_KEY at minimum
3 β Install frontend deps
cd frontend && npm install && cd ..
3.1 β Docker deployment support
This repo includes a root-level Dockerfile so you can build the app as a single container for Hugging Face Spaces or any Docker host.
4 β Run (two terminals)
Terminal 1 β Flask API
source venv/bin/activate
python app.py
Terminal 2 β React dev server
cd frontend
npm run dev
Open http://localhost:5173 π
π Project Structure
breathe-app/
βββ app.py # WSGI entry-point
βββ requirements.txt
βββ .env.example
βββ backend/
β βββ __init__.py # Flask app factory
β βββ models/ # SQLAlchemy ORM models
β βββ routes/ # Auth + Assessment API blueprints
β βββ ml/ml_engine.py # Inference wrapper + demo fallback
βββ frontend/
β βββ vite.config.js # Proxies /api β Flask :5000
β βββ src/
β βββ pages/ # AuthPage, DashboardPage, AssessPage, HistoryPage
β βββ components/ # Layout (sidebar shell)
β βββ context/ # AuthContext
β βββ api/client.js # Fetch wrapper
βββ models/
β βββ psychometric/ # .pkl files from notebook
β βββ text/ # roberta-model.pt
βββ notebooks/ # Original Jupyter notebooks
π§ ML Pipeline
Lifestyle cues (12 numeric + 4 categorical)
β
βΌ
Feature engineering (PolynomialFeatures, scaling, label encoding)
β
βΌ
Stacking ensemble βββββββββββββββββββββββββββββββ
(LightGBM + CatBoost + XGBoost + RF + MLP) β
β β
βΌ βΌ
psycho_score (0β1) text_score (0β1) β RoBERTa fine-tuned
β β
βββββββββββββ fusion (50/50) ββββββββββββββββ
β
βΌ
fused_score β stress label
[Minimal | Mild | Moderate | Severe | Critical]
The engine falls back to Demo mode (rule-based heuristics) if model files are missing β the full UI still works.
π API Reference
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/signup |
Register (username, email, password) |
| POST | /api/auth/login |
Login (email or username, password) |
| POST | /api/auth/logout |
Logout |
| GET | /api/auth/me |
Current user |
| POST | /api/assessments |
Submit assessment |
| GET | /api/assessments |
List (paginated) |
| GET | /api/assessments/<id> |
Single assessment |
| GET | /api/assessments/summary |
Dashboard data |
π¦ Production Build
# Build React bundle (output β frontend/dist/)
cd frontend && npm run build && cd ..
# Flask auto-serves frontend/dist/ β no Node process needed
gunicorn "app:app" --workers 2 --bind 0.0.0.0:5000 --timeout 120
π€ Contributing
- Fork the repo
- Create a feature branch:
git checkout -b feat/my-feature - Commit your changes:
git commit -m "feat: add my feature" - Push and open a Pull Request
π License
MIT β see LICENSE for details.