LogicGoInfotechSpaces commited on
Commit
118703c
·
verified ·
1 Parent(s): 6d2caf9

Update src/core.py

Browse files
Files changed (1) hide show
  1. src/core.py +44 -33
src/core.py CHANGED
@@ -23,40 +23,51 @@ DEFAULT_MODEL_ID = os.environ.get("GEMINI_IMAGE_MODEL", "gemini-3-pro-image-prev
23
  DEFAULT_PROMPT = os.environ.get(
24
  "GEMINI_IMAGE_PROMPT",
25
  (
26
- "TASK: STRICT IMAGE INPAINTING — MASK-BOUNDED OBJECT REMOVAL ONLY\n\n"
27
  "You are given:\n"
28
- " Image A: the original image.\n"
29
- " Image B: a binary mask.\n\n"
30
-
31
- "MASK INTERPRETATION (CRITICAL):\n\n"
32
- " **Pure white (#FFFFFF)** pixels in Image B mark the ONLY pixels that may be modified.\n"
33
- " **Pure black (#000000)** pixels in Image B are **LOCKED** and **MUST remain IDENTICAL** to Image A.\n"
34
- " **Do not** extend, expand, infer, or reinterpret the mask in any way.\n\n"
35
-
36
- "OBJECT REMOVAL:\n\n"
37
- "• **Completely remove** any visual content that exists strictly within the white mask region.\n"
38
- "• Do **NOT** remove, modify, or reconstruct any object parts that extend outside the white mask.\n"
39
- " If the mask overlaps only part of an object, **remove ONLY the masked pixels** and leave the rest untouched.\n\n"
40
-
41
- "INPAINTING RULES:\n\n"
42
- " **Fill the masked area** using ONLY immediate surrounding background pixels from Image A.\n"
43
- "• **Continue existing textures, colors, lighting, and geometry naturally** to match the unmasked regions.\n"
44
- "**Do NOT invent new objects, structures, shadows, reflections, or background elements** in the inpainted region.\n"
45
- " **Do NOT smooth, blur, or stylize** the inpainted region. The result should look as natural and seamless as possible.\n\n"
46
-
47
- "STRICT CONSTRAINTS (NO EXCEPTIONS):\n\n"
48
- " **Do NOT** modify any black (unmasked) pixel.\n"
49
- "• **Do NOT** remove entire objects unless they are **fully masked** (i.e., entirely white in the mask).\n"
50
- "**Do NOT** alter the image framing, perspective, or global appearance of Image A.\n"
51
- " **Do NOT** apply any semantic cleanup or scene optimization that goes beyond the direct instructions of the mask.\n\n"
52
-
53
- "QUALITY REQUIREMENT:\n\n"
54
- " The final result must look like the **masked pixels never existed** in Image A.\n"
55
- " The inpainted region must blend **seamlessly** with surrounding pixels in terms of texture, color, and lighting.\n"
56
- "• **No halos, ghosting, color shifts**, or **texture repetition** should be visible in the final output.\n\n"
57
-
58
- "IMPORTANT:\n\n"
59
- "If a conflict exists between **semantic understanding** and the **mask**, **ALWAYS FOLLOW THE MASK EXACTLY**."
 
 
 
 
 
 
 
 
 
 
 
60
  ),
61
  )
62
  _GENAI_MODEL: genai.GenerativeModel | None = None
 
23
  DEFAULT_PROMPT = os.environ.get(
24
  "GEMINI_IMAGE_PROMPT",
25
  (
26
+ "TASK: STRICT IMAGE INPAINTING — MASK-BOUNDED OBJECT REMOVAL ONLY\n"
27
  "You are given:\n"
28
+ "1) **Image A**: The original image, which contains various elements and objects.\n"
29
+ "2) **Image B**: A binary mask that highlights the areas to be removed from the original image.\n"
30
+ "\n"
31
+ "**Step 1: Image and Mask Classification**:\n"
32
+ "- First, **classify** the two images:\n"
33
+ " - Image A is the **original image** with visible content that may include objects, background, and scene elements.\n"
34
+ " - Image B is a **binary mask**, where:\n"
35
+ " - **White pixels (#FFFFFF)** indicate areas of Image A that need to be removed.\n"
36
+ " - **Black pixels (#000000)** indicate areas that must **remain unchanged** from Image A.\n"
37
+ "\n"
38
+ "**Step 2: Understand What to Remove**:\n"
39
+ "- **Examine Image B carefully** to identify **all white areas** (the regions that need removal).\n"
40
+ "- **Understand the objects and parts of objects** that the white mask covers. If the mask partially overlaps any object, only the covered area should be removed.\n"
41
+ "- The model must **recognize and understand** the object(s) within the white-masked regions before proceeding with the removal.\n"
42
+ "- **Do NOT attempt to remove any content outside the white mask**, even if it appears similar to the content inside the mask. Only remove what is explicitly masked in Image B.\n"
43
+ "\n"
44
+ "**Step 3: Object Removal**:\n"
45
+ "- **Completely remove** everything inside the white-masked region. This includes:\n"
46
+ " - Erasing the object(s) entirely with **no visible remnants**, including shadows, outlines, or color traces.\n"
47
+ " - If the mask overlaps only part of an object, **only remove the pixels covered by the white mask**, leaving the rest of the object untouched.\n"
48
+ "- The goal is to **clear the masked region** entirely, **removing all visual content** from it.\n"
49
+ "\n"
50
+ "**Step 4: Inpainting and Filling the Masked Area**:\n"
51
+ "- After removal, **fill the masked area** using **only the immediate surrounding background pixels** from Image A.\n"
52
+ "- Continue existing **textures, colors, lighting, and geometry naturally**.\n"
53
+ " - Ensure that the **lighting**, **brightness**, **contrast**, and **color temperature** of the inpainted region perfectly match the surrounding unmasked areas.\n"
54
+ " - Do **not invent new structures, objects, shadows**, or **reflections** that were not originally present in the scene.\n"
55
+ " - **Do not smooth, blur, or stylize** the inpainted region. The transition should be smooth and seamless.\n"
56
+ "\n"
57
+ "STRICT CONSTRAINTS (NO EXCEPTIONS):\n"
58
+ "- **Do NOT modify any black (unmasked) pixels**. The unmasked areas must remain exactly as they are in Image A.\n"
59
+ "- **Do NOT remove entire objects** unless they are **fully masked**. Only the regions inside the white mask should be modified.\n"
60
+ "- **Do NOT alter the framing, perspective**, or **global appearance** of the image. The overall structure of the image must remain intact.\n"
61
+ "- **Do NOT apply any semantic cleanup** or scene optimization. This is a **strict removal task**; only the content inside the white mask should be removed.\n"
62
+ "\n"
63
+ "QUALITY REQUIREMENTS:\n"
64
+ "- The final result must look like the object never existed in the original image.\n"
65
+ "- The inpainted region should blend **seamlessly** with surrounding pixels.\n"
66
+ "- **No visible artifacts**, such as ghosting, halos, color shifts, or texture repetition, should be present.\n"
67
+ "- The transition between the inpainted region and the unmasked areas must be **natural** and **imperceptible**.\n"
68
+ "\n"
69
+ "IMPORTANT:\n"
70
+ "If a conflict exists between **semantic understanding** and the **mask**, **ALWAYS follow the mask exactly**. The mask is the **absolute guide** for removal, and no other interpretation or inference should take place. The model should strictly follow the instructions from the mask without altering the intended areas."
71
  ),
72
  )
73
  _GENAI_MODEL: genai.GenerativeModel | None = None