No description
Find a file
nickviljoen 1dff8fece5 Fix auth flow: switch from popup to redirect-based MSAL login
The popup login flow was broken because the Flask 302 redirect from
/ to /reporting/index caused MSAL in the popup to consume the auth
code hash before the parent window could detect it, leaving the
parent stuck on "Authenticating..." while the popup rendered the
full app.

- Switch signIn() from loginPopup() to loginRedirect()
- Add handleRedirectPromise() at start of initAuth() to process
  the auth code on page load after returning from Microsoft
- Change root route from 302 redirect to direct template render
  so the #code=... hash fragment is preserved for MSAL
- Switch signOut() from logoutPopup() to clearCache()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 12:22:33 +02:00
core Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
database Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
modules Consolidate legacy hm_qc and video_qc tools into main project 2026-02-25 11:40:53 +02:00
static Fix auth flow: switch from popup to redirect-based MSAL login 2026-02-25 12:22:33 +02:00
templates Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
.env.example Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
.gitignore Consolidate legacy hm_qc and video_qc tools into main project 2026-02-25 11:40:53 +02:00
app.py Fix auth flow: switch from popup to redirect-based MSAL login 2026-02-25 12:22:33 +02:00
auth_middleware.py Initial Commit 2025-12-30 16:47:56 +02:00
box_client.py Initial Commit 2025-12-30 16:47:56 +02:00
CHANGELOG.md Initial Commit 2025-12-30 16:47:56 +02:00
config.py Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
DEPLOYMENT_CHECKLIST.md Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
DOCUMENTATION_SUMMARY.txt Initial Commit 2025-12-30 16:47:56 +02:00
gunicorn_config.py Initial Commit 2025-12-30 16:47:56 +02:00
INTEGRATION_TEST_REPORT.md Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
jwt_validator.py Initial Commit 2025-12-30 16:47:56 +02:00
MIGRATION_GUIDE.md Initial Commit 2025-12-30 16:47:56 +02:00
README.md Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
report_parser.py Initial Commit 2025-12-30 16:47:56 +02:00
requirements.txt Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
run.sh Reporting updated. 2026-01-14 09:14:00 +02:00
run_prod.sh Initial Commit 2025-12-30 16:47:56 +02:00
setup.sh Initial Commit 2025-12-30 16:47:56 +02:00
test_integration.py Add modular architecture, core framework, and web UI 2026-02-25 11:39:04 +02:00
test_local.sh Initial Commit 2025-12-30 16:47:56 +02:00
wsgi.py Initial Commit 2025-12-30 16:47:56 +02:00

Unified HM QC Platform

Version: 1.0.0 Status: Production Ready

A comprehensive quality control platform merging multiple QC tools into a single unified web application with intelligent AI-powered validation, sophisticated scoring, and consolidated reporting.


Overview

The Unified HM QC Platform integrates four distinct quality control tools into a single, cohesive web application:

  1. HM QC - PDF/Image quality control with AI-powered validation
  2. Video QC (BETA) - Video quality control with technical specification checks
  3. Video Master Adot Detection (BETA) - Intelligent 4-tier video matching system
  4. Reporting - Consolidated reports from Box.com and internal QC modules

