8000 GitHub - pypi-ahmad/GroundMark: Agentic document parsing with context-aware, layout-aware Markdown, HTML, annotations, and JSON outputs. · GitHub
[go: up one dir, main page]

Skip to content

About

Agentic document parsing with context-aware, layout-aware Markdown, HTML, annotations, and JSON outputs.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

GroundMark

GroundMark turns scanned PDFs and images into layout-aware Markdown using gpt-6-sol.

GitHub repository

GroundMark asks Sol to preserve source text and layout, though transcription errors can still occur. The app keeps page, block, and bounding-box data for reading order, annotations, and JSON output. It does not extract business fields, apply a domain schema, or correct values. Document chat answers questions and summarizes parsed pages.

GroundMark architecture: document input, parsing, exports, and document chat

Explore the interactive architecture.

Install

GroundMark requires Python 3.14+. Install the GitHub release wheel with uv to use the app without cloning the repository:

uv tool install --python 3.14 "groundmark[layout] @ https://github.com/pypi-ahmad/GroundMark/releases/download/v1.1.0/groundmark-1.1.0-py3-none-any.whl"

If groundmark is not on PATH, run uv tool update-shell and open a new terminal. Install uv if needed.

You can also install the wheel in a Python 3.14+ virtual environment:

# Using uv:
uv venv --python 3.14
uv pip install "groundmark[layout] @ https://github.com/pypi-ahmad/GroundMark/releases/download/v1.1.0/groundmark-1.1.0-py3-none-any.whl"
.\.venv\Scripts\groundmark.exe --help

# Or, inside an activated virtual environment, using pip:
pip install "groundmark[layout] @ https://github.com/pypi-ahmad/GroundMark/releases/download/v1.1.0/groundmark-1.1.0-py3-none-any.whl"
groundmark --help

Use the GitHub URL when installing. The package named groundmark on PyPI belongs to a different project.

Configure your endpoint

Set your API key in PowerShell before starting the app:

$env:OPENAI_API_KEY = "your-api-key"
# Optional, for a compatible endpoint:
$env:OPENAI_BASE_URL = "https://your-endpoint.example/v1"

You can put the variables in a .env file in the working folder or pass --env-file path/to/settings.env. Variables already present in the process take priority. If you set them as Windows User or Machine variables, open a new terminal before starting GroundMark so it inherits them.

Leave OPENAI_BASE_URL unset or blank to use the SDK default. Custom endpoints must use HTTPS; HTTP is accepted only for loopback addresses. Never commit your key. See .env.example for optional resource limits.

The endpoint must support the app's models and structured visual parsing. Parsing uses gpt-6-sol; document chat uses gpt-6-luna. Setting a base URL does not change those model names.

Web UI

groundmark
# Optional workspace and port:
groundmark --workspace D:\Documents\GroundMark --port 5806

The default address is http://127.0.0.1:5805. The launcher reads .env from the workspace, which defaults to the current folder. UI uploads and results use a separate per-session temporary directory. --headless suppresses opening a browser. An occupied port produces a startup error.

Extract from the terminal

groundmark invoice.pdf output
groundmark invoice.pdf output --all
groundmark invoice.pdf output --markdown --html
groundmark invoice.pdf output --json --start-page 2 --end-page 5

Without a format flag, the command writes Markdown and any figure images it references. You can combine format flags; the selected pages are parsed once for all requested formats.

Option Output or behavior
--markdown Markdown and figure images
--html Self-contained HTML with embedded figures
--json Full extraction, grounding, and page diagnostics
--annotated-pdf PDF with selected V3 contours, Sol boxes, and detector-only overlays
--annotated-images Annotated page PNGs
--markdown-zip ZIP containing the named Markdown file and figures
--all All six formats
--start-page N, --end-page N Inclusive page range; all pages by default
--view full, --view clean Rendering view; full by default; JSON stays complete
--detailed-layout Experimental structure extraction, off by default
--env-file PATH Explicit configuration file
--overwrite Allow saving a new run in a nonempty output directory
--version, --help Version and usage

