SpaceNugget commited on
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
Files changed (2) hide show
  1. app.py +42 -21
  2. 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 the accessories — keep the entire lower body from Picture 1 pixel-perfect. "
252
- "Remove only the shirt, top, or jacket from Picture 1 and replace it with the exact garment shown in Picture 2, "
253
- "strictly preserving the color, graphic, pattern, and material of the garment in Picture 2. "
254
- "Do not add or change any lower body clothing. "
 
 
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
- "strictly preserving its (garment from Picture 2) color, material and design. "
 
 
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
- "strictly preserving its (garment from Picture 2) color, material and design. "
 
 
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 the dominant color and pattern of a garment.
337
- Returns a short description like 'green plaid' or 'white floral print'
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 = _best(_COLOR_CANDIDATES, "a {} colored piece of clothing")
351
- pattern = _best(_PATTERN_CANDIDATES, "a {} fabric or textile")
 
 
 
352
 
353
- # Don't say "green solid plain color" — drop pattern when it adds nothing
354
- if "solid" in pattern or "plain" in pattern:
355
- desc = color
356
- else:
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": 12,
26
  "width": ["115", 0],
27
  "height": ["115", 1]
28
  },
@@ -101,8 +101,8 @@
101
  },
102
  "110": {
103
  "inputs": {
104
- "upscale_method": "nearest-exact",
105
- "megapixels": 1,
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
  },