Watch
1
0
Fork
You've already forked swissgeol-assets-dataextraction
0
mirror of https://github.com/swisstopo/swissgeol-assets-dataextraction.git synced 2026-08-17 12:43:22 +00:00
Read-only mirror of https://github.com/swisstopo/swissgeol-assets-dataextraction — Bundesamt für Landestopografie. Issues & pull requests at the source. Catalog: https://www.opensource.admin.ch/en/softwares/ahbv8o https://www.opensource.admin.ch/en/softwares/ahbv8o
  • Python 99.5%
  • Dockerfile 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-05-21 09:11:35 +02:00
.github precommit update 2026-03-05 16:31:04 +01:00
.vscode move dependencies to uv 2026-03-05 16:27:37 +01:00
api change typing and return none if return_entities is False 2026-03-17 14:47:04 +01:00
config latest model with gt updated 2026-04-10 14:23:11 +02:00
docs Merge branch 'develop' into feat/issue-101/rethink-unknown-class 2026-04-13 11:16:07 +02:00
examples add reference document for testing 2026-03-09 16:50:51 +01:00
models/stable model is now WITHOUT OOD 2026-04-17 13:56:33 +02:00
prompts updated title detection with text anbd image 2026-03-05 08:18:10 +01:00
src change to sorted 2026-05-05 08:50:35 +02:00
tests reduced test version 2026-03-25 15:04:23 +01:00
.env.template clean fasttext references 2025-11-12 14:47:26 +01:00
.gitignore move dependencies to uv 2026-03-05 16:27:37 +01:00
.pre-commit-config.yaml move dependencies to uv 2026-03-05 16:27:37 +01:00
api.http Remove comment 2025-08-20 10:10:44 +02:00
docker-compose.yml Add docker build 2025-08-19 14:11:00 +02:00
Dockerfile add release 1.0.0 from boreholes 2026-04-10 14:32:20 +02:00
LICENSE.md first round correction 2026-02-25 10:51:34 +01:00
main.py solve merge conflict with script retrun structure 2026-03-17 15:41:53 +01:00
publiccode.yml Merge branch 'feat/issue-92/improve-readme' of https://github.com/swisstopo/swissgeol-assets-dataextraction into feat/issue-92/improve-readme 2026-02-25 10:52:33 +01:00
pyproject.toml add release 1.0.0 from boreholes 2026-04-10 14:32:20 +02:00
README.md final comment for asset run 2026-03-06 16:40:27 +01:00
uv.lock add release 1.0.0 from boreholes 2026-04-10 14:32:20 +02:00

Page Classification for Geological Documents

This repository provides a classification pipeline to categorise PDF pages from geological reports into document classes, with the goal of supporting document understanding and metadata extraction in the Assets platform. The solution can be used as a standalone API.

The classification helps to map individual pages in a document, which facilitates the identification of borehole profiles and maps in PDFs to link between documents on Assets and boreprofiles on Boreholes.

Features:

  • Classifies individual PDF pages into 8 document classes: Text, Boreprofile, Maps, TitlePage, GeoProfile, Table, Diagram, Unknown.
  • Two classifier backends: feature-based XGBoost (default) and Pixtral Large (via Amazon Bedrock).
  • REST API with versioned endpoints (V1, V2) and batch processing support.
  • SHAP-based model explainability for tree-based classifiers.
  • MLflow experiment tracking (optional).

Usage

1. Installation

Python >=3.11 is required. Install uv and let it manage the environment:

curl -LsSf https://astral.sh/uv/install.sh | sh

2. Install dependencies

To install base dependencies:

uv sync

For development, install all optional tools:

uv sync --all-extras

Then activate your environment:

source .venv/bin/activate

3. Configuration

Copy the environment template and configure your settings:

cp .env.template .env

4. Running as CLI

We base our running pipeline on the command:

python main.py -i <input_path> [-g <ground_truth_path>] [-c <classifier_name>] [-p <model_path>] [-w]

The input path -i is mandatory and can be either a single PDF file or a directory. In the latter case, all PDF files in that directory will be processed. To simply obtain predictions, use -w to write the results to data/prediction.json.

python main.py -i path/to/document.pdf -w

If no classifier (-c) is specified, the default treebased classifier is used. The model path (-p / --model_path) defaults to models/stable/model.joblib. The ground truth file (-g) is optional and only required to compute accuracy metrics:

python main.py -i data/single_pages/ -g data/gt_single_pages.json

See Model Training for the ground truth file format.

Classifier Description
treebased Default. Feature-based XGBoost model
pixtral Uses Pixtral Large via Amazon Bedrock

5. Running as API

uvicorn api.api:app --reload --host 0.0.0.0 --port 8000

For detailed endpoint documentation, output formats, and local S3 setup, see the API Usage Guide.

Documentation

Document Description
API Architecture API versioning and OpenAPI spec
API Usage Guide Endpoints, output formats, MinIO setup
Docker Deployment Building and running Docker images
Model Overview Stable model features and usage
Model Explainability SHAP interpretation for tree-based models
Model Training Data, XGBoost training, hyperparameter tuning
Pixtral Setup AWS Bedrock configuration

Repository Structure

  • api/: FastAPI application
  • config/: YAML configs (models, matching, prediction profiles)
  • data/: Input data, predictions and ground truths
  • docs/: Detailed documentation
  • evaluation/: Evaluation and metrics
  • models/: Trained models (TreeBased)
  • prompts/: Pixtral prompts
  • src/: Core logic and utility scripts
  • tests/: Unit tests
  • main.py: CLI entry point

Contributing

We use pre-commit hooks with Ruff for code formatting. After installing dependencies, run:

pre-commit install

This needs to be done only once. After installing, hooks will run automatically on each git commit.

Governance

This repository is managed by the Swiss Federal Office of Topography swisstopo. The project lead and primary maintainer is Stijn Vermeeren (@stijnvermeeren-swisstopo). Support has come from external contractors at Visium and EBP. Individual contributors are listed on GitHub's Contributors page.

We welcome suggestions, bug reports and code contributions from third parties. However, the priority of any external request will have to be evaluated based on compatibility with our legal mandate as a government agency.

License

This project is released as open-source software, under the principle of "public money, public code", in accordance with the 2023 federal law "EMBAG", and following the guidance of the tools for OSS published by the Federal Chancellery.

The source code is licensed under the AGPL-3.0-only License. This is due to the licensing of certain dependencies, most notably PyMuPDF, which is only available under either the AGPL license or a commercial license. If this dependency is removed in the future, we will switch to a more permissive license for this project.