Use a new or empty output directory unless you pass --overwrite. The input file must be outside it. CLI exports and GUI downloads use the original filename and extraction start time in UTC, such as invoice_20260923_100045Z.md. One basename covers every format and stays fixed when you switch between Clean and Full. If the name is taken, GroundMark adds fractional seconds. It replaces unsupported filename characters and shortens long stems. The source hash remains in the grounded JSON.

The command prints generated paths to stdout and progress and diagnostics to stderr. Exit codes are 0 for success, 1 for failure, 2 for invalid arguments or configuration, 3 for partial extraction or export problems, and 130 for interruption. Usable partial output stays in the output directory.

Clone and run locally

git clone https://github.com/pypi-ahmad/GroundMark.git
cd GroundMark
uv sync --extra layout
uv run --extra layout groundmark
# Or extract without opening the UI:
uv run --extra layout groundmark invoice.pdf output --all

Windows users can also run run.cmd, which includes the layout extra and forwards launcher arguments. For development, run uv run --locked python -m pytest tests -q --import-mode=importlib. The Runbook covers artifacts, builds, upgrades, and troubleshooting.

GroundMark attempts local PP-DocLayoutV3 analysis before each Sol extraction request. The layout extra supplies the runtime dependencies; base imports and offline tests still work without them. First use downloads the pinned official model into the user cache unless an explicit local model directory is configured. The pinned PaddlePaddle/PP-DocLayoutV3_onnx export supplies boxes, native order, and decoded mask contours. Preparation verifies CUDA inference, with CPU fallback. A later CUDA execution failure gets one CPU retry; successful recovery retains CPU for later pages. If neither works, or dependencies are absent, extraction continues with Sol blocks and records a safe layout-fallback diagnostic. See runtime configuration and verification.

In Streamlit, the first valid Parse click shows “Preparing PP-DocLayoutV3…” and then the actual GPU (CUDA) or CPU device. Uploads and previews do not load the model. Preparation failure shows a warning and continues with Sol; another Parse click retries V3. Failed CPU recovery after a page CUDA failure is latched until process restart. The process keeps one ready model across reruns and uploads. Tab/view changes do not rerun inference. The Detailed layout checkbox remains a separate, experimental Sol structure option.

CLI extraction prints readiness, reuse, timings, and each page's outcome to stderr. The UI's Layout summary shows match/review counts; JSON layout_metadata retains full evidence. Review counts can overlap accepted matches and do not measure accuracy. Configure GROUNDMARK_LAYOUT_DEVICE=cpu for explicit CPU use or leave auto for verified CUDA with CPU fallback. GROUNDMARK_LAYOUT_MODEL_DIR selects existing pinned files; otherwise the standard Hugging Face cache is used. Restart the process after configuration changes.

Outputs

  • Input preview shows the selected source pages before processing.
  • Markdown has rendered and raw views, plus copy and download controls.
  • Annotated shows matched V3 contours, unmatched Sol boxes, and detector-only regions, with a PDF download.
  • HTML shows the self-contained rendered output and provides a download.
  • JSON shows the internal layout data with copy and download controls.
  • Chat answers document questions with gpt-6-luna at medium reasoning, using short responses and inline page references.

UI artifacts use a per-session temporary directory, cleaned when the upload is replaced or removed. Browser disconnects do not guarantee immediate cleanup or request cancellation; see the runbook. CLI extraction writes selected artifacts to the supplied output directory.

Markdown and HTML open in Clean view. Full also shows running headers and footers when Sol has classified them. Both views keep unclassified content. JSON and chat include all extracted content from successful pages; annotations also show unmatched detector regions for inspection. Tables without identified headers keep their first row as data. Figures with valid boxes appear as crops in the previews and HTML. Download Markdown with images packages the Markdown and crops in a ZIP.

Detailed layout (experimental) adds heading levels, nested lists, checkbox states, merged cells, and page-header/footer roles. It is off by default. In a five-page comparison before V3 integration, mean word-token F1 rose from 95.67% to 95.99%, but source review found new transcription errors. Those results do not measure the V3 path. See Layout evaluation for the results and limits.

