""" Stage 1 - PDF processing. PDF bytes in, the text a model is allowed to read out, cut into windows. **Everything above `window_document` is lifted verbatim from the EDA notebook that built the corpus** (Final_project_V7_EDA.ipynb, cells 85-90). That is not tidiness - it is the whole correctness argument of this application. Part B measured Gemma on `payload_window` strings produced by exactly this code. If the app extracted text even slightly differently, the published F1 of 0.969 would stop describing this program. `tests/test_fidelity.py` re-derives the corpus columns from the original PDFs and fails on a single differing character. """ import re import zlib import numpy as np # -------------------------------------------------------------------------------------------- # Lifted verbatim from the corpus build. Do not "improve" anything in this block. # -------------------------------------------------------------------------------------------- STREAM_RE = re.compile(rb"(stream\r?\n)(.*?)(endstream)", re.S) INJECTION_MARKERS = { "javascript_injection": [rb"/S\s*/JavaScript", rb"/JS\s*\("], "cross_site_scripting": [rb"