Update src/core.py
Browse files- 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
|
| 27 |
"You are given:\n"
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
| 40 |
-
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
-
|
| 47 |
-
"
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
|
| 58 |
-
"
|
| 59 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|