Sign inSign up

blazordevlab/face-extraction-api

By blazordevlab

•Updated 9 months ago

A simple Flask-based API that extracts the highest-confidence face from an image

Image
API management
Machine learning & AI
1

596

blazordevlab/face-extraction-api repository overview

Docker Build and Push Python Compile Check

⁠Face Extraction API with Flask and DeepFace

⁠Description

A simple Flask-based API that extracts the highest-confidence face from an image, expands its bounding box by 20%, and returns the cropped image as a downloadable JPEG file without saving it on the server. The API supports two methods of image input: providing an image URL or uploading an image file.

⁠Features

  • Image URL Input: Downloads an image from a given URL.
  • File Upload: Accepts an image file uploaded via a form-data POST request.
  • Detects faces using the DeepFace library with the Yunet detector.
  • Selects the face with the highest confidence.
  • Expands the detected face region by 20%.
  • Returns the cropped image as a downloadable attachment.

⁠Requirements

  • Python 3.9+
  • Docker (optional, for containerized deployment)

⁠Installation and Running Locally

  1. Clone this repository:

    git clone https://github.com/your_username/face-extraction-api.git
    cd face-extraction-api
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    
  3. Run the Flask application:

    python app.py
    

The API will be available at http://localhost:5000.

⁠Running with Docker

  1. Build the Docker image:

    docker build -t face-extraction-api .
    
  2. Run the Docker container:

    docker run -p 5000:5000 face-extraction-api
    
  3. Docker compose file:

    version: '3.8'
    services:
      face-extraction-api:
        image: blazordevlab/face-extraction-api:latest
        container_name: faceextraction
        ports:
          - "5000:5000"
        labels:
          - "traefik.enable=true"
          # Replace 'faceextraction.example.com' with your actual domain
          - "traefik.http.routers.faceextraction.rule=Host(`faceextraction.example.com`)"
          - "traefik.http.routers.faceextraction.tls=true"
          - "traefik.http.routers.faceextraction.entrypoints=https"
          - "traefik.http.services.faceextraction.loadbalancer.server.port=5000"
          - "traefik.docker.network=proxy"
        networks:
          proxy:
        security_opt:
          - no-new-privileges:true
    networks:
       proxy:
          external: true      
    

⁠API Endpoints

⁠1. Extract Face by Image URL
  • Endpoint: /extract_face

  • Method: POST

  • Payload: JSON object containing the image_url key.

    Example JSON Payload:

    {
      "image_url": "https://example.com/your_image.jpg"
    }
    
  • Response: Returns the cropped face image as a downloadable JPEG file.

⁠2. Extract Face by File Upload
  • Endpoint: /upload_extract_face

  • Method: POST

  • Payload: Form-data with an image file in the file field.

    Example using curl:

    curl -X POST -F "file=@/path/to/your_image.jpg" http://localhost:5000/upload_extract_face --output extracted_face.jpg
    
  • Response: Returns the cropped face image as a downloadable JPEG file.

⁠License

This project is licensed under the MIT License.

Tag summary

Content type

Image

Digest

sha256:127baec73…

Size

1.7 GB

Last updated

9 months ago

docker pull blazordevlab/face-extraction-api