Skip to main content

Module

detect_schema_from_image

Detect document schema from a PDF/image using Gemini 2.5 Flash vision. Extracts document type, header fields, line items, totals, and a confidence score. Returns:

pdf_to_image

Convert the first page of a PDF to PNG using Playwright (900x1270 viewport). Returns output_path.

schema_to_flat

Convert a detected schema (from detect_schema_from_image()) to a flat field_name -> value dict suitable for the verification pipeline. Flattening rules:
  • header.field_name -> field_name
  • items[i].field_name -> item_{i+1}_field_name
  • totals.field_name -> field_name
  • observations -> observations
  • None values are omitted
Example:

upload_and_generate

Full upload pipeline: input file -> schema detection -> verified photo generation. Pipeline:
  1. If PDF, convert to image via pdf_to_image()
  2. Detect schema via detect_schema_from_image()
  3. Save detected_schema.json and ground_truth.json
  4. Generate verified photos for each preset
  5. Save per-image _verification.json and _occlusion.json
Returns: