<<<<<<< HEAD
AI-Powered Cognitive Fatigue Detection & Wellness System
Mind-Shield+ is an intelligent desktop application that monitors your behavioral interaction patterns in real-time to estimate cognitive load, predict mental fatigue, detect behavioral drift, and monitor posture. It provides proactive wellness interventions before fatigue impacts your health and productivity.
- π₯οΈ Real-Time Monitoring: Captures keyboard, mouse, and system activity in real-time
- π§ Fatigue Prediction: ML-powered fatigue probability estimation using Random Forest
- π Cognitive Load Scoring: Weighted multi-factor mental effort calculation
- π Behavioral Drift Detection: Isolation Forest algorithm detects deviation from baseline
- π§ Posture Detection: Webcam-based posture monitoring with skeleton overlay (MediaPipe)
- π― Focus AI Mode: Pomodoro-style deep work sessions with distraction detection
- π Real-Time Dashboard: Live graphs, metrics, and recommendations
- π‘ Smart Recommendations: Contextual break and wellness suggestions
EDI_Project/
βββ mindshield.py # Main desktop application (GUI)
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ PROJECT_DOCUMENTATION.md # Detailed technical documentation
βββ .venv/ # Virtual environment
βββ src/
βββ __init__.py # Package initialization
βββ data_simulation.py # Synthetic data for model training
βββ feature_engineering.py # Feature extraction and transformation
βββ cognitive_load.py # Cognitive load scoring algorithm
βββ fatigue_model.py # Random Forest fatigue prediction
βββ anomaly_detection.py # Isolation Forest drift detection
βββ risk_evaluation.py # Integrated risk assessment engine
βββ posture_detection.py # MediaPipe webcam posture analysis
βββ visualization.py # Plotting and dashboards
βββ pose_landmarker_lite.task # MediaPipe pose model
βββ main.py # Console demonstration script
- Python 3.10 or newer
- Webcam (optional, for posture detection)
-
Clone or download the project
-
Create and activate virtual environment:
# Create virtual environment
python -m venv .venv
# Activate (Windows)
.\.venv\Scripts\Activate.ps1
# Activate (Linux/macOS)
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt
# For posture detection (optional but recommended)
pip install mediapipe opencv-python pillow# Activate virtual environment first
.\.venv\Scripts\Activate.ps1
# Run the application
python mindshield.pyOr directly with venv Python:
.\.venv\Scripts\python.exe mindshield.pyFeatures:
- Real-time behavioral monitoring (typing speed, mouse velocity, errors)
- Live fatigue probability display with risk levels
- Dynamic cognitive load estimation
- Focus AI Mode with distraction detection
- Posture monitoring with webcam preview
- Smart break reminders and recommendations
- Session analytics and graphs
cd src
python main.pyThis will:
- Generate synthetic behavioral data (for model training)
- Extract cognitive features
- Train fatigue prediction models
- Run behavioral drift detection
- Estimate cognitive load
- Evaluate integrated risk
- Simulate a 90-minute work session
- Generate visualization outputs
# Test fatigue prediction model
python src/fatigue_model.py
# Test anomaly detection
python src/anomaly_detection.py
# Test cognitive load estimator
python src/cognitive_load.py
# Generate synthetic training data
python src/data_simulation.py| Variable | Description | Normal | Fatigued |
|---|---|---|---|
| Typing Speed | Keystrokes per minute | ~60 WPM | ~35 WPM |
| Typing Delay | Time between keystrokes (ms) | ~120ms | ~200ms |
| Backspace Rate | Error correction frequency | ~5% | ~15% |
| Tab Switch Rate | Context switches per minute | ~2/min | ~5/min |
| Mouse Velocity | Navigation speed (px/s) | ~500 | ~300 |
| Idle Time | Pause duration (seconds) | ~3s | ~8s |
| Posture Score | Webcam posture analysis | 85-100 | <70 |
- Algorithm: Random Forest Classifier (100 trees)
- Input: Typing speed, error rate, mouse velocity, idle time, etc.
- Output: Probability of fatigue (0-100%)
- Performance: ~92% accuracy, ~97% ROC AUC
- Algorithm: Isolation Forest (unsupervised)
- Input: Current behavioral features
- Output: Anomaly score indicating deviation from baseline
- Use: Detects when behavior significantly changes
- Algorithm: Multi-factor weighted combination
- Components: Typing load (25%), Error load (25%), Attention (20%), Idle (15%), Engagement (15%)
- Output: Cognitive load score (0-100)
- Algorithm: MediaPipe PoseLandmarker + geometric analysis
- Input: Webcam frames
- Output: Posture score, detected issues (head tilt, slouching, etc.)
| Level | Score Range | Action |
|---|---|---|
| π’ Low | 0-25 | Continue working normally |
| π‘ Moderate | 26-50 | Consider a short break |
| π High | 51-75 | Take a break soon |
| π΄ Critical | 76-100 | Immediate break recommended |
Dedicated deep work mode with:
- Configurable timer (default: 25 minutes)
- Distraction detection (YouTube, Facebook, Twitter, etc.)
- Focus score based on concentration quality
- Session history and statistics
- Auto-start monitoring when focus begins
Real-time webcam-based posture monitoring:
- Head tilt detection (>12Β° threshold)
- Slouching detection (>15Β° deviation)
- Forward head posture detection
- Uneven shoulders detection
- Skeleton overlay on video preview
- Smoothed readings to reduce jitter
| Package | Purpose |
|---|---|
| pynput | Keyboard and mouse monitoring |
| psutil | System and process information |
| numpy | Numerical computations |
| pandas | Data manipulation |
| scikit-learn | Machine learning models |
| tkinter | Desktop GUI (included with Python) |
| mediapipe | Pose detection (optional) |
| opencv-python | Webcam capture (optional) |
| pillow | Image processing (optional) |
For detailed technical information including:
- Algorithm explanations
- Code architecture
- Module-by-module breakdown
- Future enhancements
- Patent potential
This project is developed for educational and research purposes.
AI-Powered Cognitive Fatigue Detection & Wellness System
Mind-Shield+ is an intelligent desktop application that monitors your behavioral interaction patterns in real-time to estimate cognitive load, predict mental fatigue, detect behavioral drift, and monitor posture. It provides proactive wellness interventions before fatigue impacts your health and productivity.
- π₯οΈ Real-Time Monitoring: Captures keyboard, mouse, and system activity in real-time
- π§ Fatigue Prediction: ML-powered fatigue probability estimation using Random Forest
- π Cognitive Load Scoring: Weighted multi-factor mental effort calculation
- π Behavioral Drift Detection: Isolation Forest algorithm detects deviation from baseline
- π§ Posture Detection: Webcam-based posture monitoring with skeleton overlay (MediaPipe)
- π― Focus AI Mode: Pomodoro-style deep work sessions with distraction detection
- π Real-Time Dashboard: Live graphs, metrics, and recommendations
- π‘ Smart Recommendations: Contextual break and wellness suggestions
EDI_Project/
βββ mindshield.py # Main desktop application (GUI)
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ Project_Documentation.md # Detailed technical documentation
βββ .venv/ # Virtual environment
βββ src/
βββ __init__.py # Package initialization
βββ data_simulation.py # Synthetic data for model training
βββ feature_engineering.py # Feature extraction and transformation
βββ cognitive_load.py # Cognitive load scoring algorithm
βββ fatigue_model.py # Random Forest fatigue prediction
βββ anomaly_detection.py # Isolation Forest drift detection
βββ risk_evaluation.py # Integrated risk assessment engine
βββ posture_detection.py # MediaPipe webcam posture analysis
βββ presence_auth.py # Local face auth + presence validation
βββ visualization.py # Plotting and dashboards
βββ pose_landmarker_lite.task # MediaPipe pose model
βββ main.py # Console demonstration script
- Python 3.10 or newer
- Webcam (optional, for posture detection)
-
Clone or download the project
-
Create and activate virtual environment:
# Create virtual environment
python -m venv .venv
# Activate (Windows)
.\.venv\Scripts\Activate.ps1
# Activate (Linux/macOS)
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt
# For posture detection (optional but recommended)
pip install mediapipe opencv-python pillow# Activate virtual environment first
.\.venv\Scripts\Activate.ps1
# Run the application
python mindshield.pyOr directly with venv Python:
.\.venv\Scripts\python.exe mindshield.pyFeatures:
- Real-time behavioral monitoring (typing speed, mouse velocity, errors)
- Live fatigue probability display with risk levels
- Dynamic cognitive load estimation
- Focus AI Mode with distraction detection
- Posture monitoring with webcam preview
- Smart break reminders and recommendations
- Session analytics and graphs
Local Face Auth verifies the enrolled user and also checks that the same face stays in the usual seat position.
What it enforces:
- One enrolled face per profile name.
- Single face in view (multiple faces = lock).
- Seat position check (face center + size must match enrollment).
- Local-only encrypted embeddings. No raw video stored.
Enrollment steps:
- Start Mind-Shield+.
- Click Posture to start the webcam (or enable Local Face Auth and it will start for you).
- Sit in your normal position and make sure only your face is visible.
- Enter a profile name and click Enroll when the preview is steady.
- Enable Local Face Auth to lock/unlock monitoring based on presence.
If no profile exists, enabling face auth will prompt you to enroll first.
Flowchart: See face_auth_flow.svg.
cd src
python main.pyThis will:
- Generate synthetic behavioral data (for model training)
- Extract cognitive features
- Train fatigue prediction models
- Run behavioral drift detection
- Estimate cognitive load
- Evaluate integrated risk
- Simulate a 90-minute work session
- Generate visualization outputs
# Test fatigue prediction model
python src/fatigue_model.py
# Test anomaly detection
python src/anomaly_detection.py
# Test cognitive load estimator
python src/cognitive_load.py
# Generate synthetic training data
python src/data_simulation.pypython src/api_server.pyHealth check: http://127.0.0.1:8000/health
| Variable | Description | Normal | Fatigued |
|---|---|---|---|
| Typing Speed | Keystrokes per minute | ~60 WPM | ~35 WPM |
| Typing Delay | Time between keystrokes (ms) | ~120ms | ~200ms |
| Backspace Rate | Error correction frequency | ~5% | ~15% |
| Tab Switch Rate | Context switches per minute | ~2/min | ~5/min |
| Mouse Velocity | Navigation speed (px/s) | ~500 | ~300 |
| Idle Time | Pause duration (seconds) | ~3s | ~8s |
| Posture Score | Webcam posture analysis | 85-100 | <70 |
- Algorithm: Random Forest Classifier (100 trees)
- Input: Typing speed, error rate, mouse velocity, idle time, etc.
- Output: Probability of fatigue (0-100%)
- Performance: ~92% accuracy, ~97% ROC AUC
- Algorithm: Isolation Forest (unsupervised)
- Input: Current behavioral features
- Output: Anomaly score indicating deviation from baseline
- Use: Detects when behavior significantly changes
- Algorithm: Multi-factor weighted combination
- Components: Typing load (25%), Error load (25%), Attention (20%), Idle (15%), Engagement (15%)
- Output: Cognitive load score (0-100)
- Algorithm: MediaPipe PoseLandmarker + geometric analysis
- Input: Webcam frames
- Output: Posture score, detected issues (head tilt, slouching, etc.)
| Level | Score Range | Action |
|---|---|---|
| π’ Low | 0-25 | Continue working normally |
| π‘ Moderate | 26-50 | Consider a short break |
| π High | 51-75 | Take a break soon |
| π΄ Critical | 76-100 | Immediate break recommended |
Dedicated deep work mode with:
- Configurable timer (default: 25 minutes)
- Distraction detection (YouTube, Facebook, Twitter, etc.)
- Focus score based on concentration quality
- Session history and statistics
- Auto-start monitoring when focus begins
Real-time webcam-based posture monitoring:
- Head tilt detection (>12Β° threshold)
- Slouching detection (>15Β° deviation)
- Forward head posture detection
- Uneven shoulders detection
- Skeleton overlay on video preview
- Smoothed readings to reduce jitter
| Package | Purpose |
|---|---|
| pynput | Keyboard and mouse monitoring |
| psutil | System and process information |
| numpy | Numerical computations |
| pandas | Data manipulation |
| scikit-learn | Machine learning models |
| tkinter | Desktop GUI (included with Python) |
| mediapipe | Pose detection (optional) |
| opencv-python | Webcam capture (optional) |
| pillow | Image processing (optional) |
- All paths are resolved relative to the project root at runtime.
- To override the MediaPipe pose model location, set
MINDSHIELD_POSE_MODELto a custom path.
For detailed technical information including:
- Algorithm explanations
- Code architecture
- Module-by-module breakdown
- Future enhancements
- Patent potential
This project is developed for educational and research purposes.
Mind-Shield+ Team
c1412b8 (updated)