Upload 7 files
Browse files- .gitattributes +39 -35
- .gitignore +23 -0
- README.md +18 -13
- app.py +333 -0
- banner.html +59 -0
- requirements.txt +4 -0
- tips.html +29 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,39 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Virtual environment
|
| 2 |
+
.venv*/
|
| 3 |
+
venv/
|
| 4 |
+
env/
|
| 5 |
+
|
| 6 |
+
# Model weights (downloaded at runtime)
|
| 7 |
+
weights/
|
| 8 |
+
|
| 9 |
+
# Python
|
| 10 |
+
__pycache__/
|
| 11 |
+
*.py[cod]
|
| 12 |
+
*$py.class
|
| 13 |
+
*.so
|
| 14 |
+
|
| 15 |
+
# IDE
|
| 16 |
+
.idea/
|
| 17 |
+
.vscode/
|
| 18 |
+
*.swp
|
| 19 |
+
*.swo
|
| 20 |
+
|
| 21 |
+
# OS
|
| 22 |
+
.DS_Store
|
| 23 |
+
Thumbs.db
|
README.md
CHANGED
|
@@ -1,13 +1,18 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: VTON
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 6.
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: FASHN VTON v1.5
|
| 3 |
+
emoji: "\U0001F457"
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.3.0
|
| 8 |
+
python_version: 3.10.14
|
| 9 |
+
app_file: app.py
|
| 10 |
+
pinned: false
|
| 11 |
+
license: apache-2.0
|
| 12 |
+
short_description: Maskless try-on directly in pixel space
|
| 13 |
+
tags:
|
| 14 |
+
- virtual-try-on
|
| 15 |
+
- diffusion
|
| 16 |
+
- fashion
|
| 17 |
+
- image-to-image
|
| 18 |
+
---
|
app.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FASHN VTON v1.5 HuggingFace Space Demo."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import platform
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import spaces
|
| 8 |
+
import torch
|
| 9 |
+
from huggingface_hub import hf_hub_download
|
| 10 |
+
from PIL import Image
|
| 11 |
+
|
| 12 |
+
# ----------------- CONFIG ----------------- #
|
| 13 |
+
|
| 14 |
+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
+
ASSETS_DIR = os.path.join(SCRIPT_DIR, "assets")
|
| 16 |
+
WEIGHTS_DIR = os.path.join(SCRIPT_DIR, "weights")
|
| 17 |
+
|
| 18 |
+
CATEGORIES = ["tops", "bottoms", "one-pieces"]
|
| 19 |
+
GARMENT_PHOTO_TYPES = ["model", "flat-lay"]
|
| 20 |
+
|
| 21 |
+
# Global pipeline instance (lazy loaded)
|
| 22 |
+
_pipeline = None
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# ----------------- HELPERS ----------------- #
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def download_weights():
|
| 29 |
+
"""Download model weights from HuggingFace Hub."""
|
| 30 |
+
os.makedirs(WEIGHTS_DIR, exist_ok=True)
|
| 31 |
+
dwpose_dir = os.path.join(WEIGHTS_DIR, "dwpose")
|
| 32 |
+
os.makedirs(dwpose_dir, exist_ok=True)
|
| 33 |
+
|
| 34 |
+
# Download TryOnModel weights
|
| 35 |
+
tryon_path = os.path.join(WEIGHTS_DIR, "model.safetensors")
|
| 36 |
+
if not os.path.exists(tryon_path):
|
| 37 |
+
print("Downloading TryOnModel weights...")
|
| 38 |
+
hf_hub_download(
|
| 39 |
+
repo_id="fashn-ai/fashn-vton-1.5",
|
| 40 |
+
filename="model.safetensors",
|
| 41 |
+
local_dir=WEIGHTS_DIR,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Download DWPose models
|
| 45 |
+
dwpose_files = ["yolox_l.onnx", "dw-ll_ucoco_384.onnx"]
|
| 46 |
+
for filename in dwpose_files:
|
| 47 |
+
filepath = os.path.join(dwpose_dir, filename)
|
| 48 |
+
if not os.path.exists(filepath):
|
| 49 |
+
print(f"Downloading DWPose/{filename}...")
|
| 50 |
+
hf_hub_download(
|
| 51 |
+
repo_id="fashn-ai/DWPose",
|
| 52 |
+
filename=filename,
|
| 53 |
+
local_dir=dwpose_dir,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
print("Weights downloaded successfully!")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# ----------------- MODEL LOADING ----------------- #
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def get_pipeline():
|
| 63 |
+
"""Lazy-load the pipeline on first use (ensures GPU is available on ZeroGPU)."""
|
| 64 |
+
global _pipeline
|
| 65 |
+
if _pipeline is None:
|
| 66 |
+
# Check CUDA availability (will be true inside @spaces.GPU context)
|
| 67 |
+
if not torch.cuda.is_available():
|
| 68 |
+
raise gr.Error(
|
| 69 |
+
"CUDA is not available. This demo requires a GPU to run. "
|
| 70 |
+
"If you're on HuggingFace Spaces, please try again in a moment."
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# ---------------------------------- Diagnostics ---------------------------------- #
|
| 74 |
+
print(f"Python : {platform.python_version()}")
|
| 75 |
+
print(f"PyTorch : {torch.__version__}")
|
| 76 |
+
print(f" • built for CUDA : {torch.version.cuda}")
|
| 77 |
+
if torch.backends.cudnn.is_available():
|
| 78 |
+
print(f" • built for cuDNN: {torch.backends.cudnn.version()}")
|
| 79 |
+
print(f"torch.cuda.is_available(): {torch.cuda.is_available()}")
|
| 80 |
+
if torch.cuda.is_available():
|
| 81 |
+
dev = torch.cuda.current_device()
|
| 82 |
+
cc = torch.cuda.get_device_capability(dev)
|
| 83 |
+
print(f"GPU {dev}: {torch.cuda.get_device_name(dev)} (compute {cc[0]}.{cc[1]})")
|
| 84 |
+
|
| 85 |
+
# Enable TF32 for faster computation on Ampere+ GPUs
|
| 86 |
+
if torch.cuda.get_device_properties(0).major >= 8:
|
| 87 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
| 88 |
+
torch.backends.cudnn.allow_tf32 = True
|
| 89 |
+
|
| 90 |
+
print("Downloading weights (if needed)...")
|
| 91 |
+
download_weights()
|
| 92 |
+
|
| 93 |
+
print("Loading pipeline...")
|
| 94 |
+
from fashn_vton import TryOnPipeline
|
| 95 |
+
|
| 96 |
+
_pipeline = TryOnPipeline(weights_dir=WEIGHTS_DIR, device="cuda")
|
| 97 |
+
print("Pipeline loaded on CUDA!")
|
| 98 |
+
|
| 99 |
+
return _pipeline
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
# ----------------- INFERENCE ----------------- #
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@spaces.GPU
|
| 106 |
+
def try_on(
|
| 107 |
+
person_image: Image.Image,
|
| 108 |
+
garment_image: Image.Image,
|
| 109 |
+
category: str,
|
| 110 |
+
garment_photo_type: str,
|
| 111 |
+
num_timesteps: int,
|
| 112 |
+
guidance_scale: float,
|
| 113 |
+
seed: int,
|
| 114 |
+
segmentation_free: bool,
|
| 115 |
+
) -> Image.Image:
|
| 116 |
+
"""Run virtual try-on inference."""
|
| 117 |
+
if person_image is None:
|
| 118 |
+
raise gr.Error("Please upload a person image")
|
| 119 |
+
if garment_image is None:
|
| 120 |
+
raise gr.Error("Please upload a garment image")
|
| 121 |
+
|
| 122 |
+
# Handle seed (guard against None or invalid values)
|
| 123 |
+
if seed is None or seed < 0:
|
| 124 |
+
seed = 42
|
| 125 |
+
|
| 126 |
+
# Convert to RGB if needed
|
| 127 |
+
if person_image.mode != "RGB":
|
| 128 |
+
person_image = person_image.convert("RGB")
|
| 129 |
+
if garment_image.mode != "RGB":
|
| 130 |
+
garment_image = garment_image.convert("RGB")
|
| 131 |
+
|
| 132 |
+
# Get pipeline (lazy loads on first call)
|
| 133 |
+
pipeline = get_pipeline()
|
| 134 |
+
|
| 135 |
+
# Run inference
|
| 136 |
+
result = pipeline(
|
| 137 |
+
person_image=person_image,
|
| 138 |
+
garment_image=garment_image,
|
| 139 |
+
category=category,
|
| 140 |
+
garment_photo_type=garment_photo_type,
|
| 141 |
+
num_samples=1,
|
| 142 |
+
num_timesteps=num_timesteps,
|
| 143 |
+
guidance_scale=guidance_scale,
|
| 144 |
+
seed=int(seed),
|
| 145 |
+
segmentation_free=segmentation_free,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
return result.images[0]
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# ----------------- UI ----------------- #
|
| 152 |
+
|
| 153 |
+
# Custom CSS
|
| 154 |
+
CUSTOM_CSS = """
|
| 155 |
+
.contain img {
|
| 156 |
+
object-fit: contain !important;
|
| 157 |
+
max-height: 856px !important;
|
| 158 |
+
max-width: 576px !important;
|
| 159 |
+
}
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
# Load HTML content
|
| 163 |
+
with open(os.path.join(SCRIPT_DIR, "banner.html"), "r") as f:
|
| 164 |
+
banner_html = f.read()
|
| 165 |
+
with open(os.path.join(SCRIPT_DIR, "tips.html"), "r") as f:
|
| 166 |
+
tips_html = f.read()
|
| 167 |
+
|
| 168 |
+
# Build example paths
|
| 169 |
+
examples_dir = os.path.join(ASSETS_DIR, "examples")
|
| 170 |
+
|
| 171 |
+
# Paired examples: [person_path, garment_path, category, garment_photo_type]
|
| 172 |
+
paired_examples = [
|
| 173 |
+
[os.path.join(examples_dir, "person1.png"), os.path.join(examples_dir, "garment1.jpeg"), "one-pieces", "model"],
|
| 174 |
+
[os.path.join(examples_dir, "person2.png"), os.path.join(examples_dir, "garment2.webp"), "tops", "model"],
|
| 175 |
+
[os.path.join(examples_dir, "person3.png"), os.path.join(examples_dir, "garment3.jpeg"), "tops", "flat-lay"],
|
| 176 |
+
[os.path.join(examples_dir, "person4.png"), os.path.join(examples_dir, "garment4.webp"), "tops", "model"],
|
| 177 |
+
[os.path.join(examples_dir, "person5.png"), os.path.join(examples_dir, "garment5.jpeg"), "bottoms", "flat-lay"],
|
| 178 |
+
[os.path.join(examples_dir, "person6.png"), os.path.join(examples_dir, "garment6.webp"), "one-pieces", "model"],
|
| 179 |
+
]
|
| 180 |
+
|
| 181 |
+
# Individual examples (classic from repo)
|
| 182 |
+
person_only_examples = [os.path.join(examples_dir, "person0.png")]
|
| 183 |
+
|
| 184 |
+
# Garment examples with their settings: (image_path, category, photo_type)
|
| 185 |
+
# Order matters - index in Gallery corresponds to this list
|
| 186 |
+
garment_examples_data = [
|
| 187 |
+
(os.path.join(examples_dir, "garment0.png"), "tops", "model"),
|
| 188 |
+
(os.path.join(examples_dir, "garment7.jpg"), "tops", "flat-lay"),
|
| 189 |
+
]
|
| 190 |
+
garment_gallery_images = [item[0] for item in garment_examples_data]
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def on_garment_gallery_select(evt: gr.SelectData):
|
| 194 |
+
"""Handle garment gallery selection - load image and update dropdowns."""
|
| 195 |
+
idx = evt.index
|
| 196 |
+
if idx < len(garment_examples_data):
|
| 197 |
+
image_path, cat, photo_type = garment_examples_data[idx]
|
| 198 |
+
return Image.open(image_path), cat, photo_type
|
| 199 |
+
return None, "tops", "model"
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
# Build UI
|
| 203 |
+
with gr.Blocks(css=CUSTOM_CSS) as demo:
|
| 204 |
+
# Header
|
| 205 |
+
gr.HTML(banner_html)
|
| 206 |
+
gr.HTML(tips_html)
|
| 207 |
+
|
| 208 |
+
with gr.Row(equal_height=False):
|
| 209 |
+
# Column 1: Person
|
| 210 |
+
with gr.Column(scale=1):
|
| 211 |
+
person_image = gr.Image(
|
| 212 |
+
label="Person Image",
|
| 213 |
+
type="pil",
|
| 214 |
+
sources=["upload", "clipboard"],
|
| 215 |
+
elem_classes=["contain"],
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
# Individual person examples
|
| 219 |
+
gr.Examples(
|
| 220 |
+
examples=person_only_examples,
|
| 221 |
+
inputs=person_image,
|
| 222 |
+
label="Person Examples",
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
# Column 2: Garment
|
| 226 |
+
with gr.Column(scale=1):
|
| 227 |
+
garment_image = gr.Image(
|
| 228 |
+
label="Garment Image",
|
| 229 |
+
type="pil",
|
| 230 |
+
sources=["upload", "clipboard"],
|
| 231 |
+
elem_classes=["contain"],
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
with gr.Row():
|
| 235 |
+
category = gr.Dropdown(
|
| 236 |
+
choices=CATEGORIES,
|
| 237 |
+
value="tops",
|
| 238 |
+
label="Category",
|
| 239 |
+
)
|
| 240 |
+
garment_photo_type = gr.Dropdown(
|
| 241 |
+
choices=GARMENT_PHOTO_TYPES,
|
| 242 |
+
value="model",
|
| 243 |
+
label="Photo Type",
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
# Garment examples as clickable gallery
|
| 247 |
+
gr.Markdown("**Garment Examples** (click to load with settings)")
|
| 248 |
+
garment_gallery = gr.Gallery(
|
| 249 |
+
value=garment_gallery_images,
|
| 250 |
+
columns=2,
|
| 251 |
+
rows=1,
|
| 252 |
+
height="auto",
|
| 253 |
+
object_fit="contain",
|
| 254 |
+
show_label=False,
|
| 255 |
+
allow_preview=False,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
# Column 3: Result
|
| 259 |
+
with gr.Column(scale=1):
|
| 260 |
+
result_image = gr.Image(
|
| 261 |
+
label="Try-On Result",
|
| 262 |
+
type="pil",
|
| 263 |
+
interactive=False,
|
| 264 |
+
elem_classes=["contain"],
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
run_button = gr.Button("Try On", variant="primary", size="lg")
|
| 268 |
+
|
| 269 |
+
# Advanced settings
|
| 270 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 271 |
+
num_timesteps = gr.Slider(
|
| 272 |
+
minimum=10,
|
| 273 |
+
maximum=50,
|
| 274 |
+
value=50,
|
| 275 |
+
step=5,
|
| 276 |
+
label="Sampling Steps",
|
| 277 |
+
info="Higher = better quality, slower.",
|
| 278 |
+
)
|
| 279 |
+
guidance_scale = gr.Slider(
|
| 280 |
+
minimum=1.0,
|
| 281 |
+
maximum=3.0,
|
| 282 |
+
value=1.5,
|
| 283 |
+
step=0.1,
|
| 284 |
+
label="Guidance Scale",
|
| 285 |
+
info="How closely to follow the garment. 1.5 recommended.",
|
| 286 |
+
)
|
| 287 |
+
seed = gr.Number(
|
| 288 |
+
value=42,
|
| 289 |
+
label="Seed",
|
| 290 |
+
info="Random seed for reproducibility.",
|
| 291 |
+
precision=0,
|
| 292 |
+
)
|
| 293 |
+
segmentation_free = gr.Checkbox(
|
| 294 |
+
value=True,
|
| 295 |
+
label="Segmentation Free",
|
| 296 |
+
info="Preserves body features and allows unconstrained garment volume. Disable for tighter garment fitting.",
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
# Paired examples at the bottom
|
| 300 |
+
gr.Examples(
|
| 301 |
+
examples=paired_examples,
|
| 302 |
+
inputs=[person_image, garment_image, category, garment_photo_type],
|
| 303 |
+
label="Complete Examples (click to load person + garment + settings)",
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
# Event handlers
|
| 307 |
+
run_button.click(
|
| 308 |
+
fn=try_on,
|
| 309 |
+
inputs=[
|
| 310 |
+
person_image,
|
| 311 |
+
garment_image,
|
| 312 |
+
category,
|
| 313 |
+
garment_photo_type,
|
| 314 |
+
num_timesteps,
|
| 315 |
+
guidance_scale,
|
| 316 |
+
seed,
|
| 317 |
+
segmentation_free,
|
| 318 |
+
],
|
| 319 |
+
outputs=[result_image],
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
# Garment gallery selection - loads image and updates dropdowns
|
| 323 |
+
garment_gallery.select(
|
| 324 |
+
fn=on_garment_gallery_select,
|
| 325 |
+
inputs=None,
|
| 326 |
+
outputs=[garment_image, category, garment_photo_type],
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
# Configure queue with concurrency limit to prevent GPU OOM
|
| 330 |
+
demo.queue(default_concurrency_limit=1, max_size=30)
|
| 331 |
+
|
| 332 |
+
if __name__ == "__main__":
|
| 333 |
+
demo.launch(share=False)
|
banner.html
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div style="
|
| 2 |
+
display: flex;
|
| 3 |
+
flex-direction: column;
|
| 4 |
+
justify-content: center;
|
| 5 |
+
align-items: center;
|
| 6 |
+
text-align: center;
|
| 7 |
+
background: linear-gradient(45deg, #1a1a1a 0%, #333333 100%);
|
| 8 |
+
padding: 24px;
|
| 9 |
+
gap: 24px;
|
| 10 |
+
border-radius: 8px;
|
| 11 |
+
">
|
| 12 |
+
<div style="display: flex; gap: 8px;">
|
| 13 |
+
<h1 style="
|
| 14 |
+
font-size: 42px;
|
| 15 |
+
color: #fafafa;
|
| 16 |
+
margin: 0;
|
| 17 |
+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande',
|
| 18 |
+
'Lucida Sans', Arial, sans-serif;
|
| 19 |
+
">
|
| 20 |
+
FASHN VTON v1.5
|
| 21 |
+
</h1>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<p style="
|
| 25 |
+
margin: 0;
|
| 26 |
+
line-height: 1.6rem;
|
| 27 |
+
font-size: 18px;
|
| 28 |
+
color: #fafafa;
|
| 29 |
+
opacity: 0.9;
|
| 30 |
+
">
|
| 31 |
+
Efficient Maskless Virtual Try-On in Pixel Space
|
| 32 |
+
</p>
|
| 33 |
+
|
| 34 |
+
<p style="
|
| 35 |
+
margin: 0;
|
| 36 |
+
line-height: 1.5rem;
|
| 37 |
+
font-size: 14px;
|
| 38 |
+
color: #fafafa;
|
| 39 |
+
opacity: 0.7;
|
| 40 |
+
">
|
| 41 |
+
Virtual try-on model that generates photorealistic images directly in pixel space without requiring segmentation masks.
|
| 42 |
+
</p>
|
| 43 |
+
|
| 44 |
+
<div style="
|
| 45 |
+
display: flex;
|
| 46 |
+
justify-content: center;
|
| 47 |
+
align-items: center;
|
| 48 |
+
text-align: center;
|
| 49 |
+
gap: 4px;
|
| 50 |
+
flex-wrap: wrap;
|
| 51 |
+
">
|
| 52 |
+
<a href="https://fashn.ai" target="_blank" rel="noopener"><img src="https://custom-icon-badges.demolab.com/badge/FASHN_AI-333333?style=for-the-badge&logo=fashn" alt="FASHN AI" /></a>
|
| 53 |
+
<a href="https://fashn.ai/research/vton-1-5" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Project-Page-1A1A1A?style=for-the-badge" alt="Project Page" /></a>
|
| 54 |
+
<a href="https://github.com/fashn-AI/fashn-vton-1.5" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white" alt="Github" /></a>
|
| 55 |
+
<a href="https://huggingface.co/fashn-ai/fashn-vton-1.5" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model-FFD21E?style=for-the-badge" alt="HuggingFace Model" /></a>
|
| 56 |
+
<a href="#" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/arXiv-Coming%20Soon-b31b1b?style=for-the-badge&logo=arXiv&logoColor=white" alt="arXiv" /></a>
|
| 57 |
+
<a href="https://discord.gg/4XRXgJ2ysU" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge&logo=discord&logoColor=white" alt="Discord" /></a>
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.9.1
|
| 2 |
+
fashn-vton @ git+https://github.com/fashn-AI/fashn-vton-1.5.git
|
| 3 |
+
gradio
|
| 4 |
+
spaces
|
tips.html
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div style="
|
| 2 |
+
padding: 12px;
|
| 3 |
+
border: 1px solid #333333;
|
| 4 |
+
border-radius: 8px;
|
| 5 |
+
text-align: center;
|
| 6 |
+
display: flex;
|
| 7 |
+
flex-direction: column;
|
| 8 |
+
gap: 8px;
|
| 9 |
+
">
|
| 10 |
+
<b style="font-size: 18px;">Tips for best results</b>
|
| 11 |
+
|
| 12 |
+
<ul style="
|
| 13 |
+
display: flex;
|
| 14 |
+
gap: 16px;
|
| 15 |
+
justify-content: center;
|
| 16 |
+
list-style: none;
|
| 17 |
+
padding: 0;
|
| 18 |
+
margin: 0;
|
| 19 |
+
flex-wrap: wrap;
|
| 20 |
+
">
|
| 21 |
+
<li>Single person, clearly visible</li>
|
| 22 |
+
<li>|</li>
|
| 23 |
+
<li>Match category to garment type</li>
|
| 24 |
+
<li>|</li>
|
| 25 |
+
<li>Use "flat-lay" for product shots</li>
|
| 26 |
+
<li>|</li>
|
| 27 |
+
<li>2:3 aspect ratio optimal</li>
|
| 28 |
+
</ul>
|
| 29 |
+
</div>
|