BREATHE / README.md
tannuiscoding's picture
updated readme
3782d65
metadata
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

  1. Fork the repo
  2. Create a feature branch: git checkout -b feat/my-feature
  3. Commit your changes: git commit -m "feat: add my feature"
  4. Push and open a Pull Request

πŸ“„ License

MIT β€” see LICENSE for details.