Commit graph

35 commits

Author SHA1 Message Date
nickviljoen
564ee96ac7 Fix selectedClient persistence bug on page refresh
Issue: When refreshing the page after selecting a client, saved files
would not display because init() was called without await, causing a
race condition where loadSavedFiles() could execute before selectedClient
was properly set.

Fix: Added await to init() call in DOMContentLoaded handler (line 3280)
to ensure init() completes before continuing. This guarantees that
loadSavedFiles() is called after selectedClient is properly set.

Also added debug logging to trace selectedClient value through the
initialization process for easier troubleshooting.

Testing: After this fix, refreshing the page should properly restore
the selected client and display their saved files.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 12:15:32 +02:00
nickviljoen
08a9901d70 Create L'Oréal Static profile and update client configurations
Created new L'Oréal Static profile (loreal_static.json):
- Focused 3-check profile for L'Oréal digital static assets
- Checks: language_consistency, text_readability_general, background_contrast_general
- Weighting: 3.34, 3.33, 3.33 (total 10.0 for 100-point scale)
- All checks use Gemini LLM

Updated client_config.py:
- L'Oréal: Added 'loreal_static' profile, kept 'static_general', removed 'general_check'
- Diageo: Added 'static_general', removed 'general_check'
- Unilever: Added 'static_general', removed 'general_check'
- General: Added 'static_general', removed 'general_check'

Result:
- Static General (10 checks) now available to ALL clients
- L'Oréal Static (3 checks) exclusive to L'Oréal
- General Check profile removed from all clients (deprecated)

Profile distribution by client:
- Diageo: diageo_key_visual, diageo_packaging, static_general
- Unilever: unilever_key_visual, unilever_packaging, static_general
- L'Oréal: loreal_static, static_general
- General: static_general, inclusive_accessibility

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 11:59:47 +02:00
nickviljoen
70c2563521 Create digital-focused general check modules and update Static General profile
Created 4 new "_general" QC check modules optimized for digital static assets:
- visual_hierarchy_general: Digital hierarchy assessment (removed POS/physical viewing distances)
- product_visibility_general: Digital product presentation (removed POS terminology)
- logo_visibility_general: Digital logo prominence (removed 3m/1m viewing distance requirements)
- call_to_action_general: Digital CTA effectiveness (added clickability and mobile considerations)

Updated Static General profile (static_general.json):
- Now includes 10 AI vision-focused checks
- Even weighting: 1.0 per check for 100-point scale
- Total weight: 10.0 for proper scoring calculation
- All checks assigned to Gemini LLM
- Updated description to clarify focus on AI vision capabilities

Profile focuses exclusively on checks that only AI vision models can perform,
excluding physical file properties that Twist system handles (file size, format,
resolution, naming, aspect ratio, bleed, crop marks, etc.).

10 checks in Static General profile:
1. text_readability_general
2. background_contrast_general
3. language_consistency
4. visual_hierarchy_general (NEW)
5. element_alignment
6. product_visibility_general (NEW)
7. logo_visibility_general (NEW)
8. call_to_action_general (NEW)
9. accessibility
10. inclusive

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 11:55:23 +02:00
nickviljoen
b1f3275a97 Fix client filtering bug in saved files refresh
The refreshSavedFilesAfterAnalysis() function was correctly filtering
the initial fetch by client, but the three retry attempts in the loop
were missing the client filter parameter. This caused the first API
call to correctly return only the selected client's files, but the
subsequent three calls to return all files.

Fixed by adding client filter to all refresh attempts in the loop.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 11:37:52 +02:00
nickviljoen
2d27356478 Add debug logging for client filtering
- Log client_filter parameter received by backend
- Log selectedClient value in frontend
- Log number of files returned
- Help diagnose why all files are showing for all clients

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 11:27:34 +02:00
nickviljoen
477780df09 Add client-specific output folders and 14-day auto-cleanup
## New Features

### Client-Specific Output Folders
- Files now saved in client-specific subdirectories (loreal/, diageo/, unilever/, general/)
- Automatic client detection from profile ID
- Better organization for multi-client environment
- Each client only sees their own QC reports

### Automatic File Cleanup
- Auto-delete reports older than 14 days on every file listing request
- Keeps output folder clean and manageable
- Configurable cleanup age (default: 14 days)

### File Filtering by Client
- API endpoint `/api/output_files` now accepts `?client=<client_id>` parameter
- Frontend automatically filters files by selected client
- No more cluttered file lists for clients

### Migration Script
- `migrate_output_files.py` - Move existing files to client folders
- Dry-run mode by default (use --execute to run)
- Deletes files older than 14 days during migration
- Supports both development (--dev) and production (--production)

## API Changes

### Modified Endpoints
- `GET /api/output_files?client=<client_id>` - List files filtered by client
- `GET /output/<client>/<filename>` - Serve files from client folders
- `GET /output/<filename>` - Legacy route for backward compatibility

