Update src/core.py
Browse files- src/core.py +28 -46
src/core.py
CHANGED
|
@@ -23,58 +23,40 @@ 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
|
| 27 |
-
"You are
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
|
| 31 |
-
"MASK
|
| 32 |
-
"•
|
| 33 |
-
"
|
| 34 |
-
"•
|
| 35 |
-
"and should not be altered in any way.\n"
|
| 36 |
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"The inpainted area must blend smoothly with the unmasked regions so that no traces of the removal are visible.\n\n"
|
| 42 |
|
| 43 |
-
"INPAINTING
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
-
"
|
| 47 |
-
"
|
| 48 |
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
" • **Brightness and Contrast** – The brightness and contrast should be consistent across the image, without any abrupt changes where the object was removed.\n"
|
| 55 |
-
" • **Color Temperature** – Ensure the inpainted area aligns with the color temperature of the surrounding image (i.e., warm, cool, neutral tones).\n"
|
| 56 |
-
" • **Noise and Texture** – Maintain the same noise level and texture (grain) in the inpainted region as in the surrounding areas, avoiding unnatural smoothness or patchiness.\n\n"
|
| 57 |
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
"• Do **NOT** modify or enhance the unmasked areas (black regions). The unmasked regions should remain completely unchanged, with no alteration to the content, color, or lighting.\n"
|
| 66 |
-
"• Do **NOT** alter the **original composition**, **camera angle**, or **perspective** of the image. The overall structure of the image should remain intact.\n\n"
|
| 67 |
-
|
| 68 |
-
"FAILURE CONDITIONS (MUST BE AVOIDED):\n\n"
|
| 69 |
-
"• If any **outline, shadow, or color fragment** from the removed object is still visible in the final result, the inpainting is considered incorrect and must be re-generated.\n"
|
| 70 |
-
"• If the inpainted region **does not blend** properly with the surrounding areas (i.e., visible transitions, edge halos, ghosting effects), the result is incorrect and must be re-generated.\n\n"
|
| 71 |
-
|
| 72 |
-
"QUALITY REQUIREMENTS:\n\n"
|
| 73 |
-
"• The result must look like the object **never existed** in the original image.\n"
|
| 74 |
-
"• There should be no **ghosting**, **halo effects**, or **smearing** in the inpainted area.\n"
|
| 75 |
-
"• The final image must have **natural and realistic inpainting**. The inpainted area should seamlessly match the rest of the image, without any **patchy fills** or **repeated textures**.\n"
|
| 76 |
-
"• The **background** in the inpainted region should match the **lighting, texture, color**, and **depth** of the surrounding area.\n\n"
|
| 77 |
-
"Please ensure that all conditions are followed strictly for accurate and flawless object removal. The output should be a polished, high-quality image where the removed area is seamlessly inpainted without leaving any detectable signs of modification."
|
| 78 |
),
|
| 79 |
)
|
| 80 |
_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\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
|