ai_qc/backend/visual_qc_apps/safety_area/app.py
nickviljoen 9eed569587 Tone down OCR from authoritative to supplementary to reduce false positives
OCR measurements were causing the LLM to over-rely on bounding box numbers
and fail correct assets on minor measurement inaccuracies. Changes:
- All prompts now say "supplementary data" not "authoritative/primary source"
- LLM instructed to prioritise visual assessment, use OCR to confirm/question
- Alignment tolerance widened from 1.5% to 3% of width
- OCR context footer softened with accuracy caveat (~5-10px margin of error)

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

56 lines
No EOL
2.5 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 SafetyAreaApp(FlaskAppTemplate):
"""
Safety Area Check
"""
def __init__(self):
# Define the hardcoded prompt
prompt = """You are performing a visual quality-control check on an advertisement to verify that all important elements are within the safety area. Your task is to determine whether all copy, mandatory elements, and brand assets are positioned correctly within safe margins.
MEASUREMENT DATA:
If OCR LAYOUT MEASUREMENTS are provided at the end of this prompt, use them as supplementary data for safety area assessment. OCR bounding boxes can have small inaccuracies, so use them to confirm or question what you see visually, but prioritise the overall visual impression.
CRITERIA FOR SAFETY AREA:
1. All important content must be kept a safe distance from the edges of the design (typically 10% inward from each edge)
2. Critical elements that must be within the safety area include:
- All text/copy
- Brand logos
- Key visuals
- Mandatory information (legal text, disclaimers)
- Call-to-action elements
STEPS TO EVALUATE:
1. Look for any visible safety guides, margins, or trim marks in the design
2. If safety guides are visible, check if all critical elements are positioned within these guides
3. If no safety guides are visible, consider a standard safety margin of approximately 10% inward from each edge
4. Check if any elements appear too close to the edges of the design
5. Pay special attention to text, logos, and legally required elements
YOUR OUTPUT:
• State whether safety guides/margins were visible in the design
• State whether all critical elements are positioned within safe margins
• If any elements are outside or too close to the safety area, list them specifically
• Include a JSON code block with these fields:
{
"safety_guides_visible": true or false,
"all_elements_within_safety_area": true or false,
"safety_area_check": "Pass" or "Fail",
"elements_outside_safety_area": ["List specific elements outside safety area, if any, else an empty array"],
"recommendations": ["List specific recommendations if applicable, else an empty array"]
}"""
# Initialize the Flask app with the prompt
super().__init__(__name__, prompt)
# Run the app if executed directly
if __name__ == "__main__":
app = SafetyAreaApp()
app.run(debug=True)