Commit graph

3 commits

Author SHA1 Message Date
chopratejas
13081f4647 Skip image tests when Pillow not installed (CI fix)
Tests that create PIL images now have @needs_pillow decorator.
Token estimation and tile math tests still run without Pillow.
2026-04-09 16:24:15 -07:00
chopratejas
65e4a35546 Add OCR routing via RapidOCR + measure actual tokens after compression
Transcode technique now runs RapidOCR to extract text from images.
Falls back to full_low if OCR confidence < 70% or no text detected.

Token counting is now done AFTER compression by measuring the actual
output — no hardcoded estimates. OCR text counted by char length,
resized images re-estimated from new dimensions.

RapidOCR added to headroom-ai[image] extra (~15MB ONNX models, ~180ms CPU).
4 new OCR tests (extraction, blank image, confidence threshold, full pipeline).
29 total image compression tests passing.
2026-04-09 16:22:18 -07:00
chopratejas
7984bd2389 Re-enable image compression: tile optimizer + ONNX router, no PyTorch
Image compression pipeline:
1. Tile-boundary alignment (pure math, 0ms) — saves 340-680 tokens/image
   on OpenAI by snapping to 512px tile boundaries
2. ONNX technique router (32MB, 6ms) — classifies query intent
3. ONNX SigLIP image encoder (95MB, 49ms) — analyzes image properties

Total: ~127MB models, ~55ms latency, no PyTorch dependency.
Re-enabled in both Anthropic and OpenAI proxy handlers.
25 tests.
2026-04-09 16:11:00 -07:00