AI-powered face recognition attendance system built for the NIST University Smart Campus initiative.
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.
- π₯ 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)
| 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 |
- Python 3.10+
- Webcam
- Supabase account (free at supabase.com)
# 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 supabaseContributors 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.
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_USERNAMEshould be a Gmail account used for sending alerts.MAIL_PASSWORDmust 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.
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)
);python app.pyVisit http://localhost:5000
If you encounter issues while setting up or running AttendAI, try the following solutions.
Problem
ModuleNotFoundError: No module named 'flask'
Solution
- Activate your virtual environment.
- Install all required dependencies:
pip install -r requirements.txtIf requirements.txt is unavailable, install the required packages manually.
Problem
The application fails to start or cannot connect to Supabase.
Solution
- Create a
.envfile in the project root. - Copy the required variables from the README.
- Ensure there are no spelling mistakes or empty values.
Problem
Database operations fail or authentication errors occur.
Solution
- Verify
SUPABASE_URLandSUPABASE_KEY. - Confirm your Supabase project is active.
- Restart the Flask application after updating the
.envfile.
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.
Problem
Import errors occur for MediaPipe or OpenCV.
Solution
pip install --upgrade mediapipe opencv-contrib-pythonIf the issue persists, recreate your virtual environment and reinstall dependencies.
Problem
Address already in use
Port 5000 is already occupied.
Solution
Run the application on another port:
flask run --port=5001or stop the process currently using port 5000.
Problem
Attendance warning emails are not being sent.
Solution
- Verify
MAIL_USERNAMEandMAIL_PASSWORD. - Use a Gmail App Password instead of your Gmail account password.
- Restart the application after updating mail credentials.
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
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
Secure login interface for Admin, Faculty, and Student users.
Student registration page with webcam-based face capture.
Captures student faces for registration and attendance.
Faculty can create and manage attendance sessions.
Real-time face recognition used for marking attendance.
Displays attendance information and system overview.
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 β
| Role | Access |
|---|---|
| Admin | All records, retrain model, manage sessions, export CSV |
| Faculty | Start sessions, mark attendance, view records |
| Student | View own attendance history |
AttendAI supports automated attendance warning emails.
Admins can trigger attendance checks and automatically notify students whose attendance falls below a configurable threshold.
Admin triggers attendance check
β
βΌ
Fetch all students from Supabase
β
βΌ
Calculate attendance percentage
β
βΌ
Below threshold?
YES / NO
β
βΌ
Send email warning via Flask-Mail
- Gmail SMTP credentials configured in
.env - Student email addresses stored in database
- Flask-Mail installed
Default threshold: 75%
- 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
Subham Sahu
- GitHub: @Subham503
- Email: sahusubham38632@gmail.com
MIT License β see LICENSE for details.
Built with β€οΈ for NIST University Smart Campus Initiative





