Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

65 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AttendAI πŸŽ“

AI-powered face recognition attendance system built for the NIST University Smart Campus initiative.

Python Flask OpenCV Supabase MediaPipe License


πŸ“Œ Overview

AttendAI automates student attendance using real-time face recognition. Faculty start a class session, the system auto-scans faces continuously via browser webcam, and attendance is marked instantly β€” no manual effort, no proxy attendance possible.

Built as part of the NIST University AI-Enabled Smart Campus Project under the Department of Computer Science & Engineering.


✨ Features

  • πŸŽ₯ Browser-based webcam capture β€” no server camera required, works on any deployment
  • πŸ‘οΈ Liveness detection β€” MediaPipe blink detection prevents photo/screen spoofing
  • πŸ”„ Auto-continuous scanning β€” scans every 3 seconds, marks entire class without manual clicks
  • πŸ‘€ 20-frame face registration β€” captures multiple angles for better recognition accuracy
  • πŸ” bcrypt password hashing β€” secure auth for Admin, Faculty, and Student roles
  • ⚑ Optimized model loading β€” LBPH model loads once at startup, not on every scan
  • πŸ” Auto-retrain β€” model retrains automatically after every new student registration
  • πŸ“Š Analytics dashboard β€” attendance stats by department and subject
  • πŸ“₯ CSV export β€” download attendance reports as Excel-compatible CSV
  • πŸ—‚οΈ Role-based access β€” Admin, Faculty, Student with separate dashboards
  • ☁️ Supabase cloud database β€” no local DB setup, works from anywhere
  • 🌐 Environment-based config β€” no hardcoded credentials, uses .env
  • πŸ“§ Low attendance email alerts β€” automatic email notifications for students below attendance threshold (requires SMTP credentials)

πŸ› οΈ Tech Stack

Layer Technology
Backend Python, Flask 3.x
Face Detection OpenCV (Haar Cascade)
Face Recognition LBPH (Local Binary Patterns Histograms)
Liveness Detection MediaPipe Face Mesh (Eye Aspect Ratio)
Frontend HTML, CSS, JavaScript (getUserMedia API)
Database Supabase (PostgreSQL)
Auth bcrypt, Flask Session
Config python-dotenv

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Webcam
  • Supabase account (free at supabase.com)

Installation

# Clone the repo
git clone https://github.com/Subham503/AttendAI.git
cd AttendAI

# Install dependencies
pip install flask opencv-contrib-python bcrypt numpy python-dotenv 
pip install flask opencv-contrib-python bcrypt numpy python-dotenv supabase

Contributor Notes

Contributors do not require production credentials.

For local development:

  • Create your own .env
  • Use personal SMTP credentials for testing email alerts
  • If mail credentials are absent, email functionality remains disabled

Production credentials are intentionally not committed to the repository.


Environment Variables

Create a .env file in the root directory:

SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_service_role_key
SECRET_KEY=your_flask_secret_key
SESSION_TIMEOUT_MINUTES=30

# Email alerts (required for attendance warning emails)
MAIL_USERNAME=your_email@gmail.com
MAIL_PASSWORD=your_gmail_app_password
  • FLASK_DEBUG=true β†’ runs in debug mode (local development only)
  • FLASK_DEBUG=false β†’ runs in production mode (safe default)

Notes:

  • MAIL_USERNAME should be a Gmail account used for sending alerts.
  • MAIL_PASSWORD must be a Gmail App Password, not your normal Gmail password.
  • Email alert functionality remains disabled if mail credentials are not configured.
  • Contributors without SMTP credentials can still run the project normally.

### Database Setup

Go to Supabase Dashboard β†’ SQL Editor β†’ Run:

