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>
88 lines
3.6 KiB
Python
88 lines
3.6 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 TextEdgeClearanceApp(FlaskAppTemplate):
|
||
"""
|
||
Text Edge Clearance Check - Ensures text has sufficient margin from image edges
|
||
"""
|
||
|
||
def __init__(self):
|
||
# Define the hardcoded prompt
|
||
prompt = """You are performing a visual quality control check on a marketing material or advertisement. Your task is to verify that all text elements have sufficient clearance from the edges of the image to prevent cutoff or poor readability.
|
||
|
||
MEASUREMENT DATA:
|
||
If OCR LAYOUT MEASUREMENTS are provided at the end of this prompt, use them as supplementary data for edge clearance 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.
|
||
|
||
EVALUATION STEPS:
|
||
|
||
1. Identify all text elements in the image:
|
||
a. Headlines and titles
|
||
b. Body copy and descriptions
|
||
c. Call-to-action text
|
||
d. Product labels and captions
|
||
e. Brand taglines
|
||
f. Any other readable text
|
||
|
||
2. Measure the clearance from each edge:
|
||
a. Check distance from TOP edge
|
||
b. Check distance from BOTTOM edge
|
||
c. Check distance from LEFT edge
|
||
d. Check distance from RIGHT edge
|
||
|
||
3. Apply clearance requirements:
|
||
MINIMUM SAFE ZONE: Text should have at least 5% margin from any edge
|
||
RECOMMENDED SAFE ZONE: Text should have at least 8-10% margin from any edge
|
||
|
||
Calculate percentage as: (distance from edge / image dimension) × 100
|
||
|
||
Example: If text is 20 pixels from the left edge and image width is 1000 pixels:
|
||
Clearance = (20 / 1000) × 100 = 2% (FAIL - too close to edge)
|
||
|
||
4. Check for text cutoff:
|
||
a. Identify any text that is partially cut off by the image boundary
|
||
b. Check for letters or words that appear incomplete at edges
|
||
c. Verify that text doesn't extend beyond the visible canvas
|
||
|
||
5. Special considerations:
|
||
a. Small disclaimer text may have reduced clearance requirements (3% minimum)
|
||
b. Text intentionally placed at edges for design effect should still be fully visible
|
||
c. Rotated or angled text should maintain clearance from nearest edge
|
||
|
||
DECISION CRITERIA:
|
||
• Pass: All text has ≥5% clearance from all edges, no text cutoff
|
||
• Fail: Any text has <5% clearance from any edge, or any text is cut off
|
||
• Provide specific details about which edges are violated and by which text elements
|
||
|
||
YOUR OUTPUT:
|
||
• State whether the design "passes" or "fails" the text edge clearance check
|
||
• List any edges with insufficient clearance
|
||
• Identify any text that is cut off or too close to edges
|
||
• Provide recommendations for repositioning text if failed
|
||
|
||
Format your response as JSON:
|
||
{
|
||
"text_edge_clearance": "Pass" or "Fail",
|
||
"edges_violated": ["top", "bottom", "left", "right"] (only violated edges),
|
||
"text_cutoff_detected": true or false,
|
||
"problem_text_elements": ["Description of text element and location", ...] (only if "Fail"),
|
||
"clearance_percentages": {
|
||
"top": "percentage or 'sufficient'",
|
||
"bottom": "percentage or 'sufficient'",
|
||
"left": "percentage or 'sufficient'",
|
||
"right": "percentage or 'sufficient'"
|
||
},
|
||
"recommendation": "Brief recommendation for text repositioning" (only if "Fail")
|
||
}"""
|
||
|
||
# Initialize the Flask app with the prompt
|
||
super().__init__(__name__, prompt)
|
||
|
||
# Run the app if executed directly
|
||
if __name__ == "__main__":
|
||
app_instance = TextEdgeClearanceApp()
|
||
app_instance.run()
|