ai_qc/backend/visual_qc_apps/background_contrast_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

74 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 BackgroundContrastGeneralApp(FlaskAppTemplate):
"""
Background Contrast General Check - For Digital Assets
"""
def __init__(self):
# Define the hardcoded prompt
prompt = """You are conducting a visual quality control check on a digital marketing asset to verify that crucial design elements—including product images, the brand logo, and MARKETING TEXT (not text on product packaging)—stand out clearly from the background.
IMPORTANT: Focus on the MARKETING/ADVERTISING elements (headlines, slogans, calls-to-action), NOT the text printed on product packaging or labels.
EVALUATION STEPS:
1. Identify primary visual elements:
a. Brand logo (extra scrutiny for brand consistency and visibility).
b. Product shots or key imagery (overall product visibility, not text on packaging).
c. Main marketing text, headlines, slogans, and calls to action (NOT text on product packaging).
2. Check clarity and visibility:
a. Ensure each element is immediately recognizable and legible.
b. Verify that no elements are blending into or getting lost in the background.
c. Check for text overlapping with backgrounds or images that reduce visibility.
3. Evaluate color and brightness contrast:
a. Visually verify that each key element "pops" against the background.
b. Pay special attention to the brand logo. Any condition that makes the logo less than immediately recognizable is grounds for failing.
c. If any key element (product, marketing text, logo) is difficult to distinguish from the background, consider contrast insufficient.
4. Check for color conflicts:
a. Ensure marketing text doesn't blend with similar-colored backgrounds.
b. Verify that products are clearly visible against their background.
c. Confirm the logo maintains its visibility across the entire design.
d. Identify any text that overlaps with background elements, making it hard to read.
5. Assess overall visual hierarchy:
a. Important elements should stand out clearly.
b. Background should support, not compete with, key content.
PASS/FAIL CRITERIA:
"Pass" only if ALL key marketing elements (logo, product, marketing text) are sharp, legible, and clearly distinct from the background.
"Fail" if any single critical element has low contrast, appears to blend in, overlaps poorly with background, or is difficult to see against its background.
YOUR OUTPUT MUST INCLUDE:
• Detailed explanation of what you observed (which elements pass/fail and why)
• If it fails, specific recommendations for improvement
• Format your response as a JSON code block with the structure:
{
"background_contrast": "Pass" or "Fail",
"analysis_details": "Detailed explanation of what was checked and findings for logo, product, and marketing text",
"elements_checked": {
"logo": "Pass/Fail - Brief explanation",
"product": "Pass/Fail - Brief explanation",
"marketing_text": "Pass/Fail - Brief explanation"
},
"recommended_adjustments": "None (if Pass) OR specific recommendations to improve contrast (if Fail)"
}
CRITICAL: Always provide detailed analysis_details and element-by-element breakdown. Never return just "Pass" or "Fail" without explanation."""
# Initialize the Flask app with the prompt
super().__init__(__name__, prompt)
# Run the app if executed directly
if __name__ == "__main__":
app = BackgroundContrastGeneralApp()
app.run(debug=True)