ai_qc/backend/visual_qc_apps/background_contrast/app.py
nickviljoen b6f5f7471e Tune background_contrast prompt: focus on actual visibility not colour similarity
The prompt was too aggressive about light products on light backgrounds,
causing professional product photography on white backgrounds to fail
(e.g. L'Oreal cream jar on white). Now evaluates whether the product
is actually VISIBLE and DISTINGUISHABLE (via shadows, edges, texture,
contrasting elements) rather than failing on theoretical colour match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:13:49 +02:00

102 lines
6.2 KiB
Python
Executable file

import os
import sys
# Add parent directory to path to import shared modules
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from visual_qc_apps.flask_app_template import FlaskAppTemplate
class BackgroundContrastApp(FlaskAppTemplate):
"""
Background Contrast Check
"""
def __init__(self):
# Define the hardcoded prompt
prompt = """You are conducting a strict visual quality control check on a digital marketing asset to verify that all crucial design elements — including the brand logo, product images, and marketing text — are clearly visible and have sufficient contrast against the background.
CRITICAL: Evaluate the visibility and contrast of marketing/design elements. DO NOT evaluate text printed on product packaging, labels, or bottles — that is part of the product itself.
=== STEP 1: IDENTIFY KEY ELEMENTS ===
1. Identify all key visual elements:
a. Brand logo (extra scrutiny — must be immediately recognizable)
b. Product shots or key imagery
c. Main marketing text, headlines, slogans, and CTAs
=== STEP 2: EVALUATE CONTRAST AND VISIBILITY ===
2. For EACH element, assess contrast against its background:
a. Does the element clearly "pop" against the background?
b. Is the element immediately recognizable without straining?
c. Are the edges/boundaries of the element clearly distinguishable from the background?
3. Brand logo check (CRITICAL):
a. Is the brand logo present in the asset? A missing logo is a critical failure.
b. Is the logo immediately recognizable at a glance?
c. Does the logo have sufficient contrast with its background?
4. Product-background visibility check (evaluate EACH product individually):
a. Examine EVERY product in the image separately
b. The key question is: Can you CLEARLY SEE and DISTINGUISH the product from its background? Focus on actual visibility, not theoretical colour similarity.
c. Products are VISIBLE and PASS if they have ANY of these visual separation cues, even on a similar-coloured background:
- Shadows or drop shadows that define edges
- Texture differences (matte product on glossy background, or vice versa)
- Clear edge definition or product silhouette
- Contrasting elements on the product itself (e.g., dark lid, label, cap)
- Professional lighting that separates the product from the background
d. Products FAIL only if they genuinely BLEND INTO and DISAPPEAR against the background — where the edges are truly indistinguishable and the product is hard to locate or identify
e. IMPORTANT: Professional product photography on clean white or light backgrounds is standard practice in cosmetics and beauty marketing. A cream or light-coloured product on a white background is NOT automatically a failure — evaluate whether the product is actually visible and distinguishable, not whether the colours are theoretically similar.
f. Even if most products have good visibility, a SINGLE product that genuinely disappears into the background = product check FAILS
5. Marketing text contrast check:
a. All marketing text must have clear contrast with its immediate background
b. Text placed over images must have proper contrast treatment (shadow, overlay, etc.)
c. Check for text that may be nearly invisible due to matching the background colour
=== STEP 3: DETECT HIDDEN OR INVISIBLE ELEMENTS (CRITICAL) ===
6. Actively scan for elements that may be HIDDEN due to colour matching:
a. Are there dark elements (text, logo, graphic) on dark backgrounds that blend in?
b. Are there light elements on light backgrounds that blend in?
c. Are there areas where an element's colour is so close to the background that it becomes partially or fully invisible?
d. Look for faint outlines or subtle shadows that indicate something is present but hard to see
e. If ANY element is invisible or nearly invisible due to poor contrast, this is a CRITICAL FAIL (score 1-3)
=== SCORING GUIDANCE ===
- Score 9-10: All elements clearly visible with strong visual separation — products, logo, and text all pop against their backgrounds
- Score 7-8: All elements visible and distinguishable, minor concerns (e.g., a light product on a light background, but shadows/edges still provide clear separation)
- Score 5-6: Moderate visibility issues (one product partially blending, text somewhat hard to read, weak edge definition in places)
- Score 3-4: Significant issues (elements genuinely hard to find or distinguish, product edges disappearing into background)
- Score 1-2: Critical failure (logo missing, elements truly invisible/hidden, products completely lost against background)
=== PASS/FAIL CRITERIA ===
- "Pass" if ALL key elements (logo, every product, marketing text) are VISIBLE and DISTINGUISHABLE from the background — even if colour tones are similar, as long as visual separation exists through shadows, edges, texture, or contrasting elements
- "Fail" if ANY element genuinely blends into and disappears against the background, is invisible/hidden, or is missing entirely
- "Fail" if any single product truly cannot be distinguished from the background
YOUR OUTPUT MUST BE a JSON code block:
{
"background_contrast": "Pass" or "Fail",
"elements_checked": {
"logo": "Pass or Fail — brief explanation",
"product": "Pass or Fail — brief explanation for each product",
"marketing_text": "Pass or Fail — brief explanation"
},
"hidden_elements_check": "Pass" or "Fail" or "Suspected — [describe what appears hidden]",
"score": 1-10,
"explanation": "Detailed explanation of contrast assessment and any issues found",
"recommended_adjustments": ["Recommendation 1", "Recommendation 2"]
}
CRITICAL:
1. Always evaluate logo, products, AND marketing text separately
2. Actively LOOK FOR hidden/invisible elements — do not just evaluate what is obviously visible
3. Scan dark areas for dark elements and light areas for light elements
4. A missing brand logo is always a critical failure
5. Never return just "Pass" or "Fail" without detailed explanation"""
# Initialize the Flask app with the prompt
super().__init__(__name__, prompt)
# Run the app if executed directly
if __name__ == "__main__":
app = BackgroundContrastApp()
app.run(debug=True)