CoolFace
Apppublic

avy23/passport-photo-processor

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

PassportPro AI - Image Processor

This is the image processing backend for PassportPro AI, deployed on Hugging Face Spaces.

Features

  • —✅ Background removal using rembg
  • —✅ Automatic face detection and centering
  • —✅ Smart cropping for passport photo standards (413x531px)
  • —✅ Image enhancement (contrast, sharpness, brightness)
  • —✅ Custom background color support

API Usage

Endpoint: POST /process

Parameters:

  • —image (file): The photo to process (JPEG or PNG)
  • —bgColor (string, optional): Background color in hex format (default: #FFFFFF)

Example Request (cURL):

bash
curl -X POST https://YOUR_USERNAME-passport-photo-processor.hf.space/process \
  -F "image=@photo.jpg" \
  -F "bgColor=#FFFFFF"

Example Response:

json
{
  "success": true,
  "outputImage": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
  "originalFilename": "photo.jpg",
  "processedSize": 125847,
  "message": "Photo processed successfully"
}

Local Testing

bash
# Install dependencies
pip install -r requirements.txt
pip install fastapi uvicorn python-multipart

# Run the server
python app.py

Visit http://localhost:7860/docs for interactive API documentation.

Deployment on Hugging Face Spaces

  1. 1.Create a new Space with Docker SDK
  2. 2.Upload these files:
  3. 3.app.py
  4. 4.passport_process.py
  5. 5.requirements.txt
  6. 6.Dockerfile
  7. 7.README_HF.md (rename to README.md)
  1. 1.Space will automatically build and deploy

Performance

  • —Processing Time: 3-8 seconds per image (depends on image size)
  • —Max Image Size: Recommended < 5MB for faster processing
  • —Concurrent Requests: Handled sequentially to avoid memory issues

Tech Stack

  • —FastAPI: Web framework
  • —rembg: Background removal (uses U2-Net model)
  • —OpenCV: Face detection
  • —Pillow: Image manipulation
  • —Uvicorn: ASGI server

License

MIT License