Go to file
2025-11-30 18:50:27 +03:30
.gitattributes Initial commit 2025-11-16 17:03:38 +03:30
.gitignore do lots of things 2025-11-16 18:30:04 +03:30
docker-compose.yml update 2025-11-30 18:36:07 +03:30
Dockerfile do lots of things 2025-11-16 18:30:04 +03:30
main.py update main 2025-11-30 18:50:27 +03:30
postman_collection.json do lots of things 2025-11-16 18:30:04 +03:30
POSTMAN_SETUP.md do lots of things 2025-11-16 18:30:04 +03:30
README.md do lots of things 2025-11-16 18:30:04 +03:30
requirements.txt update 2025-11-30 18:41:31 +03:30
test_api_key.py do lots of things 2025-11-16 18:30:04 +03:30
TROUBLESHOOTING.md do lots of things 2025-11-16 18:30:04 +03:30
xray-config.json update 2025-11-30 18:33:39 +03:30

AIFit Try-On Service

A FastAPI microservice that uses Google's Gemini API to generate virtual try-on images. Takes a user mirror selfie and an outfit reference image, then returns an edited image with the outfit applied.

Setup

  1. Install dependencies (preferably in a virtual environment):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
    
  2. Set up environment variables:

    • Create a .env file in the project root (same directory as main.py)
    • Add your Gemini API key with NO spaces around the = sign:
      GEMINI_API_KEY=YOUR_REAL_KEY_HERE
      
    • Important:
      • No quotes around the value
      • No spaces: GEMINI_API_KEY=key (correct)
      • Wrong: GEMINI_API_KEY = key (has spaces)
      • Wrong: GEMINI_API_KEY="key" (has quotes)
    • The .env file should be in the same directory as docker-compose.yml

Running the Service

Option 1: Direct Python

Start the FastAPI server:

uvicorn main:app --reload

Option 2: Docker Compose

Build and run with Docker:

docker-compose up --build

The API will be available at:

API Endpoints

GET /health

Health check endpoint for monitoring and Docker healthchecks.

Response:

{"status": "ok"}

POST /api/try-on/

Generate a try-on image by combining a user photo with an outfit reference.

Parameters:

  • user_photo (file): User mirror/body photo (JPEG or PNG)
  • outfit_photo (file): Collection/outfit photo (JPEG or PNG)

Response:

  • Returns the generated image as image/png

Example using curl:

curl -X POST "http://localhost:8000/api/try-on/" \
  -F "user_photo=@user_selfie.jpg" \
  -F "outfit_photo=@outfit_reference.jpg" \
  --output result.png

Testing in Postman:

  1. Health Check:

    • Method: GET
    • URL: http://localhost:8000/health
    • No body or headers needed
    • Expected response: {"status": "ok"}
  2. Try-On Endpoint:

    • Method: POST
    • URL: http://localhost:8000/api/try-on/
    • Body tab → Select form-data
    • Add two fields:
      • user_photo (type: File) → Select your user mirror/body photo
      • outfit_photo (type: File) → Select your collection/outfit photo
    • Click Send
    • Response will be an image (PNG format)
    • To save: Click "Save Response" → "Save to a file"

Import Postman Collection: You can import postman_collection.json into Postman for pre-configured requests.

Notes

  • The service uses gemini-2.5-flash-image model
  • CORS is enabled for all origins (tighten in production)
  • Images are validated before processing
  • The service handles errors gracefully with appropriate HTTP status codes
  • Docker healthcheck is configured to use the /health endpoint
  • For production, remove --reload from the Dockerfile CMD and remove volume mounts from docker-compose.yml