Skip to content

Latest commit

Β 

History

69 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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:

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


πŸ› οΈ Troubleshooting

If you encounter issues while setting up or running AttendAI, try the following solutions.

1. ModuleNotFoundError

Problem

ModuleNotFoundError: No module named 'flask'

Solution

  • Activate your virtual environment.
  • Install all required dependencies:
pip install -r requirements.txt

If requirements.txt is unavailable, install the required packages manually.


2. Missing or Incorrect .env Variables

Problem

The application fails to start or cannot connect to Supabase.

Solution

  • Create a .env file in the project root.
  • Copy the required variables from the README.
  • Ensure there are no spelling mistakes or empty values.

3. Supabase Connection Errors

Problem

Database operations fail or authentication errors occur.

Solution

  • Verify SUPABASE_URL and SUPABASE_KEY.
  • Confirm your Supabase project is active.
  • Restart the Flask application after updating the .env file.

4. Webcam Permission Issues

Problem

The browser cannot access the webcam.

Solution

  • Allow camera permission in your browser.
  • Close any other application currently using the webcam.
  • Refresh the page and try again.

5. MediaPipe or OpenCV Installation Problems

Problem

Import errors occur for MediaPipe or OpenCV.

Solution

pip install --upgrade mediapipe opencv-contrib-python

If the issue persists, recreate your virtual environment and reinstall dependencies.


6. Port 5000 Already in Use

Problem

Address already in use
Port 5000 is already occupied.

Solution

Run the application on another port:

flask run --port=5001

or stop the process currently using port 5000.


7. Flask-Mail Configuration Errors

Problem

Attendance warning emails are not being sent.

Solution

  • Verify MAIL_USERNAME and MAIL_PASSWORD.
  • Use a Gmail App Password instead of your Gmail account password.
  • Restart the application after updating mail credentials.

πŸ“ 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


πŸ“Έ Screenshots

πŸ” Login Page

Login Page

Secure login interface for Admin, Faculty, and Student users.

πŸ“ Registration Page

Registration Page

Student registration page with webcam-based face capture.

πŸŽ₯ Camera Interface

Camera Interface

Captures student faces for registration and attendance.

πŸ“š Class Session

Class Session

Faculty can create and manage attendance sessions.

πŸ“· Attendance Scanner

Attendance Scanner

Real-time face recognition used for marking attendance.

πŸ–₯️ Dashboard

Dashboard

Displays attendance information and system overview.


πŸ—ΊοΈ 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

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages