--- title: Ai_Clothes_change sdk: docker emoji: ⚑ colorFrom: yellow colorTo: blue --- # ✦ AI Clothes Changer β€” Virtual Try-On AI-powered virtual try-on app using **CatVTON** diffusion model. Upload a person photo + a clothing image β†’ get a photorealistic try-on result in seconds. --- ## 🧠 Tech Stack | Layer | Technology | |-------|------------| | AI Model | CatVTON (diffusion-based VTON) | | Backend | Python Β· FastAPI Β· PyTorch | | Frontend | React Β· Vite Β· Tailwind CSS | | Inference | CUDA (GPU) / CPU fallback | | Packaging | Docker Β· docker-compose | --- ## πŸ“ Project Structure ``` ai-clothes-changer/ β”œβ”€β”€ backend/ β”‚ β”œβ”€β”€ app/ β”‚ β”‚ β”œβ”€β”€ main.py # FastAPI app + CORS β”‚ β”‚ β”œβ”€β”€ routes/tryon.py # POST /api/v1/try-on β”‚ β”‚ β”œβ”€β”€ services/ β”‚ β”‚ β”‚ β”œβ”€β”€ inference.py # CatVTON model loading + inference β”‚ β”‚ β”‚ β”œβ”€β”€ preprocessing.py # Image resize, normalize β”‚ β”‚ β”‚ └── postprocessing.py# Tensor β†’ PIL β†’ base64 β”‚ β”‚ β”œβ”€β”€ schemas/request.py # Pydantic models β”‚ β”‚ └── utils/ β”‚ β”‚ β”œβ”€β”€ config.py # Settings from .env β”‚ β”‚ └── file_handler.py # Upload + cleanup helpers β”‚ β”œβ”€β”€ weights/catvton/ # ← model weights go here β”‚ β”œβ”€β”€ requirements.txt β”‚ └── .env β”‚ β”œβ”€β”€ frontend/ β”‚ └── src/ β”‚ β”œβ”€β”€ api/api.js # Axios client β”‚ β”œβ”€β”€ components/ β”‚ β”‚ β”œβ”€β”€ Upload.jsx # Drag-and-drop uploader β”‚ β”‚ └── Result.jsx # Output + download β”‚ └── pages/Home.jsx # Main UI β”‚ β”œβ”€β”€ scripts/ β”‚ β”œβ”€β”€ download_model.py # Downloads CatVTON weights β”‚ └── train.py # Fine-tuning stub β”‚ β”œβ”€β”€ docker/Dockerfile └── docker-compose.yml ``` --- ## πŸš€ Quick Start ### 1. Download model weights ```bash python scripts/download_model.py ``` This downloads ~4GB of weights from Hugging Face into `backend/weights/catvton/`. ### 2. Backend (Python) ```bash cd backend python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt uvicorn app.main:app --reload --port 8000 ``` API docs: http://localhost:8000/docs ### 3. Frontend (React) ```bash cd frontend npm install npm run dev ``` Open: http://localhost:5173 --- ## 🐳 Docker (Production) ```bash # Build and run backend docker compose up --build # Dev mode (backend + frontend) docker compose --profile dev up --build ``` --- ## πŸ”Œ API Reference ### `POST /api/v1/try-on` | Field | Type | Description | |-------|------|-------------| | `person_image` | File | Full-body person photo (JPEG/PNG/WEBP, max 10MB) | | `cloth_image` | File | Clothing item photo | | `cloth_type` | string | `upper` \| `lower` \| `overall` | | `num_steps` | int | Inference steps 20–100 (default: 50) | **Response:** ```json { "status": "success", "output_image": "/outputs/results/abc123.png", "output_image_base64": "data:image/png;base64,...", "processing_time_ms": 4200.5, "message": "Try-on completed successfully" } ``` ### `GET /api/v1/health` ```json { "status": "healthy", "model_loaded": true, "device": "cuda" } ``` --- ## βš™οΈ Configuration (`.env`) ```env DEVICE=cuda # cuda | cpu MODEL_PATH=weights/catvton MIXED_PRECISION=fp16 # fp16 | no OUTPUT_IMAGE_WIDTH=768 OUTPUT_IMAGE_HEIGHT=1024 CLOTH_TYPE=upper MAX_IMAGE_SIZE_MB=10 ``` --- ## πŸ’‘ Tips for Best Results - **Person image**: Full-body photo, neutral background, front-facing - **Cloth image**: Flat-lay or product photo on white background - **Steps**: 50 = balanced quality/speed Β· 80+ = best quality (slower) - **GPU**: CUDA speeds up inference 10–20Γ— vs CPU --- ## πŸ—ΊοΈ Roadmap - [ ] Cloth library / preset gallery - [ ] Video try-on (CatV2TON) - [ ] Background removal (rembg) - [ ] Body size / pose adjustment - [ ] Cloudinary / S3 storage - [ ] Redis queue for concurrent requests - [ ] Mobile-optimized UI --- ## πŸ“„ License MIT β€” built on [CatVTON](https://github.com/Zheng-Chong/CatVTON) (Apache 2.0).