Spaces:
Running
title: VisionAttend API
emoji: 👁️
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
VisionAttend Backend
The backend of VisionAttend handles the computational heavy lifting. It exposes the API endpoints necessary for student management and uses a DeepFace model for instantaneous facial embedding extraction.
Features
- FastAPI Core: Utilizes asynchronous endpoints for maximum concurrency.
- DeepFace Integration: Leverages the
Facenetmodel for robust 128-dimensional encodings. Uses theopencvdetector backend for rapid alignment performance compared toretinafaceormtcnn. - Postgres pgvector Matchmaking: Embeddings are stored in Neon Postgres using
pgvector. A student is recognized instantly using the<=>cosine distance operator to find the closest match under a set confidence threshold (0.40).
Requirements
Before starting, ensure you have a standard Python 3.10+ environment.
fastapiuvicorndeepfacepsycopg(with pool and pgvector integration)python-dotenvnumpy&pillow
Setup & Running
Virtual Environment Setup
python -m venv venv source venv/bin/activate pip install -r requirements.txtEnvironment Configuration Create a
.envfile referencing your Neon Postgres database containing thepgvectorextension.DATABASE_URL="postgres://user:password@host/dbname?sslmode=require"Initialize the Database Before running the app, execute the init script to build the exact table architecture needed.
python init_db.pyLaunch Server
uvicorn main:app --reload --port 8000
REST API Overview
All routes accept appropriate multipart/form-data for image payloads or generic application/json strings.
POST /api/register: Stores a new student photo representation.POST /api/recognize: Validates a live frame against existing students and marks attendance.GET /api/attendance: Retrieves attendance logs, optionally filtered by?date_filter=YYYY-MM-DD.PUT /api/students/{id}: Manual override to rename or change a roll number.DELETE /api/students/{id}: Purges a student and all historical logs.POST /api/attendance/manual: Enables manual toggling of "Present" status without the camera.
Testing
A programmatic integration test suite mimicking camera requests is available:
python test_core_flows.py
GitHub Actions Automation
This repository includes GitHub Actions workflows for Hugging Face Spaces deployment and keep-alive automation.
HF_TOKEN: required by the deploy workflow to pushbackend/to the Space repository.HF_SPACE_URL: required by the keep-alive workflow and should point to the public app domain.
The keep-alive workflow runs every 6 hours and sends a lightweight request to / so the free Space does not go inactive due to lack of traffic.