Skip to content

Heer12354/anti-doomscroll-trap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

21 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšซ๐Ÿ“ฑ Anti-Doomscroll Trap

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.

Python OpenCV YOLOv8 License


๐Ÿ“– Description

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.


โœจ Features

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

๐Ÿ—‚ Folder Structure

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

๐Ÿš€ Installation (Step-by-Step)

Prerequisites

  • Python 3.9 or newer โ€” Download here
  • A working webcam
  • An MP3 or WAV alarm sound file

Step 1 โ€” Clone or Download the Project

Option A: Git clone (recommended)

git clone https://github.com/YOUR_USERNAME/anti-doomscroll-trap.git
cd anti-doomscroll-trap

Option B: Download ZIP

  1. Click the green Code button on GitHub โ†’ Download ZIP
  2. Extract the ZIP
  3. Open a terminal and cd into the folder

Step 2 โ€” Create a Virtual Environment

This keeps dependencies isolated from your system Python.

Windows:

python -m venv venv
venv\Scripts\activate

macOS / Linux:

python3 -m venv venv
source venv/bin/activate

You should see (venv) at the start of your terminal prompt.


Step 3 โ€” Install Dependencies

pip install -r requirements.txt

โณ This may take 2โ€“5 minutes the first time (ultralytics + opencv are large).


Step 4 โ€” Add Your Alarm Sound

  1. Find a free alarm MP3 from freesound.org or mixkit.co
  2. Rename it to alarm.mp3
  3. Place it in the assets/ folder

Step 5 โ€” Run the App

python main.py

The 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 webcam

Press q to quit at any time.


โš™๏ธ Configuration

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 | ERROR

๐ŸŽฎ How It Works

Camera 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!

๐Ÿ›  Troubleshooting

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

๐Ÿ”ฎ Future Improvements

  • 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

๐Ÿ“ฆ Dependencies

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

๐Ÿ“„ License

MIT License โ€” free to use, modify, and distribute.


๐Ÿ™ Credits


Built with โค๏ธ to help you stay focused and off your phone.

About

๐Ÿšซ๐Ÿ“ฑ AI-powered focus monitor that uses YOLOv8 + webcam to detect phone use, track eye attention, and sound an alarm when you lose focus. Built with Python, OpenCV & multi-threading for smooth real-time performance. Stay focused, stop doomscrolling!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages