Update src/core.py
Browse files- src/core.py +45 -41
src/core.py
CHANGED
|
@@ -22,52 +22,56 @@ log = logging.getLogger(__name__)
|
|
| 22 |
DEFAULT_MODEL_ID = os.environ.get("GEMINI_IMAGE_MODEL", "gemini-3-pro-image-preview")
|
| 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 |
-
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
| 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 |
-
|
| 45 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
"
|
| 49 |
-
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
"
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
-
|
| 62 |
-
"\n"
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
|
| 68 |
-
"\n"
|
| 69 |
-
"
|
| 70 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
),
|
| 72 |
)
|
| 73 |
_GENAI_MODEL: genai.GenerativeModel | None = None
|
|
|
|
| 22 |
DEFAULT_MODEL_ID = os.environ.get("GEMINI_IMAGE_MODEL", "gemini-3-pro-image-preview")
|
| 23 |
DEFAULT_PROMPT = os.environ.get(
|
| 24 |
"GEMINI_IMAGE_PROMPT",
|
| 25 |
+
("TASK: STRICT IMAGE INPAINTING — MASK-BOUNDED OBJECT REMOVAL ONLY\n\n"
|
|
|
|
| 26 |
"You are given:\n"
|
| 27 |
"1) **Image A**: The original image, which contains various elements and objects.\n"
|
| 28 |
+
"2) **Image B**: A binary mask that highlights the areas to be removed from the original image.\n\n"
|
| 29 |
+
|
| 30 |
+
"MASK INTERPRETATION (CRITICAL):\n\n"
|
| 31 |
+
"• **White pixels (#FFFFFF)** in Image B represent **the exact regions** in Image A that need to be removed. Only these regions can be modified or deleted.\n"
|
| 32 |
+
"• **Black pixels (#000000)** in Image B must **remain completely unchanged** in Image A. Do **NOT** modify or generate anything in these black areas.\n"
|
| 33 |
+
"• **Do NOT** modify or alter any other parts of Image A that are outside the white-masked region. Do not paint, blur, or alter any pixels that are not covered by the white mask.\n"
|
| 34 |
+
"• **Do NOT** attempt to remove or alter anything in the unmasked regions, even if the object in the unmasked area looks similar to the object inside the mask.\n"
|
| 35 |
+
"• **The white-masked region is the **only** area to be modified. The rest of the image must **remain intact**. No other object or area should be painted or modified.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
"\n"
|
| 37 |
+
|
| 38 |
+
"STEP 1: OBJECT REMOVAL ANALYSIS\n\n"
|
| 39 |
+
"• **Analyze the mask carefully** and **identify the exact areas** to be removed. Only focus on the white-masked region for removal.\n"
|
| 40 |
+
"• The model must recognize what needs to be removed based on the white mask and **do nothing to the black (unmasked) regions**.\n"
|
| 41 |
+
"• Do **NOT** modify, erase, or paint anything outside the white-masked region. Only remove what is explicitly covered by the white mask.\n\n"
|
| 42 |
+
|
| 43 |
+
"STEP 2: OBJECT REMOVAL\n\n"
|
| 44 |
+
"• **Completely remove** everything inside the white-masked region in Image A. This includes:\n"
|
| 45 |
" - Erasing the object(s) entirely with **no visible remnants**, including shadows, outlines, or color traces.\n"
|
| 46 |
" - 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"
|
| 47 |
+
"• The goal is to **clear the masked region** entirely, **removing all visual content** from it.\n\n"
|
| 48 |
+
|
| 49 |
+
"IMPORTANT NOTE ABOUT INPAINTING:\n\n"
|
| 50 |
+
"• **The inpainted region must NOT be filled with pure white (#FFFFFF)**. The model should **never** generate a blank, white, or featureless region.\n"
|
| 51 |
+
"• The white areas should be filled with **the natural surrounding background** of Image A. This means extending **existing textures, colors, lighting, and geometry naturally**, without introducing any artificial white filling.\n"
|
| 52 |
+
"• **Do not paint or alter any other region** in the image, including the unmasked areas. **Only the white-masked area** should be modified, and no other content should be painted or changed.\n\n"
|
| 53 |
+
|
| 54 |
+
"INPAINTING RULES:\n\n"
|
| 55 |
+
"• After the object is removed, **fill the masked area** using **only the immediate surrounding pixels** from Image A.\n"
|
| 56 |
+
"• **Do not invent new objects, structures, or details**. Only extend or copy background textures, lighting, and geometry from the unmasked areas.\n"
|
| 57 |
+
"• The lighting, contrast, brightness, color temperature, and texture in the inpainted region must **perfectly match** the surrounding areas.\n"
|
| 58 |
+
"• **Do not add** shadows, reflections, or new structures to the inpainted region.\n"
|
| 59 |
+
"• The inpainted region should seamlessly blend with the surrounding pixels. It should appear as though the object was **never there**.\n\n"
|
| 60 |
+
|
| 61 |
+
"STRICT CONSTRAINTS (NO EXCEPTIONS):\n\n"
|
| 62 |
+
"• **Do NOT modify any black (unmasked) pixels**. The unmasked areas must remain **exactly** as they are in Image A.\n"
|
| 63 |
+
"• **Do NOT remove entire objects** unless they are **fully and completely masked**. Only the regions inside the white mask should be modified.\n"
|
| 64 |
+
"• **Do NOT alter the original image's **framing**, **perspective**, or **composition**. Only the regions inside the white mask should be affected.\n"
|
| 65 |
+
"• **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"
|
| 66 |
+
|
| 67 |
+
"QUALITY REQUIREMENTS:\n\n"
|
| 68 |
+
"• The final result should look as though the object **never existed** in the original image.\n"
|
| 69 |
+
"• The inpainted region must blend **seamlessly** with surrounding pixels.\n"
|
| 70 |
+
"• **No visible artifacts**, such as ghosting, halos, color shifts, or texture repetition, should be present.\n"
|
| 71 |
+
"• The transition between the inpainted region and the unmasked areas must be **natural** and **imperceptible**.\n\n"
|
| 72 |
+
|
| 73 |
+
"IMPORTANT:\n\n"
|
| 74 |
+
"If there is a conflict between **semantic understanding** and the **mask**, **ALWAYS follow the mask exactly**. The mask is the **absolute guide**, and no interpretation should deviate from the mask’s instructions.\n"
|
| 75 |
),
|
| 76 |
)
|
| 77 |
_GENAI_MODEL: genai.GenerativeModel | None = None
|