An AI-powered real-time focus monitor that detects phone use, tracks your attention, and sounds an alarm when you lose focus โ all from your webcam.
Anti-Doomscroll Trap uses your webcam, state-of-the-art YOLOv8 object detection, and Haar cascade face/eye tracking to monitor whether you are focused on your work or distracted by your phone.
When you pick up your phone or look away too long, a focus health bar drains. If it stays low for more than 5 seconds (configurable), an audio alarm fires to snap you back to reality.
Everything runs locally on your PC โ no cloud, no subscription, no data collection.
| Feature | Description |
|---|---|
| ๐ฑ Phone Detection | YOLOv8 identifies a phone in your hand in real-time |
| ๐ Book Detection | Detects reading and rewards it with health regeneration |
| ๐๏ธ Eye Tracking | Haar cascades verify your eyes are on the screen |
| ๐ Focus Health Bar | Visual health bar that drains when you're distracted |
| ๐ Audio Alarm | Plays your chosen MP3 alarm when focus stays low |
| โก High FPS | Multi-threaded design keeps camera feed smooth (~30 FPS) |
| โ๏ธ Configurable | All thresholds editable via config/settings.yaml |
| ๐ Logging | Full session logs written to logs/app.log |
anti-doomscroll-trap/
โ
โโโ main.py โ Entry point โ run this to start
โ
โโโ src/ โ Core application modules
โ โโโ __init__.py
โ โโโ detector.py โ DetectionEngine (YOLO + face/eye)
โ โโโ focus_state.py โ FocusState machine (health, alarm logic)
โ โโโ audio_manager.py โ AudioManager (pygame alarm control)
โ โโโ hud.py โ HUD renderer (all on-screen overlays)
โ โโโ config_loader.py โ YAML config loader with defaults
โ
โโโ config/
โ โโโ settings.yaml โ All user-configurable settings
โ
โโโ assets/
โ โโโ README.md โ Instructions for adding alarm.mp3
โ โโโ alarm.mp3 โ Your alarm sound (add this yourself!)
โ
โโโ logs/
โ โโโ app.log โ Auto-generated session log
โ
โโโ requirements.txt โ Python dependencies
โโโ .gitignore
โโโ README.md โ You are here
- Python 3.9 or newer โ Download here
- A working webcam
- An MP3 or WAV alarm sound file
Option A: Git clone (recommended)
git clone https://github.com/YOUR_USERNAME/anti-doomscroll-trap.git
cd anti-doomscroll-trapOption B: Download ZIP
- Click the green Code button on GitHub โ Download ZIP
- Extract the ZIP
- Open a terminal and
cdinto the folder
This keeps dependencies isolated from your system Python.
Windows:
python -m venv venv
venv\Scripts\activatemacOS / Linux:
python3 -m venv venv
source venv/bin/activateYou should see (venv) at the start of your terminal prompt.
pip install -r requirements.txtโณ This may take 2โ5 minutes the first time (ultralytics + opencv are large).
- Find a free alarm MP3 from freesound.org or mixkit.co
- Rename it to
alarm.mp3 - Place it in the
assets/folder
python main.pyThe YOLOv8 model (yolov8n.pt) will auto-download (~6 MB) on the first run.
Optional: custom config or camera
python main.py --config config/settings.yaml
python main.py --camera 1 # use second webcamPress q to quit at any time.
All settings are in config/settings.yaml. Open it with any text editor:
alarm_file: "assets/alarm.mp3" # path to your alarm sound
alarm_threshold: 50 # health % that starts the timer
alarm_delay: 5.0 # seconds before alarm fires
yolo_interval: 0.5 # YOLO check frequency (seconds)
camera_index: 0 # 0 = default webcam
model_path: "yolov8n.pt" # YOLO model size
log_level: "INFO" # DEBUG | INFO | WARNING | ERRORCamera Frame
โ
โโโถ [YOLO Thread] โ runs every 0.5s in background
โ โโโ Detects: phone, book
โ
โโโถ [Face Cascade] โ runs every frame (fast)
โ โโโ Detects: face + eyes
โ
โโโถ [Focus State Machine]
โ
โโโ Eyes found? โ Health +20, status = Focused
โโโ Phone detected? โ Health = 0, status = DOOMSCROLLING
โโโ Book detected? โ Health +10, status = Reading
โโโ None? โ Health -5, status = Looking away
โ
โโโ Health < 50 for > 5s? โ ๐ ALARM!
| Problem | Solution |
|---|---|
[ERROR] Alarm file not found |
Add alarm.mp3 to the assets/ folder |
| Camera won't open | Try python main.py --camera 1 (or 2, 3โฆ) |
| Very slow / low FPS | Lower frame_width/frame_height in settings.yaml, or use yolov8n.pt |
| Phone not detected | Ensure good lighting; hold the phone clearly facing the camera |
| Eyes not detected | Make sure your face is well-lit and not at extreme angles |
ModuleNotFoundError |
Run pip install -r requirements.txt inside your virtual environment |
| Alarm won't stop | Press q to quit, or cover your eyes and look back at screen |
- Web Dashboard โ React frontend showing session stats and charts
- Session History โ SQLite database logging daily focus scores
- Multiple Faces โ Track focus for several people simultaneously
- Screen Time Reports โ PDF/CSV export of weekly focus analytics
- Posture Detection โ Mediapipe-based bad-posture alert
- Custom Wake Words โ Voice command to temporarily pause alarm
- Tray Icon โ Run minimised in the system tray (Windows/Mac)
- Mobile App โ React Native companion for phone-side notifications
| Package | Version | Purpose |
|---|---|---|
opencv-python |
โฅ 4.8 | Camera capture, Haar cascades, display |
ultralytics |
โฅ 8.0 | YOLOv8 object detection |
pygame |
โฅ 2.5 | Alarm audio playback |
PyYAML |
โฅ 6.0 | YAML config file parsing |
MIT License โ free to use, modify, and distribute.
- Ultralytics YOLOv8 โ Object detection backbone
- OpenCV โ Computer vision framework
- pygame โ Audio playback
Built with โค๏ธ to help you stay focused and off your phone.