Spaces:
Paused
Paused
Commit ·
e1b8d5e
1
Parent(s): e3c5bff
improve: richer garment description + stronger prompt + 16 steps + 2MP ref- describe_garment now detects sleeve type, neckline, and special features (tie/bow, buttons, ruffles, etc.) using CLIP zero-shot — gives the model a much more specific caption to work from- Prompts now explicitly instruct the model to preserve sleeve shape, neckline, silhouette, and decorative elements without simplifying- Steps: 12 → 16 (better detail at ~25% more inference time)- Clothing reference: 1.5 → 2.0 megapixels (more detail in the conditioning)
Browse files- app.py +42 -21
- workflow_api.json +3 -3
app.py
CHANGED
|
@@ -248,27 +248,33 @@ _GARMENT_TYPES = ["upper", "lower", "full"]
|
|
| 248 |
_PROMPTS = {
|
| 249 |
"upper": (
|
| 250 |
"start with Picture 1 as the base image, keeping its lighting, environment, and background. "
|
| 251 |
-
"Do NOT change the pants, trousers, shorts, skirt, shoes or
|
| 252 |
-
"Remove only the
|
| 253 |
-
"
|
| 254 |
-
"
|
|
|
|
|
|
|
| 255 |
"Match the pose from Picture 1, high quality, sharp details, 4k. "
|
| 256 |
-
"Preserve the face, hair and expression from Picture 1."
|
| 257 |
),
|
| 258 |
"lower": (
|
| 259 |
"start with Picture 1 as the base image, keeping its lighting, environment, and background. "
|
| 260 |
"Keep the top/shirt/jacket and the shoes/feet/accessories from Picture 1 exactly as they are. "
|
| 261 |
-
"Remove only the pants/skirt/shorts from Picture 1 and replace them with the garment from Picture 2
|
| 262 |
-
"
|
|
|
|
|
|
|
| 263 |
"Match the pose from Picture 1, high quality, sharp details, 4k. "
|
| 264 |
-
"Preserve the face and expression from Picture 1."
|
| 265 |
),
|
| 266 |
"full": (
|
| 267 |
"start with Picture 1 as the base image, keeping its lighting, environment, and background. "
|
| 268 |
-
"Remove the entire outfit from Picture 1 and replace it completely with the garment from Picture 2
|
| 269 |
-
"
|
|
|
|
|
|
|
| 270 |
"Match the pose from Picture 1, high quality, sharp details, 4k. "
|
| 271 |
-
"Preserve the face and expression from Picture 1."
|
| 272 |
),
|
| 273 |
}
|
| 274 |
|
|
@@ -331,11 +337,24 @@ _PATTERN_CANDIDATES = [
|
|
| 331 |
"polka dots", "geometric pattern", "animal print", "abstract print",
|
| 332 |
"camouflage", "color block", "embroidered", "lace",
|
| 333 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
def describe_garment(img_pil: Image.Image) -> str:
|
| 336 |
-
"""Use CLIP to detect
|
| 337 |
-
Returns a
|
| 338 |
-
that gets injected into the generation prompt for better adherence."""
|
| 339 |
model, processor = _load_clip()
|
| 340 |
|
| 341 |
def _best(candidates, prompt_template):
|
|
@@ -347,14 +366,16 @@ def describe_garment(img_pil: Image.Image) -> str:
|
|
| 347 |
logits = model(**inputs).logits_per_image[0]
|
| 348 |
return candidates[logits.argmax().item()]
|
| 349 |
|
| 350 |
-
color
|
| 351 |
-
pattern
|
|
|
|
|
|
|
|
|
|
| 352 |
|
| 353 |
-
#
|
| 354 |
-
if "solid" in pattern or "plain" in pattern
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
desc = f"{color} {pattern}"
|
| 358 |
print(f"Garment description: {desc}")
|
| 359 |
return desc
|
| 360 |
|
|
|
|
| 248 |
_PROMPTS = {
|
| 249 |
"upper": (
|
| 250 |
"start with Picture 1 as the base image, keeping its lighting, environment, and background. "
|
| 251 |
+
"Do NOT change the pants, trousers, shorts, skirt, shoes or accessories — keep the entire lower body from Picture 1 pixel-perfect. "
|
| 252 |
+
"Remove only the top/shirt/jacket from Picture 1 and replace it with the exact garment shown in Picture 2. "
|
| 253 |
+
"Copy every single detail of the garment in Picture 2: its precise color, fabric texture, pattern, print, "
|
| 254 |
+
"sleeve length and shape, neckline, silhouette, fit, and all decorative elements such as ties, bows, buttons, ruffles, lace, or drawstrings. "
|
| 255 |
+
"Do not simplify or genericise any feature — reproduce it faithfully. "
|
| 256 |
+
"Do not add or alter any lower body clothing. "
|
| 257 |
"Match the pose from Picture 1, high quality, sharp details, 4k. "
|
| 258 |
+
"Preserve the face, hair and expression from Picture 1 exactly."
|
| 259 |
),
|
| 260 |
"lower": (
|
| 261 |
"start with Picture 1 as the base image, keeping its lighting, environment, and background. "
|
| 262 |
"Keep the top/shirt/jacket and the shoes/feet/accessories from Picture 1 exactly as they are. "
|
| 263 |
+
"Remove only the pants/skirt/shorts from Picture 1 and replace them with the exact garment from Picture 2. "
|
| 264 |
+
"Copy every detail of the garment in Picture 2: its precise color, fabric, pattern, length, silhouette, "
|
| 265 |
+
"waistband style, and any decorative elements such as pleats, pockets, or belts. "
|
| 266 |
+
"Do not simplify or genericise any feature — reproduce it faithfully. "
|
| 267 |
"Match the pose from Picture 1, high quality, sharp details, 4k. "
|
| 268 |
+
"Preserve the face and expression from Picture 1 exactly."
|
| 269 |
),
|
| 270 |
"full": (
|
| 271 |
"start with Picture 1 as the base image, keeping its lighting, environment, and background. "
|
| 272 |
+
"Remove the entire outfit from Picture 1 and replace it completely with the exact garment from Picture 2. "
|
| 273 |
+
"Copy every detail of the garment in Picture 2: its precise color, fabric, pattern, silhouette, "
|
| 274 |
+
"sleeve style, neckline, length, and all decorative elements. "
|
| 275 |
+
"Do not simplify or genericise any feature — reproduce it faithfully. "
|
| 276 |
"Match the pose from Picture 1, high quality, sharp details, 4k. "
|
| 277 |
+
"Preserve the face and expression from Picture 1 exactly."
|
| 278 |
),
|
| 279 |
}
|
| 280 |
|
|
|
|
| 337 |
"polka dots", "geometric pattern", "animal print", "abstract print",
|
| 338 |
"camouflage", "color block", "embroidered", "lace",
|
| 339 |
]
|
| 340 |
+
_SLEEVE_CANDIDATES = [
|
| 341 |
+
"sleeveless", "short sleeve", "long sleeve", "3/4 sleeve",
|
| 342 |
+
"balloon or puff sleeve", "cropped sleeve",
|
| 343 |
+
]
|
| 344 |
+
_NECKLINE_CANDIDATES = [
|
| 345 |
+
"v-neck", "round crew neck", "collared button-up shirt",
|
| 346 |
+
"turtleneck", "scoop neck", "off-shoulder neckline",
|
| 347 |
+
]
|
| 348 |
+
_FEATURE_CANDIDATES = [
|
| 349 |
+
"no special features", "tie or bow at waist or neck",
|
| 350 |
+
"buttons down the front", "ruffles or frills", "lace trim",
|
| 351 |
+
"drawstring or elastic waist", "belt", "pockets",
|
| 352 |
+
]
|
| 353 |
|
| 354 |
def describe_garment(img_pil: Image.Image) -> str:
|
| 355 |
+
"""Use CLIP to detect color, pattern, sleeve type, neckline, and special features.
|
| 356 |
+
Returns a rich description like 'beige plaid long sleeve v-neck with tie at waist'
|
| 357 |
+
that gets injected into the generation prompt for better detail adherence."""
|
| 358 |
model, processor = _load_clip()
|
| 359 |
|
| 360 |
def _best(candidates, prompt_template):
|
|
|
|
| 366 |
logits = model(**inputs).logits_per_image[0]
|
| 367 |
return candidates[logits.argmax().item()]
|
| 368 |
|
| 369 |
+
color = _best(_COLOR_CANDIDATES, "a {} colored piece of clothing")
|
| 370 |
+
pattern = _best(_PATTERN_CANDIDATES, "a {} fabric or textile")
|
| 371 |
+
sleeve = _best(_SLEEVE_CANDIDATES, "a piece of clothing with {} sleeves")
|
| 372 |
+
neckline = _best(_NECKLINE_CANDIDATES, "a {} piece of clothing")
|
| 373 |
+
feature = _best(_FEATURE_CANDIDATES, "a piece of clothing with {}")
|
| 374 |
|
| 375 |
+
# Build compact but information-dense description
|
| 376 |
+
pattern_str = "" if ("solid" in pattern or "plain" in pattern) else f" {pattern}"
|
| 377 |
+
feature_str = "" if "no special" in feature else f" with {feature}"
|
| 378 |
+
desc = f"{color}{pattern_str} {sleeve} {neckline}{feature_str}"
|
|
|
|
| 379 |
print(f"Garment description: {desc}")
|
| 380 |
return desc
|
| 381 |
|
workflow_api.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
},
|
| 23 |
"100": {
|
| 24 |
"inputs": {
|
| 25 |
-
"steps":
|
| 26 |
"width": ["115", 0],
|
| 27 |
"height": ["115", 1]
|
| 28 |
},
|
|
@@ -101,8 +101,8 @@
|
|
| 101 |
},
|
| 102 |
"110": {
|
| 103 |
"inputs": {
|
| 104 |
-
"upscale_method": "
|
| 105 |
-
"megapixels":
|
| 106 |
"resolution_steps": 1,
|
| 107 |
"image": ["135:133", 0]
|
| 108 |
},
|
|
|
|
| 22 |
},
|
| 23 |
"100": {
|
| 24 |
"inputs": {
|
| 25 |
+
"steps": 16,
|
| 26 |
"width": ["115", 0],
|
| 27 |
"height": ["115", 1]
|
| 28 |
},
|
|
|
|
| 101 |
},
|
| 102 |
"110": {
|
| 103 |
"inputs": {
|
| 104 |
+
"upscale_method": "lanczos",
|
| 105 |
+
"megapixels": 2.0,
|
| 106 |
"resolution_steps": 1,
|
| 107 |
"image": ["135:133", 0]
|
| 108 |
},
|