Key Features

  • 🎯 Unified Interface - Single platform with tabbed navigation
  • 🔒 Secure Authentication - Azure AD with JWT validation
  • 🤖 AI-Powered - GPT-4o and Claude integration for intelligent validation
  • 📊 Advanced Scoring - 0-100 confidence scoring with detailed breakdowns
  • 🎨 H&M Branding - Consistent black (#000000) and yellow (#FFDD00) theme
  • 🔄 Real-time Progress - SSE and polling support for long-running operations
  • 📦 Modular Architecture - Flask blueprints for clean separation of concerns

Quick Start

Prerequisites

  • Python 3.9+
  • ffmpeg (for video processing)
  • chromaprint (optional, for audio fingerprinting)

Installation

# 1. Navigate to project directory
cd /Users/nickviljoen/Desktop/HM_QC_Bitbucket/hm_ai_qc_report_tool

# 2. Create virtual environment
python3 -m venv venv
source venv/bin/activate

# 3. Install dependencies
pip install --upgrade pip
pip install -r requirements.txt

# 4. Create .env file (see Configuration section)
cp .env.example .env
# Edit .env with your credentials

# 5. Initialize database
python3 -c "from app import create_app; from core.models.database import db; app = create_app(); app.app_context().push(); db.create_all()"

# 6. Run application
python3 app.py

Access the platform at: http://localhost:7183


Architecture

Tech Stack

Backend:

  • Flask 3.0 (Python web framework)
  • SQLAlchemy (ORM with SQLite database)
  • OpenAI / Anthropic (LLM providers)
  • Box SDK (Cloud storage integration)

Frontend:

  • Bootstrap 5 (Responsive UI)
  • Vanilla JavaScript (Tab management, progress tracking)
  • Server-Sent Events (Real-time updates)

Video Processing:

  • ffmpeg-python (Video manipulation)
  • OpenCV (AKAZE feature matching)
  • Chromaprint (Audio fingerprinting)

Directory Structure

hm_ai_qc_report_tool/
├── app.py                    # Application factory
├── config.py                 # Configuration
├── requirements.txt          # Dependencies
│
├── core/                     # Shared infrastructure
│   ├── auth/                 # Authentication
│   ├── models/               # Database models
│   ├── services/             # LLM, Box.com
│   └── utils/                # Progress, parsing
│
├── modules/                  # Feature modules
│   ├── hm_qc/               # HM QC
│   ├── video_qc/            # Video QC (BETA)
│   ├── video_master/        # Video Master (BETA)
│   └── reporting/           # Reporting
│
├── templates/               # Shared templates
├── static/                  # CSS, JavaScript
├── database/                # SQLite database
├── data/                    # Video Master data
└── storage/                 # Report storage

Modules

1. HM QC Module

Status: Complete (Demo with 2 sample checks)

Automated quality control for PDF and image marketing materials.

Features:

  • Drag-and-drop file upload
  • Profile-based configuration
  • Weighted check execution
  • 0-100 scoring (Pass: 90+, Warning: 70-89, Fail: <70)
  • Real-time progress tracking
  • HTML report generation

Workflow:

  1. Upload PDF/image → 2. Select profile → 3. Execute QC → 4. View results with score → 5. Download report

2. Video QC Module (BETA) 🔶

Status: Basic Structure

Video quality control with technical validation.

Planned Features:

  • Filename convention validation
  • Technical specs (codec, resolution, FPS, bitrate)
  • Audio quality validation
  • AI-powered censorship detection
  • Duration validation

3. Video Master Module (BETA)

Status: Complete (Full 4-tier engine)

Intelligent video matching using cascading 4-tier approach.

Matching System:

  • Stage 0: Metadata filtering (80-95% reduction, <1s)
  • Tier 1: Perceptual hash (5-10s for 50 masters)
  • Tier 2: AKAZE verification (5-10s per candidate)
  • Tier 3: AI Vision fallback (smart triggering, ~$0.006/comparison)

Performance:

  • Smart AI Vision triggering: ~97% cost reduction
  • Typical batch: $0.30 instead of $15

Features:

  • 0-100 confidence scoring
  • Match quality analysis
  • Cost tracking
  • Master library management

4. Reporting Module

Status: Complete

Consolidated reporting from Box.com and internal QC.

Features:

  • Job number search
  • Dual-source aggregation (Box + Database)
  • Source badges ("HM QC", "Box")
  • Dashboard with parsed data
  • Export to HTML

AI_QC Improvements

1. Centralized LLM Configuration

NO hardcoded API keys - All from environment Multi-provider support (OpenAI, Anthropic, Azure, Google) Retry logic with exponential backoff Token tracking and cost monitoring

2. Scoring System (0-100 Scale)

Thresholds:

  • 90-100: Pass (Excellent)
  • 70-89: Warning (Minor issues)
  • 0-69: Fail (Significant issues)

3. Sophisticated Prompt Engineering

Structured prompts with:

  • Evaluation criteria
  • Scoring guidance
  • Step-by-step instructions
  • Decision criteria
  • Required JSON output

4. Profile-Based Configuration

YAML profiles with:

  • Per-check weights
  • LLM provider/model selection
  • Enable/disable flags
  • Easy customization

Configuration

Environment Variables (.env)

# Flask
SECRET_KEY=<generate-random-key>
FLASK_ENV=development
HOST=0.0.0.0
PORT=7183

# Azure AD
AZURE_TENANT_ID=e519c2e6-bc6d-4fdf-8d9c-923c2f002385
AZURE_CLIENT_ID=9079054c-9620-4757-a256-23413042f1ef

# Box.com
BOX_CONFIG_PATH=config/box_config.json
BOX_REPORT_FOLDER_ID=133295752718

# LLM Providers (NO HARDCODED KEYS!)
OPENAI_API_KEY=<your-key>
ANTHROPIC_API_KEY=<your-key>

Generate SECRET_KEY:

python3 -c "import secrets; print(secrets.token_hex(32))"

Usage

HM QC Workflow

  1. Navigate to HM QC tab
  2. Upload PDF/image file
  3. Select profile and configure checks
  4. Enter job number
  5. Execute QC with real-time progress
  6. View results with 0-100 score
  7. Download HTML report

Video Master Matching (Python API)

from modules.video_master.matching import VideoMatcher

matcher = VideoMatcher(
    enable_ai_vision=True,
    use_akaze=True
)

matcher.add_master("/path/to/master.mp4", "master_1")
matches = matcher.match_adaptation("/path/to/adaptation.mp4")

for match in matches:
    print(f"Master: {match['master_id']}")
    print(f"Confidence: {match['confidence_score']}/100")
    print(f"Method: {match['matching_method']}")
  1. Navigate to Reporting tab
  2. Enter job number
  3. View consolidated results (Box + HM QC)
  4. Export to HTML

Testing

Integration Tests

python3 test_integration.py

Tests:

  • App initialization
  • Blueprint registration
  • Database connectivity
  • Core services
  • Route accessibility

See INTEGRATION_TEST_REPORT.md for detailed results.


Security

NO hardcoded API keys Azure AD JWT validation httpOnly cookies Input validation Secure file handling


Performance

Operation Time Cost
HM QC - Filename check <1s $0
HM QC - AI quality check 2-5s ~$0.01
Video Master - Stage 0 <1s $0
Video Master - Tier 1 5-10s $0
Video Master - Tier 2 5-10s $0
Video Master - Tier 3 3-5s ~$0.006

Documentation


Troubleshooting

Common Issues

1. Module Not Found

source venv/bin/activate
which python  # Should show venv path

2. ffmpeg Not Found

brew install ffmpeg  # macOS
sudo apt-get install ffmpeg  # Linux

3. LLM API Errors

echo $OPENAI_API_KEY  # Verify key is set

4. Database Locked

lsof database/qc_platform.db  # Check for other processes

Production Deployment

gunicorn -c gunicorn_config.py wsgi:app

Systemd Service

See DEPLOYMENT_CHECKLIST.md for complete systemd configuration.


Changelog

Version 1.0.0 (2026-02-02)

Initial Release

Core Infrastructure (Flask, SQLAlchemy, Auth) HM QC Module (Complete workflow with 2 checks) Video QC Module (Basic structure - BETA) Video Master Module (Complete 4-tier engine) Reporting Module (Box + Database consolidation) AI_QC Improvements (Scoring, prompts, LLM config) Unified UI (Tabbed interface with H&M branding)


License

Proprietary - H&M Hennes & Mauritz AB


Support

For issues or questions, contact the development team.


Built with ❤️ for H&M Quality Control