### New Functions
- `get_client_from_profile(profile_id)` - Detect client from profile
- `ensure_client_output_folder(client)` - Create client folders
- `cleanup_old_files(max_age_days)` - Delete old files

## File Structure
```
output-dev/
├── loreal/
│   └── 20260202_102514_Missing_text_report.html
├── diageo/
│   └── 20260202_103423_Product_shot_report.html
├── unilever/
│   └── 20260202_104512_Key_visual_report.html
└── general/
    └── 20260202_105634_Other_report.html
```

## Frontend Changes
- `loadSavedFiles()` now includes client parameter in API calls
- Automatically filters saved files by selected client
- Clean UI showing only relevant reports

## Usage

### Migration (Development)
```bash
# Dry-run (no changes)
python3 migrate_output_files.py

# Execute migration
python3 migrate_output_files.py --execute
```

### Migration (Production)
```bash
# Dry-run for production folder
python3 migrate_output_files.py --production

# Execute migration
python3 migrate_output_files.py --production --execute
```

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 11:18:05 +02:00
nickviljoen
ba8b6dfa57 Fix authentication redirect to show client selection screen
After successful Microsoft authentication, force a full page reload to fetch
fresh HTML from the server instead of trying to reinitialize the cached page.
This ensures users see the client selection screen immediately after login
instead of the old cached interface.

Changes:
- Replace init() call with window.location.reload(true) after successful login
- Bypasses browser cache to fetch fresh HTML
- Fixes issue where users had to manually reload to see new interface

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 11:04:59 +02:00
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
nickviljoen
c68470c78f Fix BASE_PATH detection to handle URLs without trailing slash
The getBasePath() function was only detecting /ai_qc/ (with trailing slash) but failing when users accessed /ai_qc (without trailing slash). This caused auth endpoints to be called at wrong URLs (/auth/status instead of /ai_qc/auth/status), resulting in 404 errors and JSON parsing failures.

Fix: Updated function to handle both /ai_qc and /ai_qc/ cases consistently.
2026-01-19 22:26:10 +02:00
nickviljoen
d34b7d115c diagnostic test 2026-01-19 22:17:18 +02:00
nickviljoen
18670b23f6 Improvements to Prod vs Dev testing 2025-12-06 15:39:13 +02:00
nickviljoen
ef1abdcfc5 Sync profile weighting and weight_scale support to backend api_server.py
- Added weight_scale support for profiles (default 100)
- Enhanced /api/profiles endpoint to return detailed profile data
- Includes check weights, LLM assignments, and enabled status
- Matches functionality from root api_server.py for production deployment
2025-12-06 15:16:41 +02:00
nickviljoen
70237126f1 Apply tool descriptions update to backend api_server.py for production 2025-12-06 15:05:46 +02:00
nickviljoen
f0fd14cdc2 Updated tool discriptions 2025-12-06 14:54:36 +02:00
nickviljoen
adf24a4603 Updated UI for creating profiles and profile discriptions 2025-12-06 14:32:47 +02:00
nickviljoen
199b9c72bf UI Update to be more BTG look and feel 2025-11-15 10:52:52 +02:00
nickviljoen
e46c1d1435 Add comprehensive production deployment documentation
Added detailed troubleshooting guide covering critical production issues
encountered during deployment:

1. Web UI 404 Error Fix
   - Document absolute path requirement for serve_web_ui()
   - Explain why relative paths fail in production environments
   - Provide code examples for both root and backend api_server.py

2. Apache ProxyPass Configuration
   - Document static directory conflict with ProxyPass rules
   - Explain Apache's file-first, proxy-second behavior
   - Provide solution: remove conflicting static directories
   - Include proper ProxyPass ordering (specific paths before general)

3. MSAL Authentication Error Fix
   - Document interaction_in_progress error and root causes
   - Explain concurrent sign-in prevention implementation
   - Include storage cleanup and proper flag reset patterns

4. Production Deployment Checklist
   - Step-by-step deployment verification process
   - Backend testing commands
   - Apache proxy testing commands
   - Browser testing best practices

5. Common Production Issues Table
   - Quick reference for troubleshooting
   - Check commands for each issue
   - Solutions for common problems

This documentation ensures future deployments avoid the same pitfalls
and provides clear guidance for troubleshooting production issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 23:23:02 +02:00
nickviljoen
0a62034685 Fix MSAL interaction_in_progress error
Added protection against concurrent sign-in attempts by:
- Adding isSigningIn flag to prevent double-clicks
- Clearing MSAL localStorage/sessionStorage before authentication
- Properly resetting flag in finally block

This resolves the "interaction_in_progress" error that was preventing
users from signing in with Microsoft authentication.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 22:57:49 +02:00
nickviljoen
e136f1f905 Fix backend web UI 404 error with absolute path
Applied the same web_ui.html path fix to backend/api_server.py that
was previously applied to the root api_server.py. The backend version
needs to reference the parent directory since web_ui.html is located
at /opt/ai_qc/web_ui.html while api_server.py is in /opt/ai_qc/backend/.

