Skip to main content
Apec Sinlapachai
Back to Portfolio Overview
Project #3 · Multimodal SOP & AutomationMultimodal AI & Code Generation

Screen-to-SOP & Automation Generator

Multimodal AI pipeline that turns screen recordings into structured SOP documents, native flowcharts, and verified Playwright Python or n8n JSON automation scripts with zero hardcoded secrets.

Problem & Business Impact

Built for operations and engineering teams who spend hours manually writing step-by-step SOP manuals and brittle browser automation scripts from repetitive screen workflows. Raw screen recordings often contain exposed passwords, API tokens, or customer emails that cannot safely be hardcoded into generated scripts. This system extracts key visual frames in the browser, streams live AI progress over SSE, automatically moves sensitive values into environment variables, and verifies every generated script before delivery.

12 / 12 (100%)
Golden Eval Gate
100% Verified
Valid Script Rate
0.00%
Secret Leak Rate
40 / 40 Passed
Pytest Suite

Problem Solved

Operations teams repeat browser and back-office workflows daily, yet documenting Standard Operating Procedures (SOPs) and translating them into reliable automation scripts takes hours. Naive multimodal video-to-code prototypes upload huge raw video files, stall without progress feedback, leak credentials/PII into generated scripts, and output syntactically broken Playwright or n8n code.

Architecture & Engineering Decisions

1. Client-Side <canvas> Keyframe Extraction

  • Decodes uploaded or recorded browser video directly on the client using an HTML5 <canvas> pixel-difference detector, extracting 6–14 compressed JPEG keyframes (<= 300 KB each) instead of uploading multi-megabyte raw videos.
  • Keeps free-tier bandwidth and Gemini Vision token spend minimal while preserving every meaningful UI state transition.

2. Real-Time SSE Streaming Pipeline (/api/proxy/sop/api/v1/analyze/stream)

  • Streams live Server-Sent Events (extracting -> sanitizing -> composing_sop -> synthesizing_script -> complete) through a dedicated Next.js App Router streaming Route Handler (X-Accel-Buffering: no, Cache-Control: no-cache, no-transform) so users see real-time stage progress with zero cross-origin calls.

3. Secret & PDPA-to-.env Sanitizer (0.00% Secret Leak Rate)

  • Scans extracted workflow steps for emails, Thai phone numbers, Thai National IDs, API tokens, and password fields before SOP composition or script synthesis.
  • Replaces every detected sensitive value with typed environment variable placeholders (e.g., os.environ["PORTAL_PASSWORD"]) and generates a ready-to-use .env.example alongside the redaction audit table.

4. AST / Schema Verification Harness & Self-Repair Loop

  • Validates every generated Playwright Python script via Python's ast.parse, forbidden-operation checks (eval, exec, os.system, subprocess), and hardcoded-secret scanners; validates n8n workflows against strict node/connection JSON schemas.
  • If verification flags a syntax, schema, or security issue, an automated self-repair loop feeds the exact diagnostics back to the synthesizer before returning the final artifact.

5. Shared Supabase screen_to_sop.* Schema Isolation

  • Persists run metadata in an isolated PostgreSQL 16 schema (screen_to_sop.*) with PgBouncer-safe psycopg_pool connections (prepare_threshold=None), AUTH_MODE=demo_sandbox|token, and SHA-256 IP-hashed rate limiting.

Verified Benchmarks

  • Golden Eval Gate (12 / 12 Passed — 100%): End-to-end multimodal workflow extraction, SOP Markdown + Flowchart generation, and Playwright Python / n8n JSON synthesis.
  • Valid Script Rate (100% Verified): Zero syntax or schema failures after AST/schema verification + self-repair.
  • Hardcoded Secret Leak Rate (0.00%): All synthetic credentials, API tokens, and PDPA fields extracted cleanly into .env.example.
  • Automated Tests: 40 / 40 pytest passed + green CI.

Deep-Dive Questions for AI Copilot

Opens /chat with input pre-filled