DatNguyenTrung/ai-receptionist-be
0
AI Receptionist Face Embedding Backend
FastAPI service dedicated to generating a face embedding vector from one uploaded image. The service does not manage Person records, search a database, store embeddings, or run check-in business logic.
Tech Stack
- FastAPI
- InsightFace
- ONNX Runtime
- OpenCV
- NumPy
Telegram/Gemini utility code is kept temporarily, but the Person/database flow has been removed.
Environment Variables
Create a .env file from .env.example when running locally. Do not commit real secrets.
PROJECT_NAME=AI Receptionist Face Embedding API
INSIGHTFACE_MODEL_NAME=buffalo_l
INSIGHTFACE_PROVIDERS=CPUExecutionProvider
FACE_EMBEDDING_DIMENSION=512
MAX_IMAGE_SIZE_BYTES=5242880
ALLOWED_IMAGE_TYPES=image/jpeg,image/png
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=
SERVER_PUBLIC_URL=
GEMINI_API_KEY=Removed environment variables:
DATABASE_URLFACE_MATCH_THRESHOLDJWT_BASE64_SECRET
Run Locally
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reloadAPI Contract
Generate Face Embedding
POST /face-embeddings
Content-Type: multipart/form-dataForm field:
file: image upload containing exactly one face
Success response:
{
"success": true,
"embedding": [0.0123, -0.0456, 0.0789],
"dimension": 512,
"model": "buffalo_l",
"errorCode": null,
"message": null
}Error response:
{
"success": false,
"embedding": null,
"dimension": null,
"model": "buffalo_l",
"errorCode": "FACE_NOT_DETECTED",
"message": "Không phát hiện được khuôn mặt trong ảnh"
}Status mapping:
400:INVALID_IMAGE_FILE,EMPTY_IMAGE_FILE,UNSUPPORTED_IMAGE_TYPE,IMAGE_DECODE_FAILED413:FILE_TOO_LARGE422:FACE_NOT_DETECTED,MULTIPLE_FACES_DETECTED,FACE_EMBEDDING_FAILED,INVALID_EMBEDDING503:MODEL_NOT_INITIALIZED500:INTERNAL_ERROR
Example:
curl -X POST "http://localhost:8000/face-embeddings" \
-F "file=@tests/dat.jpg;type=image/jpeg"Health
GET /healthReturns model readiness and service metadata. It no longer checks a database connection.
Tests
python -m pytestThe tests mock InsightFace for deterministic validation of image/file errors, face-count errors, embedding validation, and API response contracts.
Removed Dependencies
sqlalchemy[asyncio]asyncpgpgvector
