ai_qc/backend/visual_qc_apps/amazon_margins/app.py
nickviljoen 20259dcad0 Add Honda client, video QC, session refresh, Amazon check tuning
- Add Honda client with static_general and video_general profiles
- Add video QC capability using Gemini native video analysis (4 checks:
  visual_quality, brand_consistency, text_legibility, pacing_flow)
- Add video_general profile assigned to all 8 clients
- Extend session lifetime with MSAL silent token refresh (proactive
  every 45min + reactive on expiry), switch cache to localStorage
- Re-enable OCR layout measurements for Amazon checks
- Add scope boundary notes to all 6 Amazon checks to prevent cross-
  check penalization (locale errors isolated to logo_country only)
- Relax margins left-alignment tolerance from 1% to 4% to account
  for logo lockup internal padding
- Update brand guidelines DB with Amazon localization matrix and
  processed Dove PDF summary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:53:52 +02:00

130 lines
9.5 KiB
Python

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 AmazonMarginsApp(FlaskAppTemplate):
"""
Amazon ASD 2025 - Margins Check
Validates margin rules based on format dimensions.
"""
def __init__(self):
prompt = """You are performing a visual quality-control check on an Amazon marketing asset. Your task is to evaluate whether the layout has appropriate margins — clear space between the main content and the edges of the asset.
SCOPE NOTE: This check focuses ONLY on margins (distance from content to edges) and left-alignment consistency across elements. Font characteristics, size ratios between text elements, and line breaks are evaluated by the separate amazon_typography and amazon_headline_layout checks. Locale/country errors (wrong URL, wrong language) are evaluated by the separate amazon_logo_country check. Do NOT penalise for locale issues or duplicate other checks' assessments here.
WHAT ARE MARGINS:
Margins are the empty/background space between the edges of the asset and the important content (headline text, date text, logo). Good margins give the design breathing room and prevent content from looking cramped or cut off.
MEASUREMENT DATA:
If OCR LAYOUT MEASUREMENTS are provided at the end of this prompt, use them as supplementary data to support your visual assessment. OCR bounding boxes can have small inaccuracies (~5-10px), so use them to confirm or question what you see visually, but do NOT fail an asset solely based on OCR numbers if the layout looks visually correct and well-composed.
VISUAL ASSESSMENT APPROACH:
If no OCR measurements are available, assess margins VISUALLY:
1. HEADLINE MARGINS (most important):
- Look at the space between the HEADLINE TEXT and the nearest edges (top, left, and right).
- There should be a visible band of empty space — roughly the height of 1-2 capital letters in the headline — between the headline and the edges.
- The headline should NOT touch or nearly touch any edge of the asset.
- If the headline appears uncomfortably close to any edge, or there is barely any gap, margins are too narrow.
2. OVERALL CONTENT AREA:
- All main text content (headline, date, campaign branding) should sit within a clear "safe zone" inset from the edges.
- There should be visible, consistent breathing room on all four sides.
- Compare the top margin to the side margins — they should feel proportional and balanced.
3. BOTTOM AREA:
- The legal line and bottom elements naturally sit near the bottom, but there should still be a small gap between the lowest text and the bottom edge.
WHAT TO PRIORITISE (in order of importance):
- HEADLINE position: Is the headline text well inset from the top and sides? This is the PRIMARY margin check.
- DATE/SUBHEAD position: Are these text elements also within the safe zone?
- OVERALL FEEL: Does the layout feel well-spaced and comfortable, or does it feel cramped and tight against the edges?
- LEGAL LINE: The legal line is small text that often sits close to the bottom — this is acceptable by design. Do NOT heavily penalise legal line position.
MARGIN GUIDELINES BY FORMAT:
- Standard formats: Approximately 7% of the shortest side as margin on all sides.
- Wide banners: Slightly larger margins (approximately 10% of the shortest side).
- The box graphic is a decorative element and MAY extend beyond the margins or to the edge — this is acceptable.
LEFT ALIGNMENT CONSISTENCY CHECK:
Left-aligned text elements (headline, date, and logo/campaign branding like "amazon prime day") should share approximately the same left margin position.
IMPORTANT CONTEXT — LOGO LOCKUP PADDING:
The logo/campaign branding lockup (e.g. "amazon.ie prime day") is a composite graphic element that often includes built-in internal padding within its bounding box. This means the OCR-detected left edge of the logo text may appear further from the asset edge than raw headline text, even when the visual alignment is correct. A difference of up to ~4% between the headline and logo left positions is NORMAL and expected due to this internal padding. Only flag alignment as an issue if the difference exceeds ~5% of the asset width.
HOW TO CHECK THIS — follow these steps carefully:
If OCR measurements are provided, use the exact pixel/percentage values from the OCR data. If not, estimate visually:
1. Look at the logo/campaign branding text at the bottom. Note the gap between the LEFT EDGE of the logo text and the LEFT EDGE of the asset, as a percentage of the asset width.
2. Now look at the HEADLINE text at the top. Note the gap between the LEFT EDGE of the first letter of the headline and the LEFT EDGE of the asset, as a percentage of the asset width.
3. COMPARE these two percentage values using these thresholds:
- Difference 0-4%: ACCEPTABLE — this is within the expected range considering logo lockup internal padding. Do NOT penalise.
- Difference 4-6%: MODERATE ISSUE — the headline may be slightly oversized. Score 5-6 for this aspect.
- Difference >6%: SIGNIFICANT ISSUE — the headline is clearly oversized and eating into margins. Score 3-4 for this aspect.
4. Report both percentages in your response.
5. Similarly, check the date text — it should reasonably align with the headline (within ~2%).
SCORING GUIDANCE: Left-alignment consistency is ONE factor in the overall margins assessment, not the sole determinant. Even if alignment is slightly off, good overall margins (comfortable spacing, balanced composition) should keep the score at 5-6 minimum. Only score below 4 for margins if BOTH the alignment is significantly off (>6% difference) AND the actual margins are too tight (headline very close to edges).
SIGNS OF GOOD MARGINS:
- Clear visible gap between headline and all edges
- Text content feels "framed" within the layout with room to breathe
- Consistent spacing on left and right sides
- Top margin gives the headline space above it
- Left edge of headline aligns with left edge of logo/branding and date text below
SIGNS OF BAD MARGINS:
- Headline text very close to or touching the top, left, or right edge
- Content feels cramped or squeezed toward the edges
- Noticeably less space on one side compared to others (unbalanced)
- Main text content (not legal line) appearing within a few pixels of any edge
- Headline left edge is significantly closer to the left edge than the logo (>6% difference) — this suggests the headline may be oversized
STEPS TO EVALUATE:
1. Look at the headline text — is there clear space between it and the nearest edges?
2. Look at the overall composition — does the content sit comfortably within the frame?
3. Compare margins on different sides — are they roughly balanced?
4. Check if any main content (headline, date) is uncomfortably close to edges
5. CHECK LEFT ALIGNMENT: Compare the left edge positions of headline and logo. Remember that differences up to ~4% are normal due to logo lockup padding. Only flag as a margin issue if the difference exceeds ~5%.
6. Note: the box graphic and legal line are exceptions — they may sit closer to edges
DECISION CRITERIA:
- PASS (score 7-10): The headline and main content have clear, visible breathing room from all edges. Left-alignment difference between headline and logo is within ~4%. The layout feels well-spaced and comfortable.
- MODERATE ISSUES (score 5-6): Minor margin tightness on one side, or left-alignment difference of 4-6% between headline and logo. Overall layout still feels acceptable.
- FAIL (score 1-4): The headline or main content text is touching or nearly touching an edge, OR left-alignment difference exceeds ~6% AND margins are visibly cramped, OR the layout feels severely cramped with insufficient margins.
YOUR OUTPUT:
Format your response as JSON:
{
"margin_check": "Pass" or "Fail",
"format_type_detected": "standard" or "wide" or "tall/portrait",
"headline_margins": {
"top": "Comfortable" or "Tight" or "Too close to edge",
"left": "Comfortable" or "Tight" or "Too close to edge",
"right": "Comfortable" or "Tight" or "Too close to edge"
},
"left_alignment_consistency": {
"headline_left_gap_percent": "Estimated gap between headline left edge and asset left edge as % of asset width (e.g. '~7%')",
"logo_left_gap_percent": "Estimated gap between logo/branding left edge and asset left edge as % of asset width (e.g. '~7%')",
"date_left_gap_percent": "Estimated gap between date left edge and asset left edge as % of asset width (e.g. '~7%')",
"headline_aligns_with_logo": true or false,
"headline_aligns_with_date": true or false,
"alignment_notes": "Compare the estimated gap percentages. Are they approximately equal? If the headline gap is smaller, the headline is too large."
},
"content_area_assessment": "Well-spaced" or "Slightly tight" or "Cramped",
"elements_too_close_to_edge": ["List of main content elements (not legal line) that are too close to edges, empty array if none"],
"overall_balance": "Balanced" or "Unbalanced - describe which side",
"explanation": "Describe what you see — where is the headline relative to edges? Does the left edge of the headline align with the logo/branding? How much breathing room is there?",
"recommendations": ["List specific recommendations if applicable, else an empty array"]
}"""
super().__init__(__name__, prompt)
# Run the app if executed directly
if __name__ == "__main__":
app_instance = AmazonMarginsApp()
app_instance.run()