From e8c83a59f2fbd466772be38500663d84596db28e Mon Sep 17 00:00:00 2001 From: Hossein Date: Sun, 30 Nov 2025 19:02:55 +0330 Subject: [PATCH] up[date --- main.py | 89 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 6cc25b2..d9d0103 100644 --- a/main.py +++ b/main.py @@ -126,25 +126,61 @@ async def try_on( # Try common key names for the UUID request_id = meta.get("request_id") or meta.get("id") or meta.get("uuid") - # Dynamic behavior based on bottom type + # ---- Dynamic behavior based on bottom/top type ---- + extra_sections = [] + + # Bottom: shorts bottom = meta.get("bottom") or {} bottom_type = (bottom.get("type") or "").lower() if bottom_type == "shorts": - # Special rule to force removal of long pants and show legs - extra_rules = """ -SPECIAL RULE FOR SHORTS (INSANELY STRICT, DO NOT IGNORE): + extra_sections.append( + """ +SPECIAL RULE FOR SHORTS (INSANELY STRICT, ZERO TOLERANCE – DO NOT IGNORE): - Metadata says the bottom garment is SHORTS. - You MUST COMPLETELY REMOVE ANY LONG PANTS OR TROUSERS from the FIRST image. - ZERO pants are allowed to remain. No black fabric, no shadows shaped like pants, - no ghost textures. If any trace of the old pants is left, the result is WRONG. + no ghost textures. If any trace of the old pants is left, the result is WRONG and UNUSABLE. - From the hem of the shorts down, the legs must be rendered as NATURAL, BARE LEGS (with socks/shoes if present) with correct skin tone, shading, lighting, and anatomy. - Only the shorts, socks and shoes may cover the legs. - You are FORBIDDEN to stack shorts on top of pants. Shorts must fully replace pants. - Shorts must match the SECOND image in color, length, silhouette and fit. """ + ) + + # Top: t-shirt / tee / short-sleeve + # We try a few common keys: "top", "upper", "outer_layer" + top = meta.get("top") or meta.get("upper") or meta.get("outer_layer") or {} + top_type = (top.get("type") or "").lower() + + if any( + token in top_type + for token in ["t-shirt", "tshirt", "tee", "t shirt"] + ): + extra_sections.append( + """ +SPECIAL RULE FOR T-SHIRT / TOP (EXTREMELY STRICT, ZERO TOLERANCE): + +- Metadata says the upper garment is a T-SHIRT / SHORT-SLEEVE TOP. +- You MUST COMPLETELY REMOVE ANY ORIGINAL SHIRT, HOODIE, JACKET OR LONG SLEEVES + from the FIRST image in the areas covered by the new top. +- No ghost sleeves, no bits of old collar, no leftover cuffs. If any part of the old top + or sleeves is still visible, the result is WRONG and MUST BE TREATED AS FAILED. +- The new T-SHIRT / TOP must match the SECOND image in: + • color + • pattern + • sleeve length + • collar shape + • overall fit and silhouette. +- Do NOT layer the new t-shirt on top of the old garment. It MUST REPLACE the old garment. +""" + ) + + if extra_sections: + extra_rules = "\n".join(extra_sections) + except Exception: metadata_text = metadata.strip() @@ -205,17 +241,19 @@ Under NO circumstances may the final image look like the SECOND person. It must always clearly be the person from the FIRST image wearing those clothes. ----------------------------------------------------- -🎯 PRIMARY OBJECTIVE +🎯 PRIMARY OBJECTIVE (ZERO TOLERANCE FOR MISTAKES) + Replace ALL clothing and accessories in the FIRST IMAGE with the outfit shown in the SECOND IMAGE, cross-verified with the metadata below. The replacement must be: -- Complete (all garments changed) +- Complete (ALL garments changed wherever indicated by the outfit and metadata) - Exact (copy the outfit items exactly) - Hyper-realistic - Seamlessly integrated - Physically correct -Do NOT leave ANY part of the original outfit visible. +If you leave **ANY** part of the original outfit visible in an area that should be replaced, +the result is considered **WRONG and FAILED**. ----------------------------------------------------- 👤 DO NOT CHANGE ANYTHING ABOUT THE USER (FIRST IMAGE) @@ -256,27 +294,33 @@ You MUST use BOTH sources: • Stitching, seams, hems, cuffs, collars, zippers, buttons, pockets, labels, prints, logos, trims • Shape, silhouette, and fabric density -2) METADATA (DESCRIPTIVE SOURCE) +2) METADATA (DESCRIPTIVE SOURCE AND HARD CHECKLIST) The following metadata describes the outfit and items: {metadata_text} {extra_rules} - Use metadata to: - - Confirm all clothing layers and components. - - Ensure no item mentioned in metadata is forgotten. - - Validate colors, patterns, and materials. - - Resolve ambiguous details from the outfit photo. - - If metadata mentions items not clearly visible, use it to refine, but do NOT invent new styles. + You MUST treat the metadata as a **STRICT CHECKLIST**: + - Every clothing item described in metadata that differs from the FIRST image MUST be updated in the final image. + - Do NOT skip or ignore ANY listed item (top, bottom, shoes, accessories, straps, etc.). + - If something is mentioned in metadata for replacement and you leave the original visible, + the result is **INCORRECT**. + - Use metadata to: + • Confirm all clothing layers and components. + • Ensure no item mentioned in metadata is forgotten. + • Validate colors, patterns, and materials. + • Resolve ambiguous details from the outfit photo. + - If metadata mentions items not clearly visible, prefer the metadata description, + but do NOT invent a style that contradicts the outfit photo. 3) COMBINED BEHAVIOR - Outfit photo is the main visual truth. - - Metadata is the checklist and description to avoid missing items. + - Metadata is the strict checklist and description to avoid missing items. - The final result MUST: • Include ALL clothing and accessories visible in the outfit photo. • Include ALL relevant items mentioned in metadata that are consistent with the outfit photo. - • Remove the original garments completely. + • Remove the original garments completely wherever replacement is implied. ----------------------------------------------------- 🧵 STRICT CLOTHING REPLACEMENT RULES @@ -302,7 +346,8 @@ You MUST use BOTH sources: 5. ACCESSORIES: - Apply all visible accessories from the outfit photo. - - If metadata mentions a glasses holder strap around the neck, it must appear naturally placed according to anatomy and perspective. + - If metadata mentions a glasses holder strap around the neck, it must appear naturally placed + according to anatomy and perspective. 6. NO NEW DESIGN ELEMENTS: - Do NOT invent new zippers, seams, logos, or prints. @@ -436,10 +481,10 @@ SECOND image = outfit_photo (outfit reference). safety_ratings = cand.safety_ratings if safety_ratings: blocked = [ - f"{getattr(r, 'category', 'unknown')}" - for r in safety_ratings - if hasattr(r, "blocked") and getattr(r, "blocked", False) - ] + f"{getattr(r, 'category', 'unknown')}" + for r in safety_ratings + if hasattr(r, "blocked") and getattr(r, "blocked", False) + ] if blocked: message += f" Safety blocked: {', '.join(blocked)}"