ai_qc/backend/visual_qc_apps/text_readability_general/app.py
nickviljoen 9f9777240a Add OCR layout measurement module for precise spatial QC checks
Adds Tesseract-based OCR pre-processing that computes pixel-level text
positions, margins, spacing, and alignment before LLM analysis. This
enables detection of subtle layout differences that vision models miss
(e.g. 2.8% vs 6.4% headline margin, 83px vs 39px date gap).

OCR measurements injected into 10 checks across all client profiles:
- Amazon: margins, typography, headline_layout
- Static General: element_alignment, safety_area, visual_hierarchy_general,
  text_readability_general, text_edge_clearance
- L'Oreal: text_readability
- Diageo/Unilever KV: visual_hierarchy

Non-blocking: if Tesseract is unavailable, checks run with visual
estimation only. Production requires: sudo apt install tesseract-ocr

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

94 lines
4.8 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 TextReadabilityGeneralApp(FlaskAppTemplate):
"""
Text Readability General Check - For Digital Assets
"""
def __init__(self):
# Define the hardcoded prompt
prompt = """You are performing a visual quality control check on a digital marketing asset. Your task is to determine whether the MARKETING TEXT (headlines, slogans, calls-to-action) is readable, clear, and properly displayed for digital viewing.
CRITICAL: Evaluate only the MARKETING/ADVERTISING TEXT added to the creative (headlines, slogans, CTAs, promotional text). DO NOT evaluate text that is part of product packaging, labels, or bottles shown in the image. Product packaging text is not within the scope of this check.
MEASUREMENT DATA:
If OCR LAYOUT MEASUREMENTS are provided at the end of this prompt, use the computed text positions, character heights, and spacing values to supplement your visual assessment. Character height in pixels indicates actual text size. Margin percentages show how close text is to edges. Spacing values between elements show whether text has adequate breathing room.
STEPS TO EVALUATE:
1. Identify marketing text elements:
a. Headlines and main messages
b. Slogans and taglines
c. Calls to action (CTAs)
d. Promotional or descriptive text added to the creative
e. EXCLUDE: Text on product packaging, bottles, labels, or boxes (these are part of the product photography)
2. Examine marketing text clarity and presentation:
a. Text size - Is it large enough to be comfortably read on digital screens?
b. Font choice - Is the font clear, modern, and easily readable (not overly decorative)?
c. Contrast - Does the text stand out clearly against its background?
d. Spacing - Is there sufficient spacing between letters, words, and lines?
3. Check for overlapping and obstruction issues (CRITICAL):
a. Text overlapping with images, making it hard to read
b. Text overlapping with product photos where it blends into busy backgrounds
c. Text overlapping with other text elements
d. Elements obscuring or partially covering marketing text
e. Text extending beyond visible boundaries
f. Text placed over complex/busy backgrounds that reduce readability
4. Assess potential readability problems:
a. Decorative fonts that sacrifice legibility for style
b. Poor contrast that makes text blend into the background
c. Text that is too small or too condensed
d. Awkward text placement that interferes with other elements
e. Text color that doesn't provide sufficient contrast with its background
f. Text placed over images without proper background treatment (shadows, overlays, etc.)
5. Evaluate overall text hierarchy and layout:
a. Headlines should be clearly distinguishable from body text
b. Important text should be prioritized visually
c. All marketing text should be fully visible and unobstructed
d. Text should not compete with product images for attention
PASS/FAIL CRITERIA:
"Pass" if ALL marketing text elements are clear, readable, properly spaced, free from overlapping issues, and not competing with background elements.
"Fail" if ANY marketing text is difficult to read, overlapping with images/backgrounds in a way that reduces legibility, obscured, poorly contrasted, cut off, or placed awkwardly over complex backgrounds.
YOUR OUTPUT MUST INCLUDE:
• Detailed explanation of which marketing text elements were evaluated
• Specific issues found (overlapping, contrast problems, size issues, etc.)
• Clear distinction between marketing text issues and product packaging (which should be ignored)
{
"text_readability": "Pass" or "Fail",
"readability_score": "High", "Medium", or "Low",
"analysis_details": "Detailed explanation of which marketing text elements were checked and what issues were found",
"issues_found": [
"List specific problems: e.g., 'Headline overlaps product image', 'CTA text too small', 'Slogan has poor contrast'"
],
"recommendations": [
"Specific recommendation 1",
"Specific recommendation 2"
]
}
CRITICAL:
1. Always provide detailed analysis_details explaining what was checked
2. Focus ONLY on marketing/advertising text, NOT product packaging text
3. Specifically call out overlapping issues if text is placed over images or backgrounds
4. If there is NO marketing text in the asset, state "No marketing text found - N/A"
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 = TextReadabilityGeneralApp()
app.run(debug=True)