This repository contains the code for the Face Embeddings APIs, which provide a set of endpoints to calculate face embeddings of human faces from images. The APIs are built using Django Rest Framework (DRF) and utilize the face_recognition library for face encoding.
The following are the available API endpoints:
-
GET /api/health-check/: Validate Face Embeddings APIs service is running and its components integrated well.
-
POST /api/face-image/: Receives an image file and responds with the face encoding. This endpoint expects a
multipart/form-datarequest with the image file attached. -
GET /api/face-image/{public_id}/: Retrieves the face encoding for a previously calculated image identified by its
public_id. -
GET /api/face-image/stats/: Retrieves statistics about how many images were processed, including the count of images with each encoding status.
-
GET /api/face-image/avg-encodings/: Retrieves AVG about face encodings for all previously calculated images.
Here is a link for postman collection with its environment For APIs.
To run the Face Embeddings APIs on your local machine, follow these steps:
- Install Docker and Docker Compose on your system.
-
Clone this repository to your local machine.
-
Create a
.envfile in the root of the project and configure the environment variables as follows:# Django Settings DEBUG=True SECRET_KEY=your_secret_key_here POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_DB=database_name POSTGRES_USER=username POSTGRES_PASSWORD=password -
Build and run using Docker:
docker compose up -d --build
-
Admin portal can be accessible at
http://localhost:8000/admin/with credentials:admin,admin_passto create api-key. You should change these credentials from admin portal. -
The APIs should now be accessible at
http://localhost:8000/api/.
The Face Embeddings APIs require API key authentication. You must include the API key in the Authorization header of each request. For example:
GET /api/face-image/ HTTP/1.1
Host: localhost:8000
Authorization: Api-Key <your_api_key_here>The API documentation is available using the Swagger UI provided by DRF-Spectacular. You can access it at http://localhost:8000/api/schema/redoc/.
To run the test suite, use the following command:
docker exec face_embeddings pytestWe welcome contributions to improve and expand the functionality of the Face Embeddings APIs. If you find any issues or have suggestions, please feel free to open a pull request or an issue on GitHub.
- Install PostgreSQL on your system.
python3.10 -m pip install --upgrade pip
python3.10 -m pip install pipenv --upgrade
pipenv --python 3.10
pipenv shell
pipenv install (run `pipenv install -d` for local development)
python manage.py migrate
python manage.py createsuperuserConfiguring Pre-Commit
Please make sure to run following commands before starting any development.
pre-commit install --hook-type pre-commit
pre-commit install --hook-type pre-push
sh cmd/install_hooks.shThis project is licensed under the MIT License. See the LICENSE file for more details.