| prompts | ||
| .gitattributes | ||
| .gitignore | ||
| docker-compose.yml | ||
| Dockerfile | ||
| main.py | ||
| postman_collection.json | ||
| POSTMAN_SETUP.md | ||
| README.md | ||
| requirements.txt | ||
| test_api_key.py | ||
| TROUBLESHOOTING.md | ||
| xray-config.json | ||
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
-
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 -
Set up environment variables:
- Create a
.envfile in the project root (same directory asmain.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
.envfile should be in the same directory asdocker-compose.yml
- Create a
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: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
- Health check: http://localhost:8000/health
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:
-
Health Check:
- Method:
GET - URL:
http://localhost:8000/health - No body or headers needed
- Expected response:
{"status": "ok"}
- Method:
-
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 photooutfit_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"
- Method:
Import Postman Collection:
You can import postman_collection.json into Postman for pre-configured requests.
Notes
- The service uses
gemini-2.5-flash-imagemodel - 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
/healthendpoint - For production, remove
--reloadfrom the Dockerfile CMD and remove volume mounts from docker-compose.yml