LogicGoInfotechSpaces commited on
Commit
6d2caf9
·
verified ·
1 Parent(s): 41ae1c4

Update src/core.py

Browse files
Files changed (1) hide show
  1. 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 TYPE: STRICT IMAGE INPAINTING — OBJECT REMOVAL ONLY\n\n"
27
- "You are provided with two images:\n\n"
28
- "1) The original image (Image A) which contains the scene with various objects.\n"
29
- "2) The binary mask image (Image B) that highlights the region(s) to be removed in the original image.\n\n"
30
 
31
- "MASK RULE (MANDATORY):\n\n"
32
- "• In the mask image (Image B), white pixels (#FFFFFF) represent the exact regions in the original image (Image A) "
33
- "that need to be completely removed.\n"
34
- "• Black pixels (#000000) in the mask image indicate areas of the original image that must remain completely unchanged "
35
- "and should not be altered in any way.\n"
36
 
37
- "PRIMARY OBJECTIVE:\n\n"
38
- "The goal is to **remove** all the objects or parts of objects that are highlighted in the white-masked regions of the mask image. "
39
- "The object in the white region must be **entirely erased** with no visible remnants, shadows, outlines, or color traces remaining. "
40
- "Once the objects are removed, the region should be seamlessly filled by **inpainting** using only the surrounding background information from the original image. "
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 INSTRUCTIONS:\n\n"
44
- "1) **Object Recognition and Removal:**\n"
45
- " The model should first **understand** that the white areas in the binary mask represent the specific regions where objects or elements need to be **completely removed**. "
46
- " This could be anything from objects, people, text, or any unwanted areas in the image. It should not leave any part of the removed object behind — not even partial shapes, shadows, outlines, or color traces.\n"
47
- " The object removal should ensure that no part of the deleted object is visible in the final image.\n\n"
48
 
49
- "2) **Inpainting the Removed Region:**\n"
50
- " After removing the designated regions, the surrounding **background textures, patterns, and structures** should be used to **fill in** the removed area. "
51
- " This should be done by **extending the background information** naturally, continuing the textures, structures, and lighting patterns that were present in the surrounding unmasked regions.\n"
52
- " The model should focus on ensuring that the inpainted region **matches** the existing background in terms of:\n"
53
- " • **Lighting Direction** Ensure the lighting in the inpainted region matches the natural direction and intensity of the surrounding areas.\n"
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
- "3) **Seamless Blending:**\n"
59
- " The inpainting should blend **seamlessly** with the surrounding areas, creating a smooth transition between the removed object and the rest of the image. "
60
- " This includes extending edges, lines, and surfaces naturally across the removed area. The goal is that **the boundary of the inpainted region should be indistinguishable from the original background**, "
61
- " without any visible edge halos, smearing, or rough transitions.\n\n"
62
 
63
- "STRICT CONSTRAINTS:\n\n"
64
- " Do **NOT** generate or keep any part of the removed object. There should be no visible remnants, outlines, or partial shapes from the deleted object.\n"
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