This fixes the 404 error when running via Waitress production server.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 22:07:23 +02:00
nickviljoen
28885f897f Fix web UI 404 error by using absolute file path
Changed web_ui.html loading in serve_web_ui() to use absolute path
instead of relative path. This resolves 404 errors when Flask is
started from directories other than the project root, which commonly
occurs in production web server deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 21:14:06 +02:00
nickviljoen
cafb37ce94 Add reorganization completion summary document 2025-11-06 11:57:31 +02:00
nickviljoen
3fec052c12 Create frontend and backend folder structure for deployment
Organized the application into separate frontend and backend directories for cleaner deployment and better separation of concerns.

Frontend Directory (frontend/):
- index.html: Single-page web interface (renamed from web_ui.html)
- README.md: Frontend deployment guide
- Total size: ~113 KB (self-contained)
- Smart base path detection (works at / or /ai_qc/)
- No configuration changes required

Backend Directory (backend/):
- All Python files (api_server.py, llm_config.py, etc.)
- visual_qc_apps/: 33 QC check modules
- profiles/: 6 QC profile configurations
- brand_guidelines/: Reference asset storage
- config/: Environment configurations
- scripts/: Deployment automation
- uploads/, output/: Data directories
- requirements.txt, ai_qc.service, apache_config.conf
- Complete documentation

New Documentation:
- FOLDER_STRUCTURE.md: Comprehensive guide to new structure
- frontend/README.md: Frontend deployment instructions
- backend/BACKEND_README.md: Backend deployment guide

Deployment Mapping:
- frontend/ → /var/www/html/ai_qc/ (web root)
- backend/ → /opt/ai_qc/ (application directory)

Benefits:
- Clear separation of concerns
- Backend code not in web-accessible directory
- Independent frontend/backend updates
- Matches server's existing patterns (/opt/veo3, /opt/voice2text)
- Industry-standard architecture
- Easy to deploy and maintain

Original files preserved in root directory for reference.
Ready for production deployment following MIGRATION_GUIDE.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 11:55:53 +02:00
nickviljoen
b7b7f57b35 Add production deployment migration guide and configuration files
Added comprehensive migration documentation and configuration files for restructuring the application to split frontend/backend:

New Documentation:
- MIGRATION_GUIDE.md: Complete step-by-step migration instructions
- MIGRATION_SUMMARY.md: Quick reference guide for deployment
- MIGRATION_CHECKLIST.md: Printable checklist for migration day
- DEPLOYMENT_RESTRUCTURE.md: Architecture overview and benefits

New Configuration Files:
- run_api_server.py: Production WSGI server wrapper using Waitress
- ai_qc.service: Systemd service configuration for backend
- apache_config.conf: Apache virtual host configuration template

Updated Files:
- requirements.txt: Added waitress>=2.1.2 for production WSGI server
- README.md: Added deployment documentation section

Migration Overview:
- Split current monolithic structure into separate frontend/backend
- Move backend to /opt/ai_qc/ (following server standards)
- Keep frontend in /var/www/html/ai_qc/ (single index.html)
- Use Apache reverse proxy to connect frontend to backend API
- Implement systemd service for reliable backend process management

Benefits:
- Improved security (backend code not in web root)
- Better separation of concerns
- Follows industry best practices
- Matches existing server app patterns (/opt/veo3, /opt/voice2text)
- Easier independent updates of frontend/backend

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 11:45:31 +02:00
nickviljoen
824c7639ec updates 2025-11-06 09:40:34 +02:00
nickviljoen
3c97267d68 Updated README File 2025-09-12 16:45:31 +02:00
nickviljoen
27a8278bd2 Have created Dev and Prod enviroments to test locally 2025-09-11 21:58:44 +02:00
michael
2598f162e4 changed MSAL URL and added base path to various API endpoint URLs in the HTML and api_server.py 2025-08-28 09:38:52 -05:00
nickviljoen
355be50b23 Bug fixes, profile updates, report updates 2025-08-23 14:44:17 +02:00
nickviljoen
56ecf9218c Added local host URl for Auth testing 2025-08-22 16:41:48 +02:00
nickviljoen
e5d36cac82 Updated SSO error, Updated Unilever Profile scoring weighting, updated output file list order 2025-08-21 17:27:11 +02:00
nickviljoen
5243ad4ae3 SSO Added 2025-08-20 15:30:29 +02:00
michael
ea7bcf5747 modified claude.md to test python and excluded venv from .gitignore 2025-08-14 08:45:29 -05:00
michael
c5dd454fe8 Merge remote-tracking branch 'origin/main'
merging for initial commit/push to existing bitbucket repo
2025-08-12 14:56:28 -05:00
michael
c3b0c37ed4 initial commit 2025-08-12 14:52:49 -05:00
Santhosha Nayak
aecb493518 Initial commit 2025-08-12 06:00:25 +00:00