How it works

LangGraph runs a fixed preprocess, parse, and finish sequence. It has no automatic extraction review or correction loop. The default prompt and response contract do not classify running headers or footers, so Clean and Full show the same blocks in default-mode results. Switching views makes no model calls and cannot recover structure the parser did not capture.

Saved JSON records schema_version: 2, the extraction profile, and separately validated layout_metadata with V3 regions, provenance, and reconciliation evidence. Older JSON without that field still loads. Neither strict Sol response schema includes it. The GUI graph saves the full Markdown and HTML; UI downloads use the selected view. CLI exports use the view chosen with --view.

GroundMark renders selected pages with the existing 200-DPI/1,600-pixel profile. V3 analyzes the same page image sent to gpt-6-sol, and both parsing prompts receive bounded region hints. The image remains the transcription source. After strict response validation, polygon-aware one-to-one assignment applies qualified V3 boxes and native relative order without changing Sol content, IDs, transcription confidence, or semantic structure. Full contours supply matching evidence and blue matched overlays on annotated images and PDFs. Unmatched Sol boxes are red; detector-only regions are amber and add no text. Unusable contours explicitly use V3 AABBs. Crops and rectangle consumers retain the selected AABB envelopes. All exports, figure crops, annotations, and chat evidence use the reconciled pages.

Pages run in source order. Each Sol request can include up to 12,000 characters from earlier successful pages. Runtime or unusable-guide failure uses Sol with explicit diagnostics. A reconciliation application defect retains the untouched Sol page and makes the document partial. Unmatched blocks keep their Sol geometry; unmatched V3 regions never invent text. Split/merge matches are allowed with review flags and coverage evidence. Matching thresholds are configurable provisional rules, not measured accuracy claims; see layout policy. The completion report separates CPU/CUDA execution and official-decoder checks from still-unmeasured correspondence and reading-order quality, and documents local replay without Sol calls.

LlamaParse describes a parse-first approach. LandingAI ADE shows a similar Markdown and annotation workflow. The GPT-6 Sol page covers the model's capabilities and pricing.

Supported inputs are PDF, PNG, JPEG, TIFF, and WebP. Parsing accepts only gpt-6-sol; chat uses only gpt-6-luna.

Chat reads successfully parsed pages from the current run. It does not read the original files or failed pages. Before showing an answer, the app checks quoted excerpts against the parsed text and makes a separate verification call. Chat refuses unrelated requests and has no tools or browsing. These controls reduce prompt-injection risk, though they cannot prevent every attack. History stays in the browser session and resets when the document, page range, extraction mode, or parse run changes.

For development, install the test dependency and run the suite through uv:

uv sync --locked
uv run --locked python -m pytest tests -q --import-mode=importlib

The suite uses fake layout runtimes and fake model responses; it needs neither weights nor paid calls. Use uv run --extra layout to include V3 after a base-only sync. Without the extra, extraction uses the documented Sol fallback.

New contributors can start with onboarding, then follow the hands-on zero-to-mastery tutorial. The developer guide maps the Python modules and their test boundaries; the contributor runbook covers a local change and review handoff.

Diagrams

The diagrams show parsing, artifact flow, run outcomes, and document chat. Each image has an interactive version.

Document parsing workflow

Document parsing workflow from upload through export and diagnostics

Explore the workflow.

Document extraction data flow

Data flow from source pages through layout validation to output artifacts

Explore the data flow.

Document execution lifecycle

Execution lifecycle with page diagnostics and full, partial, or failed parse outcomes

Explore the lifecycle.

Parse and chat sequence

Parse and chat calls, including local quote checks and a separate verification call

Explore the sequence.

The editable JSON and visual-check captures are in docs/diagrams.

Documentation

License

GroundMark's original code is MIT licensed. Adapted Pa 63A1 ddleX polygon routines in src/layout_polygons.py retain their Apache-2.0 notice.

About

Agentic document parsing with context-aware, layout-aware Markdown, HTML, annotations, and JSON outputs.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0