```sql
CREATE TABLE students (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100),
  reg_no VARCHAR(50) UNIQUE,
  department VARCHAR(50),
  class VARCHAR(50),
  password VARCHAR(255),
  email VARCHAR(255)
);

CREATE TABLE attendance (
  id SERIAL PRIMARY KEY,
  student_id INT REFERENCES students(id),
  name VARCHAR(100),
  department VARCHAR(50),
  class VARCHAR(50),
  subject VARCHAR(100),
  date DATE,
  time TIME,
  status VARCHAR(20)
);

CREATE TABLE admins (
  id SERIAL PRIMARY KEY,
  username VARCHAR(50),
  password VARCHAR(255)
);

CREATE TABLE faculty (
  id SERIAL PRIMARY KEY,
  faculty_id VARCHAR(50),
  name VARCHAR(100),
  password VARCHAR(255)
);

Run

python app.py

Visit http://localhost:5000


πŸ“ Project Structure

AttendAI/
β”œβ”€β”€ app.py                              
# Attendance email alert utilities
β”œβ”€β”€ alerts.py
# Main Flask application        
β”œβ”€β”€ face_utils.py                       # DeepFace utility (future upgrade)
β”œβ”€β”€ train.py                            # Standalone training script
β”œβ”€β”€ haarcascade_frontalface_default.xml # Face detection model
β”œβ”€β”€ images/                             # Registered face images (local)
β”œβ”€β”€ trainer.yml                         # Trained LBPH model (auto-generated)
β”œβ”€β”€ labels.pickle                       # Label map (auto-generated)
β”œβ”€β”€ .env                                # Environment variables (not committed)
└── templates/
    β”œβ”€β”€ index.html                      # Home dashboard
    β”œβ”€β”€ login.html                      # Multi-role login
    β”œβ”€β”€ register.html                   # Browser webcam 20-frame registration
    β”œβ”€β”€ camera.html                     # Auto-continuous attendance scanner
    β”œβ”€β”€ attendance.html                 # Records + CSV export
    β”œβ”€β”€ dashboard.html                  # Analytics charts
    └── class_session.html             # Session setup

πŸ”„ How It Works

Register Student
      β”‚
      β–Ό
Browser opens webcam β†’ captures 20 frames
      β”‚
      β–Ό
Flask detects faces β†’ saves images β†’ auto-retrains LBPH model
      β”‚
      β–Ό
Faculty starts class session (subject + department)
      β”‚
      β–Ό
Camera page β†’ MediaPipe blink check (liveness verified)
      β”‚
      β–Ό
Auto-scans every 3 seconds β†’ face detected β†’ LBPH predicts identity
      β”‚
      β–Ό
Attendance marked in Supabase β†’ live log shown on screen
      β”‚
      β–Ό
Export CSV β†’ downloadable attendance report

πŸ—ΊοΈ Project Workflow

View Flowchart


πŸ‘οΈ Liveness Detection

AttendAI uses MediaPipe Face Mesh to compute the Eye Aspect Ratio (EAR) in real time. When EAR drops below threshold for 2+ consecutive frames, a blink is detected β€” confirming the face is real and not a photo or screen.

EAR = (vertical distances) / (horizontal distance)
Open eye β†’ EAR β‰ˆ 0.25–0.30
Blink    β†’ EAR < 0.20 β†’ LIVENESS CONFIRMED βœ…
Photo    β†’ EAR never drops β†’ REJECTED ❌

πŸ” Roles

Role Access
Admin All records, retrain model, manage sessions, export CSV
Faculty Start sessions, mark attendance, view records
Student View own attendance history

πŸ“§ Attendance Alert System

AttendAI supports automated attendance warning emails.

Admins can trigger attendance checks and automatically notify students whose attendance falls below a configurable threshold.

Workflow

Admin triggers attendance check
          β”‚
          β–Ό
Fetch all students from Supabase
          β”‚
          β–Ό
Calculate attendance percentage
          β”‚
          β–Ό
Below threshold?
     YES / NO
       β”‚
       β–Ό
Send email warning via Flask-Mail

Requirements

  • Gmail SMTP credentials configured in .env
  • Student email addresses stored in database
  • Flask-Mail installed

Default threshold: 75%


πŸ“ Roadmap

  • Browser-based webcam capture
  • Liveness detection (anti-spoofing)
  • Auto-continuous scanning
  • Supabase cloud database
  • CSV export
  • bcrypt auth
  • Low attendance email alerts
  • QR-based student self-checkin
  • DeepFace / FaceNet upgrade
  • React Native mobile app

πŸ‘¨β€πŸ’» Author

Subham Sahu


πŸ“„ License

MIT License β€” see LICENSE for details.


Built with ❀️ for NIST University Smart Campus Initiative

About

AI-powered face recognition attendance system built for NIST University Smart Campus initiative. Browser-based webcam capture, bcrypt auth, and auto-retraining.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages