Ai_Clothes_Change / README.md
priyamdave000167's picture
Update README.md
0cc663c verified
metadata
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

python scripts/download_model.py

This downloads ~4GB of weights from Hugging Face into backend/weights/catvton/.

2. Backend (Python)

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)

cd frontend
npm install
npm run dev

Open: http://localhost:5173


🐳 Docker (Production)

# 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:

{
  "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

{ "status": "healthy", "model_loaded": true, "device": "cuda" }

⚙️ Configuration (.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 (Apache 2.0).