ai_qc/backend/visual_qc_apps/text_readability_general/app.py
nickviljoen 16741a96d6 Add L'Oréal Static General profile with multi-file queue and enhanced reporting
## New Features

### L'Oréal Static General Profile
- Created new profile with 3 checks optimized for digital marketing assets
- Even weighting (33.3% each) for 100-point scoring scale
- Removed print-specific requirements (3m viewing distance)
- Focus on marketing text vs product packaging distinction

### Multi-File Queue System (web_ui.html)
- Added file queue functionality for batch processing
- Users can now upload and process multiple files simultaneously
- Queue displays file status (pending, analyzing, complete, error)
- Individual file removal and queue clearing options
- Progress tracking for batch operations

### New General QC Checks
1. background_contrast_general
   - Optimized for digital assets (no distance requirements)
   - Checks logo, product, and marketing text contrast
   - Detects overlapping and blending issues
   - Provides element-by-element breakdown

2. text_readability_general
   - Focus on marketing text only (excludes product packaging)
   - Checks for overlapping elements
   - Digital readability optimization
   - Specific issue identification

3. language_consistency (enhanced)
   - Better distinction between marketing and packaging text
   - Detailed language detection and reporting
   - Lists specific text analyzed

### Usage Tracking System
- Added usage_tracker.py for analysis logging
- Tracks user activity, profile usage, and costs
- Daily log files in JSONL format
- Cost estimation per LLM provider

## Bug Fixes

### Authentication & User Management
- Fixed Flask 'g' import missing issue
- Fixed user info access in background threads
- Pass user_info to threads instead of accessing g.user
- Improved error handling for usage logging

### HTML Report Generation
- Fixed missing analysis details in reports
- Now extracts and displays all JSON fields properly
- Shows comprehensive breakdowns:
  - Analysis details
  - Elements checked (logo, product, text)
  - Marketing text found
  - Issues identified
  - Specific recommendations
- No more blank "Pass/Fail" results

### Scoring System
- Fixed usage_tracker to handle dict of check results (not list)
- Better handling of model_used field variations
- Skip non-dict check results gracefully

## Configuration Changes

### Model Versions (llm_config.py)
- Fixed invalid GPT-4.1 model ID to gpt-4o
- Added Gemini 3 Pro beta model option
- AVAILABLE_MODELS dict for UI selection
- Model version override support

### Profile Updates
- Static General: 3 checks, total weight 10.0
- Each check: text_readability_general (3.33), background_contrast_general (3.33), language_consistency (3.34)
- Maximum score: 100 points

## Technical Improvements

- Enhanced prompt engineering for consistent LLM outputs
- Mandatory detailed explanations in all checks
- Structured JSON responses with comprehensive fields
- Better error messages and fallback handling
- Client configuration support (client_config.py)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 10:58:39 +02:00

91 lines
4.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 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.
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)