upload version 2
This commit is contained in:
177
BAO_CAO_KET_QUA_V2.md
Normal file
177
BAO_CAO_KET_QUA_V2.md
Normal file
@@ -0,0 +1,177 @@
|
||||
# Báo cáo kết quả giả lập thông tin nhạy cảm trong PDF — phiên bản 2
|
||||
|
||||
## 1. Mục tiêu
|
||||
|
||||
Phiên bản 2 mở rộng quy trình xử lý 23 mẫu Daily Drilling Report dạng vector trong thư mục `DDR templates`.
|
||||
|
||||
Ngoài việc ẩn logo và thay tên giếng, tên giàn khoan, tọa độ bằng dữ liệu giả như phiên bản 1, phiên bản này còn:
|
||||
|
||||
- Phát hiện các tên người đã khảo sát trong từng mẫu tài liệu.
|
||||
- Xóa vĩnh viễn chuỗi tên gốc khỏi lớp văn bản PDF.
|
||||
- Chèn tên giả có hình thức tự nhiên vào đúng vị trí cũ.
|
||||
- Thay tên công ty xuất hiện trong tiêu đề/header bằng tên công ty giả.
|
||||
- Áp dụng riêng quy tắc `CLJOC` thành `CLCORP` cho biểu mẫu CuuLong.
|
||||
- Giữ kiểu viết hoa, dạng viết tắt và cấu trúc danh sách tên khi có thể.
|
||||
- Giữ nguyên nhãn trường, bảng biểu, đường kẻ, màu nền và các nội dung không nhạy cảm.
|
||||
- Chạy hoàn toàn cục bộ, không gọi ChatGPT, GLM, LLM hoặc API mạng.
|
||||
|
||||
Ngày cập nhật báo cáo: **17/09/2026**.
|
||||
|
||||
## 2. Phạm vi dữ liệu
|
||||
|
||||
- Tổng số PDF đầu vào: **24**.
|
||||
- PDF vector được xử lý: **23**.
|
||||
- PDF scan chủ động bỏ qua: **1** (`VIETSOPETRO.pdf`).
|
||||
- Tổng số trang vector được xử lý: **161**.
|
||||
- Số mẫu tên người được cấu hình: **105**.
|
||||
- Số mẫu có tên công ty trong tiêu đề/header: **12**.
|
||||
|
||||
## 3. Rule mới cho tên người và tên công ty trong tiêu đề
|
||||
|
||||
Rule được lưu trong biến `PERSON_TERMS` của `censor_pdfs_v2.py` và được cấu hình riêng theo tên tệp PDF. Các vị trí đã khảo sát gồm:
|
||||
|
||||
- Tên người liên hệ, đại diện và người phê duyệt.
|
||||
- Drilling supervisor, night supervisor, manager và engineer.
|
||||
- Danh sách personnel/crew.
|
||||
- Tên trong vùng chữ ký và phần mô tả nghiệp vụ.
|
||||
- Tên ghép bằng dấu `/`, `//` hoặc `+`.
|
||||
- Tên dạng `HỌ, TÊN`, tên viết hoa và tên viết tắt bằng chữ cái đầu.
|
||||
- Biến thể sai chính tả đã quan sát trong tài liệu.
|
||||
|
||||
Tên giả được sinh xác định bằng SHA-256 từ chuỗi gốc. Vì vậy, cùng một tên gốc luôn nhận cùng một kết quả khi chạy lại trên cùng phiên bản mã. Với một ô chứa nhiều người, số lượng tên và cấu trúc phân tách được giữ lại.
|
||||
|
||||
Phiên bản 2 dùng danh sách rule đã kiểm duyệt thay vì mô hình nhận dạng thực thể tự động. Cách làm này tránh thay nhầm tên công ty, địa danh, thuật ngữ kỹ thuật hoặc nhãn biểu mẫu.
|
||||
|
||||
Tên công ty trong tiêu đề được quản lý riêng bằng `COMPANY_TITLE_TERMS`. Logo ảnh vẫn bị ẩn; phần tên công ty dạng văn bản trong tiêu đề được giữ vị trí và thay bằng giá trị giả thay vì xóa trắng.
|
||||
|
||||
## 4. Quy trình xử lý
|
||||
|
||||
1. Chạy logic phiên bản 1 trong thư mục tạm để ẩn logo và giả lập tên giếng, tên giàn khoan, tọa độ.
|
||||
2. Giữ lại tên công ty dạng văn bản trong tiêu đề để thay thế; logo raster vẫn được phát hiện và ẩn.
|
||||
3. Tìm từng tên người và tên công ty tiêu đề đã cấu hình bằng lớp văn bản vector của PDF.
|
||||
4. Xóa glyph của giá trị gốc nhưng không xóa ảnh, đường kẻ hoặc nền bảng.
|
||||
5. Chèn giá trị giả vào cùng vùng, dựa trên cỡ chữ, màu chữ và đường cơ sở của nội dung gốc.
|
||||
6. Xóa metadata, XML metadata, nội dung ẩn và dữ liệu nhúng khi cấu trúc tài liệu cho phép.
|
||||
7. Lưu PDF mới, rồi kiểm tra giá trị gốc không còn tìm kiếm được và giá trị giả có thể tìm kiếm được.
|
||||
|
||||
## 5. Kết quả tổng hợp
|
||||
|
||||
| Chỉ tiêu | Kết quả |
|
||||
|---|---:|
|
||||
| PDF vector xử lý thành công | 23 |
|
||||
| Tổng số trang đã xử lý | 161 |
|
||||
| Vị trí logo đã ẩn | 110 |
|
||||
| Vị trí tên giếng đã thay | 152 |
|
||||
| Vị trí tên giàn khoan đã thay | 114 |
|
||||
| Vị trí tọa độ đã thay | 38 |
|
||||
| Vị trí tên người đã thay | 207 |
|
||||
| Vị trí tên công ty trong tiêu đề đã thay | 80 |
|
||||
| Tệp lỗi | 0 |
|
||||
| Tệp cảnh báo | 0 |
|
||||
| PDF scan bỏ qua | 1 |
|
||||
| Tổng dung lượng PDF đầu ra | 5.253.225 byte |
|
||||
|
||||
Số vị trí là tổng số vùng được xử lý trên tất cả các trang, không phải số giá trị duy nhất.
|
||||
|
||||
## 6. Kết quả thay tên người theo từng tệp
|
||||
|
||||
| Tệp | Trang | Vị trí tên người | Trạng thái |
|
||||
|---|---:|---:|---|
|
||||
| CuuLong.pdf | 2 | 2 | Đạt |
|
||||
| HarbourEnergy.pdf | 6 | 8 | Đạt |
|
||||
| Hibiscus.pdf | 4 | 3 | Đạt |
|
||||
| HOANGLONG_JOC.pdf | 2 | 10 | Đạt |
|
||||
| Murphy.pdf | 4 | 4 | Đạt |
|
||||
| PetronasCarigali.pdf | 3 | 1 | Đạt |
|
||||
| PVEP_POC-2.pdf | 2 | 8 | Đạt |
|
||||
| PVEP_POC.pdf | 2 | 4 | Đạt |
|
||||
| Sonatrack.pdf | 2 | 2 | Đạt |
|
||||
| THANGLONG_JOC.pdf | 3 | 10 | Đạt |
|
||||
| VIETSOPETRO.pdf | 0 | - | Bỏ qua (PDF scan) |
|
||||
| VIETSOPETRO_2.pdf | 2 | 4 | Đạt |
|
||||
| AMAL.pdf | 30 | 3 | Đạt |
|
||||
| AmourEnergy.pdf | 60 | 86 | Đạt |
|
||||
| Chevron.pdf | 4 | 6 | Đạt |
|
||||
| GPC.pdf | 1 | 3 | Đạt |
|
||||
| HOKCHI.pdf | 9 | 6 | Đạt |
|
||||
| Khalda.pdf | 3 | 6 | Đạt |
|
||||
| NISOC.pdf | 4 | 7 | Đạt |
|
||||
| PETROMINERALES.pdf | 6 | 4 | Đạt |
|
||||
| POGC.pdf | 4 | 5 | Đạt |
|
||||
| SONATRACH.pdf | 3 | 16 | Đạt |
|
||||
| SPD.pdf | 4 | 5 | Đạt |
|
||||
| WellView.pdf | 1 | 4 | Đạt |
|
||||
|
||||
### 6.1. Tên công ty trong tiêu đề/header
|
||||
|
||||
| Tệp | Giá trị gốc | Giá trị giả | Vị trí |
|
||||
|---|---|---|---:|
|
||||
| CuuLong.pdf | CLJOC | CLCORP | 4 |
|
||||
| HOANGLONG_JOC.pdf | HOANG LONG JOC | HORIZON JOC | 2 |
|
||||
| Hibiscus.pdf | Hibiscus Oil & Gas Malaysia Limited | Bluewave Oil & Gas Malaysia Limited | 4 |
|
||||
| PetronasCarigali.pdf | PETRONAS CARIGALI SDN BHD | MERIDIAN ENERGY SDN BHD | 3 |
|
||||
| THANGLONG_JOC.pdf | TLJOC | TLCORP | 2 |
|
||||
| VIETSOPETRO_2.pdf | VIETSOVPETRO | BLUESEA ENERGY | 1 |
|
||||
| AmourEnergy.pdf | ARMOUR ENERGY LTD | NORTHRIDGE ENERGY LTD | 40 |
|
||||
| Chevron.pdf | Chevron Bangladesh | Horizon Bangladesh | 4 |
|
||||
| GPC.pdf | G.P.C | R.P.C | 2 |
|
||||
| HOKCHI.pdf | HOKCHI ENERGY S.A. de C.V. | NOVA ENERGY S.A. de C.V. | 9 |
|
||||
| PETROMINERALES.pdf | PETROMINERALES PERU S.A. | ANDES ENERGY PERU S.A. | 6 |
|
||||
| SONATRACH.pdf | SONATRACH | SAHARA ENERGY | 3 |
|
||||
|
||||
## 7. Kiểm thử và xác minh
|
||||
|
||||
- Biên dịch thành công `censor_pdfs_v2.py` và `test_censor_pdfs_v2.py`.
|
||||
- Chạy **11/11** bài kiểm thử tự động thành công.
|
||||
- Mở và render thử **161/161** trang đầu ra thành công.
|
||||
- Đối chiếu toàn bộ **105** mẫu tên người: không còn mẫu gốc trong lớp văn bản PDF đầu ra.
|
||||
- Đối chiếu **12** rule tiêu đề với **80** vị trí: không còn tên công ty gốc trong lớp văn bản PDF đầu ra.
|
||||
- Kiểm tra toàn bộ tên giả đã chèn: không thiếu giá trị nào trong lớp văn bản.
|
||||
- Kiểm tra trực quan các mẫu đại diện thuộc nhiều bố cục, gồm bảng personnel, vùng contact/supervisor, chữ viết hoa, tên viết tắt và danh sách nhiều người trong một ô.
|
||||
- Kiểm tra trực quan tiêu đề của toàn bộ 12 mẫu có tên công ty; không có chữ bị cắt hoặc chồng lên thành phần khác.
|
||||
- Kết quả kiểm toán: **0 lỗi, 0 cảnh báo**.
|
||||
|
||||
## 8. Tệp đầu ra
|
||||
|
||||
- Chương trình v2: `censor_pdfs_v2.py`.
|
||||
- Kiểm thử v2: `test_censor_pdfs_v2.py`.
|
||||
- PDF đầu ra: `pseudonymized_v2/private` và `pseudonymized_v2/public`.
|
||||
- Nhật ký kiểm toán: `pseudonymized_v2/audit.json`.
|
||||
- Ảnh trực quan có bounding box: `visualization` (128 ảnh, 591 box; màu tím là tên công ty trong tiêu đề).
|
||||
- Script tạo ảnh trực quan: `visualize_synthetic_values.py`.
|
||||
- Phiên bản 1 được giữ nguyên tại `censor_pdfs.py` và `pseudonymized`.
|
||||
|
||||
## 9. Cách tái lập kết quả
|
||||
|
||||
```bash
|
||||
cd /Users/tungedng2710/Work/censor_data
|
||||
conda activate ai
|
||||
pip install -r requirements.txt
|
||||
python censor_pdfs_v2.py
|
||||
```
|
||||
|
||||
Chạy kiểm thử:
|
||||
|
||||
```bash
|
||||
python -m unittest -v
|
||||
```
|
||||
|
||||
Mặc định logo được che bằng nền trắng. Có thể dùng nền đen bằng lệnh:
|
||||
|
||||
```bash
|
||||
python censor_pdfs_v2.py --logo-fill black
|
||||
```
|
||||
|
||||
Quy trình chạy không cần Internet và không gọi ChatGPT/GLM. Internet chỉ có thể cần trong lần đầu cài thư viện nếu môi trường `ai` chưa có đủ gói trong `requirements.txt`.
|
||||
|
||||
## 10. Lưu ý và giới hạn
|
||||
|
||||
- Rule hiện được cấu hình cho đúng 23 tệp vector đã khảo sát. Tài liệu mới, tên người mới hoặc tên công ty tiêu đề mới cần được bổ sung vào `PERSON_TERMS` hoặc `COMPANY_TITLE_TERMS`.
|
||||
- `VIETSOPETRO.pdf` là PDF scan và chưa nằm trong quy trình v2; cần OCR và xử lý ảnh nếu muốn hỗ trợ tệp này.
|
||||
- PDF nguồn trong `DDR templates` vẫn chứa dữ liệu thật và phải được bảo vệ.
|
||||
- Mã nguồn v2 chứa chuỗi tên gốc để so khớp. Không nên phát hành công khai mã nếu chưa tách hoặc bảo vệ phần cấu hình này.
|
||||
- Nên kiểm tra trực quan lại sau khi bổ sung mẫu PDF, thay đổi rule hoặc cập nhật thư viện PDF.
|
||||
|
||||
## 11. Kết luận
|
||||
|
||||
Phiên bản 2 đã thay thành công tên người và tên công ty trong tiêu đề bằng dữ liệu giả có thể đọc và trích xuất, đồng thời giữ nguyên cấu trúc tài liệu để phục vụ huấn luyện Document AI. Tất cả 23 PDF vector đều đạt kiểm tra tự động và kiểm tra render; phiên bản này tái lập được hoàn toàn bằng mã cục bộ, không phụ thuộc LLM.
|
||||
392
censor_pdfs_v2.py
Normal file
392
censor_pdfs_v2.py
Normal file
@@ -0,0 +1,392 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Pseudonymize DDR PDFs, including personal names (version 2).
|
||||
|
||||
Version 2 extends ``censor_pdfs.py``. It still hides logos and replaces well
|
||||
names, rig names, and coordinates, then permanently removes known personal names
|
||||
and inserts deterministic synthetic names in the same positions.
|
||||
|
||||
No LLM, network service, or external API is used at runtime.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
from dataclasses import asdict, dataclass, field, replace
|
||||
from pathlib import Path
|
||||
from typing import Iterable, Sequence
|
||||
|
||||
import pymupdf
|
||||
|
||||
import censor_pdfs as v1
|
||||
|
||||
|
||||
PERSON_TERMS: dict[str, tuple[str, ...]] = {
|
||||
"CuuLong.pdf": ("Micheal Ting", "Nguyen Hong Hiep"),
|
||||
"HOANGLONG_JOC.pdf": (
|
||||
"Yong Kong Hai", "Mike Budrow", "Bui Xuan Them", "Tran Nam",
|
||||
"L.H. Phuong", "Chu The Phong", "Kevin Jamie Howlett",
|
||||
),
|
||||
"HarbourEnergy.pdf": (
|
||||
"Ray Third", "Pham The Thuc", "Nham Xuan Bich", "Phu / Ho",
|
||||
"William James", "Le Tran Hau",
|
||||
),
|
||||
"Hibiscus.pdf": ("Anne / Afzan", "Muzily / Hakimi", "Nor Hazlindah"),
|
||||
"Murphy.pdf": ("Trung Pham", "Andy Patrickis", "Lindsay McCracken", "Jason Hewit"),
|
||||
"PVEP_POC-2.pdf": (
|
||||
"Dave Spink / NH Hiep / LT Thinh", "VH Sang / CV Dinh", "NM Cuong",
|
||||
"NDN Tri / RV Viet / DS Ha",
|
||||
),
|
||||
"PVEP_POC.pdf": ("Steve Lees/L.H.Khoat", "Nguyen Duy Sam"),
|
||||
"PetronasCarigali.pdf": ("Iskanta/Aswade/Azlan",),
|
||||
"Sonatrack.pdf": ("H.Bouadou//K.Hadjab", "A. Chellali"),
|
||||
"THANGLONG_JOC.pdf": (
|
||||
"Mike Turgeon", "Pham The Thuc", "Mark Sword", "Kishore Kelamparabil",
|
||||
"Tran Ba Hung",
|
||||
),
|
||||
"VIETSOPETRO_2.pdf": ("Nguyen Van Tien", "Nguyen Thanh Hieu"),
|
||||
"AMAL.pdf": ("MOHAMED HASHEM", "MOHAMED SABER", "ISLAM BADR"),
|
||||
"AmourEnergy.pdf": (
|
||||
"Shane Bennett", "Shane Bennet", "Don Castles", "Jon Martin",
|
||||
"Damian Paranihi", "Dexter", "Matthew Morgan",
|
||||
),
|
||||
"Chevron.pdf": (
|
||||
"HASAN ARAFAT", "Shayne Atkins", "Stephen Joubert", "Mahbubur Rahman",
|
||||
"Ismail Hossain", "Jay Darder",
|
||||
),
|
||||
"GPC.pdf": ("HANY MESALLAM", "MAHMOUD TAIMOUR"),
|
||||
"HOKCHI.pdf": (
|
||||
"OPORTO, RAUL", "McCASKIE, ROBIN", "TERRERA, DIEGO", "SMITH, WALLACE",
|
||||
"LUAN, XIAO WEI", "JOEL DE LA FUENTE",
|
||||
),
|
||||
"Khalda.pdf": (
|
||||
"Abdel kawy Zidan", "khaled abd El-naser", "Mohamed Maher Mostafa",
|
||||
"Mohamed Mousa", "Ashraf Adel Shawky Helal", "mohamed mahmoud reda",
|
||||
),
|
||||
"NISOC.pdf": (
|
||||
"Mehdi Farahani", "A.Bozorgi", "M.Rasouli/E.Mondanipour", "H.Bonyadi",
|
||||
"A.Asghari", "M.Salmani", "R.Rezaee/M.Ameri",
|
||||
),
|
||||
"PETROMINERALES.pdf": (
|
||||
"J. BARRERA / W. BAQUERO", "FERNANDO ROMERO / FELIX CUADROS",
|
||||
),
|
||||
"POGC.pdf": (
|
||||
"Mohamad Reza Kazemi", "Sajad Nouri", "Behnam Fattahi", "Mohsen Karami",
|
||||
"M.Alipour/S.Sadeghi",
|
||||
),
|
||||
"SONATRACH.pdf": (
|
||||
"S.DOUADI / A.ROUAIGUIA", "S,BENSEMCHA+S,DOUADI", "F,BENGASMI",
|
||||
"A,BELABBAS", "M,AMROUNE", "H,KARA", "A.SAOUD", "L.BENACHI",
|
||||
"A,YOUSFI", "K,MESSAOUD", "H,SALEM", "N,ABBASSEN", "S,MIKAOUSSI",
|
||||
"A,KIRECHE",
|
||||
),
|
||||
"SPD.pdf": (
|
||||
"Mohamad Reza Kazemi", "Sajad Nouri", "Behnam Fattahi", "Mohsen Karami",
|
||||
"M.Alipour/S.Sadeghi",
|
||||
),
|
||||
"WellView.pdf": ("Tom Black", "Jim Green", "David Brown", "Sam White"),
|
||||
}
|
||||
|
||||
|
||||
# Company names that are part of a document title/header are replaced with
|
||||
# synthetic text. Raster logos are still hidden by the v1 stage. CuuLong's
|
||||
# replacement is explicitly specified; the others are plausible fake names.
|
||||
COMPANY_TITLE_TERMS: dict[str, tuple[tuple[str, str], ...]] = {
|
||||
"CuuLong.pdf": (("CLJOC", "CLCORP"),),
|
||||
"HOANGLONG_JOC.pdf": (("HOANG LONG JOC", "HORIZON JOC"),),
|
||||
"Hibiscus.pdf": ((
|
||||
"Hibiscus Oil & Gas Malaysia Limited",
|
||||
"Bluewave Oil & Gas Malaysia Limited",
|
||||
),),
|
||||
"PetronasCarigali.pdf": ((
|
||||
"PETRONAS CARIGALI SDN BHD",
|
||||
"MERIDIAN ENERGY SDN BHD",
|
||||
),),
|
||||
"THANGLONG_JOC.pdf": (("TLJOC", "TLCORP"),),
|
||||
"VIETSOPETRO_2.pdf": (("VIETSOVPETRO", "BLUESEA ENERGY"),),
|
||||
"AmourEnergy.pdf": (("ARMOUR ENERGY LTD", "NORTHRIDGE ENERGY LTD"),),
|
||||
"Chevron.pdf": (("Chevron Bangladesh", "Horizon Bangladesh"),),
|
||||
"GPC.pdf": (("G.P.C", "R.P.C"),),
|
||||
"HOKCHI.pdf": ((
|
||||
"HOKCHI ENERGY S.A. de C.V.",
|
||||
"NOVA ENERGY S.A. de C.V.",
|
||||
),),
|
||||
"PETROMINERALES.pdf": ((
|
||||
"PETROMINERALES PERU S.A.",
|
||||
"ANDES ENERGY PERU S.A.",
|
||||
),),
|
||||
"SONATRACH.pdf": (("SONATRACH", "SAHARA ENERGY"),),
|
||||
}
|
||||
|
||||
|
||||
FIRST_NAMES = (
|
||||
"Alex", "Avery", "Cameron", "Casey", "Dylan", "Elliot", "Hayden", "Jamie",
|
||||
"Jordan", "Morgan", "Parker", "Quinn", "Riley", "Robin", "Rowan", "Sam",
|
||||
"Taylor",
|
||||
)
|
||||
LAST_NAMES = (
|
||||
"Adams", "Baker", "Carter", "Davis", "Evans", "Foster", "Garcia", "Harris",
|
||||
"Ito", "Khan", "Lewis", "Martin", "Nguyen", "Patel", "Reed", "Silva",
|
||||
"Turner", "Walker", "Young",
|
||||
)
|
||||
ALIASES = {"Shane Bennet": "Shane Bennett"}
|
||||
|
||||
|
||||
@dataclass
|
||||
class V2Audit:
|
||||
input: str
|
||||
output: str
|
||||
status: str
|
||||
pages: int = 0
|
||||
replacements: dict[str, int] = field(default_factory=dict)
|
||||
synthetic_values: dict[str, list[str]] = field(default_factory=dict)
|
||||
missing: list[str] = field(default_factory=list)
|
||||
error: str | None = None
|
||||
|
||||
|
||||
def _hash_int(value: str) -> int:
|
||||
return int(hashlib.sha256(value.encode("utf-8")).hexdigest()[:16], 16)
|
||||
|
||||
|
||||
def _one_fake_name(key: str, index: int = 0) -> str:
|
||||
value = _hash_int(f"{key}:{index}")
|
||||
first = FIRST_NAMES[value % len(FIRST_NAMES)]
|
||||
last = LAST_NAMES[(value // len(FIRST_NAMES)) % len(LAST_NAMES)]
|
||||
return f"{first} {last}"
|
||||
|
||||
|
||||
def fake_person_name(original: str) -> str:
|
||||
"""Return a stable, human-looking replacement while preserving list shape."""
|
||||
canonical = ALIASES.get(original, original)
|
||||
parts = [part.strip() for part in re.split(r"/{1,2}|\+", canonical) if part.strip()]
|
||||
if len(parts) > 1:
|
||||
return " / ".join(_one_fake_name(canonical, index) for index in range(len(parts)))
|
||||
|
||||
comma_name = re.fullmatch(r"([A-Za-z.]+),\s*([A-Za-z. ]+)", canonical)
|
||||
fake = _one_fake_name(canonical)
|
||||
first, last = fake.split(" ", 1)
|
||||
if comma_name:
|
||||
if len(comma_name.group(1).replace(".", "")) == 1:
|
||||
return f"{first[0]},{last.upper()}"
|
||||
return f"{last.upper()}, {first.upper()}"
|
||||
if re.match(r"^[A-Za-z]\.", canonical):
|
||||
return f"{first[0]}. {last}"
|
||||
if canonical.isupper():
|
||||
return fake.upper()
|
||||
return fake
|
||||
|
||||
|
||||
def _profile_for_v2(original_filename: str) -> v1.Profile:
|
||||
"""Keep title text for replacement while retaining raster-logo removal."""
|
||||
profile = v1.PROFILES[original_filename]
|
||||
if original_filename not in COMPANY_TITLE_TERMS:
|
||||
return profile
|
||||
terms = {category: tuple(values) for category, values in profile.terms.items()}
|
||||
# These text entries represented company-name headers in v1. V2 replaces
|
||||
# them instead of blanking them; image-based logos are still detected.
|
||||
terms.pop("logo", None)
|
||||
rectangles = tuple(rule for rule in profile.rectangles if rule.category != "logo")
|
||||
not_applicable = tuple(dict.fromkeys((*profile.not_applicable, "logo")))
|
||||
return replace(
|
||||
profile, terms=terms, rectangles=rectangles,
|
||||
not_applicable=not_applicable,
|
||||
)
|
||||
|
||||
|
||||
def _replace_configured_text(
|
||||
source: Path,
|
||||
destination: Path,
|
||||
original_filename: str,
|
||||
scrub: bool,
|
||||
categories: tuple[str, ...] = ("person_name", "company_title"),
|
||||
) -> tuple[dict[str, int], dict[str, list[str]]]:
|
||||
replacements: dict[str, dict[str, str]] = {}
|
||||
if "person_name" in categories:
|
||||
replacements["person_name"] = {
|
||||
term: fake_person_name(term) for term in PERSON_TERMS[original_filename]
|
||||
}
|
||||
if "company_title" in categories:
|
||||
replacements["company_title"] = dict(
|
||||
COMPANY_TITLE_TERMS.get(original_filename, ())
|
||||
)
|
||||
document = pymupdf.open(source)
|
||||
replacement_counts = {category: 0 for category in categories}
|
||||
inserted_values = {category: set() for category in categories}
|
||||
|
||||
for page in document:
|
||||
candidates: list[v1.TextCandidate] = []
|
||||
# Longer strings go first so an abbreviated name inside a full name does
|
||||
# not create overlapping redaction annotations.
|
||||
configured = [
|
||||
(category, term, synthetic)
|
||||
for category, mapping in replacements.items()
|
||||
for term, synthetic in mapping.items()
|
||||
]
|
||||
for category, term, synthetic in sorted(configured, key=lambda item: len(item[1]), reverse=True):
|
||||
for rect in page.search_for(term):
|
||||
size, color, baseline = v1._style(page, rect)
|
||||
v1._add_text(candidates, v1.TextCandidate(
|
||||
category, rect + (-0.5, -0.5, 0.5, 0.5), synthetic,
|
||||
size, color, baseline,
|
||||
))
|
||||
|
||||
for candidate in candidates:
|
||||
page.add_redact_annot(candidate.rect, fill=False, cross_out=False)
|
||||
if candidates:
|
||||
page.apply_redactions(
|
||||
images=pymupdf.PDF_REDACT_IMAGE_NONE,
|
||||
graphics=pymupdf.PDF_REDACT_LINE_ART_NONE,
|
||||
text=pymupdf.PDF_REDACT_TEXT_REMOVE,
|
||||
)
|
||||
for candidate in candidates:
|
||||
v1._insert_replacement(page, candidate)
|
||||
replacement_counts[candidate.category] += 1
|
||||
inserted_values[candidate.category].add(candidate.replacement)
|
||||
|
||||
if scrub:
|
||||
document.scrub(
|
||||
attached_files=True, clean_pages=True, embedded_files=True, hidden_text=True,
|
||||
javascript=True, metadata=True, redactions=True, redact_images=0,
|
||||
remove_links=False, reset_fields=True, reset_responses=True, thumbnails=True,
|
||||
xml_metadata=True,
|
||||
)
|
||||
else:
|
||||
document.set_metadata({})
|
||||
document.del_xml_metadata()
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
document.save(destination, garbage=4, clean=True, deflate=True)
|
||||
document.close()
|
||||
|
||||
check = pymupdf.open(destination)
|
||||
leaked = [
|
||||
term
|
||||
for mapping in replacements.values()
|
||||
for term in mapping
|
||||
if any(page.search_for(term) for page in check)
|
||||
]
|
||||
inserted = {
|
||||
category: sorted(values) for category, values in inserted_values.items()
|
||||
}
|
||||
missing_fakes = [
|
||||
value
|
||||
for values in inserted.values()
|
||||
for value in values
|
||||
if not any(page.search_for(value) for page in check)
|
||||
]
|
||||
check.close()
|
||||
if leaked:
|
||||
raise RuntimeError("sensitive text still searchable: " + ", ".join(leaked))
|
||||
if missing_fakes:
|
||||
raise RuntimeError("synthetic text not searchable: " + ", ".join(missing_fakes))
|
||||
return replacement_counts, inserted
|
||||
|
||||
|
||||
def _replace_people(
|
||||
source: Path, destination: Path, original_filename: str, scrub: bool
|
||||
) -> tuple[int, list[str]]:
|
||||
"""Backward-compatible helper used by the focused person-name tests."""
|
||||
counts, inserted = _replace_configured_text(
|
||||
source, destination, original_filename, scrub, ("person_name",)
|
||||
)
|
||||
return counts["person_name"], inserted["person_name"]
|
||||
|
||||
|
||||
def _build_audit(source: Path, destination: Path, stage1: v1.FileAudit) -> V2Audit:
|
||||
profile = v1.PROFILES[source.name]
|
||||
text_counts, inserted = _replace_configured_text(
|
||||
Path(stage1.output), destination, source.name, profile.scrub
|
||||
)
|
||||
replacements = dict(stage1.redactions)
|
||||
replacements.update(text_counts)
|
||||
synthetic = {key: list(values) for key, values in stage1.synthetic_values.items()}
|
||||
synthetic.update(inserted)
|
||||
missing = list(stage1.missing)
|
||||
if not text_counts["person_name"]:
|
||||
missing.append("person_name")
|
||||
if source.name in COMPANY_TITLE_TERMS and not text_counts["company_title"]:
|
||||
missing.append("company_title")
|
||||
return V2Audit(
|
||||
input=str(source), output=str(destination),
|
||||
status="warning" if missing else "ok", pages=stage1.pages,
|
||||
replacements=replacements, synthetic_values=synthetic, missing=missing,
|
||||
)
|
||||
|
||||
|
||||
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("inputs", nargs="*", type=Path, help="PDF files/directories; defaults to DDR templates")
|
||||
parser.add_argument("--output-dir", type=Path, default=Path("pseudonymized_v2"))
|
||||
parser.add_argument("--audit", type=Path, help="audit JSON path; defaults to OUTPUT_DIR/audit.json")
|
||||
parser.add_argument(
|
||||
"--logo-fill", choices=("black", "white"), default="white",
|
||||
help="color used to hide logos (default: white)",
|
||||
)
|
||||
parser.add_argument("--strict", action="store_true", help="fail instead of skipping unprofiled/scanned PDFs")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
args = parse_args(argv)
|
||||
try:
|
||||
inputs = args.inputs or [v1._default_input()]
|
||||
sources = v1._pdfs(inputs)
|
||||
except (FileNotFoundError, OSError) as exc:
|
||||
print(f"error: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
root = inputs[0] if len(inputs) == 1 and inputs[0].is_dir() else None
|
||||
logo_fill = (0.0, 0.0, 0.0) if args.logo_fill == "black" else (1.0, 1.0, 1.0)
|
||||
audits: list[V2Audit] = []
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="censor-pdf-v2-") as temporary:
|
||||
stage_root = Path(temporary)
|
||||
for source in sources:
|
||||
profile = (
|
||||
_profile_for_v2(source.name) if source.name in v1.PROFILES else None
|
||||
)
|
||||
people = PERSON_TERMS.get(source.name)
|
||||
if profile is None or people is None:
|
||||
status = "error" if args.strict else "skipped"
|
||||
audits.append(V2Audit(
|
||||
str(source), "", status,
|
||||
error="no v2 vector-template profile (scanned PDFs are intentionally excluded)",
|
||||
))
|
||||
continue
|
||||
|
||||
relative = source.relative_to(root) if root and source.is_relative_to(root) else Path(source.name)
|
||||
stage_path = stage_root / relative
|
||||
destination = args.output_dir / relative
|
||||
stage1 = v1.redact_pdf(source, stage_path, profile, logo_fill)
|
||||
if stage1.status == "error":
|
||||
audit = V2Audit(
|
||||
str(source), str(destination), "error", pages=stage1.pages,
|
||||
error="v1 stage failed: " + (stage1.error or "unknown error"),
|
||||
)
|
||||
else:
|
||||
try:
|
||||
audit = _build_audit(source, destination, stage1)
|
||||
except Exception as exc:
|
||||
audit = V2Audit(
|
||||
str(source), str(destination), "error", pages=stage1.pages,
|
||||
error=str(exc),
|
||||
)
|
||||
audits.append(audit)
|
||||
counts = ", ".join(f"{key}={value}" for key, value in audit.replacements.items())
|
||||
print(f"{audit.status:7} {source} -> {destination} ({counts})")
|
||||
|
||||
audit_path = args.audit or args.output_dir / "audit.json"
|
||||
audit_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
audit_path.write_text(json.dumps([asdict(item) for item in audits], indent=2), encoding="utf-8")
|
||||
errors = sum(item.status == "error" for item in audits)
|
||||
warnings = sum(item.status == "warning" for item in audits)
|
||||
skipped = sum(item.status == "skipped" for item in audits)
|
||||
print(f"\nAudit: {audit_path} | files={len(audits)} errors={errors} warnings={warnings} skipped={skipped}")
|
||||
return 1 if errors or (args.strict and skipped) else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
72
test_censor_pdfs_v2.py
Normal file
72
test_censor_pdfs_v2.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import pymupdf
|
||||
|
||||
from censor_pdfs_v2 import (
|
||||
_profile_for_v2,
|
||||
_replace_configured_text,
|
||||
_replace_people,
|
||||
fake_person_name,
|
||||
)
|
||||
|
||||
|
||||
class CensorPDFV2Tests(unittest.TestCase):
|
||||
def test_fake_name_is_stable_and_human_readable(self):
|
||||
first = fake_person_name("Example Person")
|
||||
self.assertEqual(first, fake_person_name("Example Person"))
|
||||
self.assertRegex(first, r"^[A-Z][a-z]+ [A-Z][a-z]+$")
|
||||
|
||||
def test_group_shape_is_preserved(self):
|
||||
replacement = fake_person_name("First Person / Second Person / Third Person")
|
||||
self.assertEqual(replacement.count(" / "), 2)
|
||||
|
||||
def test_person_name_is_removed_and_replaced(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / "source.pdf"
|
||||
output = Path(directory) / "output.pdf"
|
||||
document = pymupdf.open()
|
||||
page = document.new_page()
|
||||
page.insert_text((72, 72), "Supervisor: Tom Black")
|
||||
document.save(source)
|
||||
document.close()
|
||||
|
||||
# WellView's profile includes Tom Black and uses normal scrubbing.
|
||||
count, replacements = _replace_people(source, output, "WellView.pdf", True)
|
||||
self.assertEqual(count, 1)
|
||||
result = pymupdf.open(output)
|
||||
text = "".join(page.get_text() for page in result)
|
||||
result.close()
|
||||
self.assertNotIn("Tom Black", text)
|
||||
self.assertTrue(any(value in text for value in replacements))
|
||||
|
||||
def test_company_name_in_title_is_replaced(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / "source.pdf"
|
||||
output = Path(directory) / "output.pdf"
|
||||
document = pymupdf.open()
|
||||
page = document.new_page()
|
||||
page.insert_text((72, 72), "CLJOC DAILY REPORT")
|
||||
document.save(source)
|
||||
document.close()
|
||||
|
||||
counts, replacements = _replace_configured_text(
|
||||
source, output, "CuuLong.pdf", False, ("company_title",)
|
||||
)
|
||||
self.assertEqual(counts["company_title"], 1)
|
||||
self.assertEqual(replacements["company_title"], ["CLCORP"])
|
||||
result = pymupdf.open(output)
|
||||
text = "".join(page.get_text() for page in result)
|
||||
result.close()
|
||||
self.assertNotIn("CLJOC", text)
|
||||
self.assertIn("CLCORP", text)
|
||||
|
||||
def test_v2_profile_preserves_company_title_text(self):
|
||||
profile = _profile_for_v2("VIETSOPETRO_2.pdf")
|
||||
self.assertNotIn("logo", profile.terms)
|
||||
self.assertFalse(any(rule.category == "logo" for rule in profile.rectangles))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
256
visualize_synthetic_values.py
Normal file
256
visualize_synthetic_values.py
Normal file
@@ -0,0 +1,256 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Render pseudonymized PDF pages and box every searchable synthetic value."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import shutil
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
|
||||
import pymupdf
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
|
||||
CATEGORIES = {
|
||||
"person_name": {"label": "PERSON", "color": (216, 27, 96)},
|
||||
"company_title": {"label": "COMPANY", "color": (123, 31, 162)},
|
||||
"well_name": {"label": "WELL", "color": (21, 101, 192)},
|
||||
"rig_name": {"label": "RIG", "color": (245, 124, 0)},
|
||||
"coordinates": {"label": "COORD", "color": (46, 125, 50)},
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Match:
|
||||
category: str
|
||||
value: str
|
||||
rect_points: list[float]
|
||||
rect_pixels: list[int]
|
||||
|
||||
|
||||
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--audit", type=Path, default=Path("pseudonymized_v2/audit.json"),
|
||||
help="v2 audit JSON (default: pseudonymized_v2/audit.json)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pdf-root", type=Path, default=Path("pseudonymized_v2"),
|
||||
help="root used to preserve private/public paths",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output-dir", type=Path, default=Path("visualization"),
|
||||
help="visualization directory (default: visualization)",
|
||||
)
|
||||
parser.add_argument("--dpi", type=int, default=144, help="render resolution")
|
||||
parser.add_argument(
|
||||
"--include-empty-pages", action="store_true",
|
||||
help="also render pages on which no synthetic value was found",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-clean", action="store_true",
|
||||
help="do not clear the output directory before rendering",
|
||||
)
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def _font(size: int, bold: bool = False) -> ImageFont.ImageFont:
|
||||
candidates = (
|
||||
"DejaVuSans-Bold.ttf" if bold else "DejaVuSans.ttf",
|
||||
"/System/Library/Fonts/Supplemental/Arial Bold.ttf" if bold
|
||||
else "/System/Library/Fonts/Supplemental/Arial.ttf",
|
||||
)
|
||||
for candidate in candidates:
|
||||
try:
|
||||
return ImageFont.truetype(candidate, size)
|
||||
except OSError:
|
||||
pass
|
||||
return ImageFont.load_default()
|
||||
|
||||
|
||||
def _find_matches(
|
||||
page: pymupdf.Page, synthetic_values: dict[str, list[str]], scale: float
|
||||
) -> list[Match]:
|
||||
matches: list[Match] = []
|
||||
seen: set[tuple[str, int, int, int, int]] = set()
|
||||
for category in CATEGORIES:
|
||||
for value in synthetic_values.get(category, []):
|
||||
for rect in page.search_for(value):
|
||||
pixel_rect = [
|
||||
round(rect.x0 * scale), round(rect.y0 * scale),
|
||||
round(rect.x1 * scale), round(rect.y1 * scale),
|
||||
]
|
||||
key = (category, *pixel_rect)
|
||||
if key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
matches.append(Match(
|
||||
category=category,
|
||||
value=value,
|
||||
rect_points=[round(number, 3) for number in rect],
|
||||
rect_pixels=pixel_rect,
|
||||
))
|
||||
return matches
|
||||
|
||||
|
||||
def _draw_legend(
|
||||
draw: ImageDraw.ImageDraw, width: int, header_height: int,
|
||||
font: ImageFont.ImageFont,
|
||||
) -> None:
|
||||
draw.rectangle((0, 0, width, header_height), fill=(248, 249, 250))
|
||||
draw.line((0, header_height - 1, width, header_height - 1), fill=(180, 180, 180), width=1)
|
||||
x = 16
|
||||
box_size = max(12, header_height // 4)
|
||||
for spec in CATEGORIES.values():
|
||||
y = (header_height - box_size) // 2
|
||||
draw.rectangle((x, y, x + box_size, y + box_size), fill=spec["color"])
|
||||
x += box_size + 7
|
||||
draw.text((x, y - 1), spec["label"], fill=(30, 30, 30), font=font)
|
||||
text_box = draw.textbbox((x, y), spec["label"], font=font)
|
||||
x = text_box[2] + 22
|
||||
|
||||
|
||||
def _draw_match(
|
||||
draw: ImageDraw.ImageDraw, match: Match, header_height: int, line_width: int,
|
||||
) -> None:
|
||||
spec = CATEGORIES[match.category]
|
||||
color = spec["color"]
|
||||
x0, y0, x1, y1 = match.rect_pixels
|
||||
y0 += header_height
|
||||
y1 += header_height
|
||||
draw.rectangle((x0, y0, x1, y1), outline=color, width=line_width)
|
||||
|
||||
|
||||
def _render_page(
|
||||
page: pymupdf.Page, matches: list[Match], destination: Path, dpi: int
|
||||
) -> None:
|
||||
pixmap = page.get_pixmap(dpi=dpi, colorspace=pymupdf.csRGB, alpha=False)
|
||||
page_image = Image.frombytes("RGB", (pixmap.width, pixmap.height), pixmap.samples)
|
||||
scale = dpi / 72
|
||||
header_height = max(48, round(28 * scale))
|
||||
canvas = Image.new("RGB", (page_image.width, page_image.height + header_height), "white")
|
||||
canvas.paste(page_image, (0, header_height))
|
||||
draw = ImageDraw.Draw(canvas)
|
||||
legend_font = _font(max(11, round(7.5 * scale)), bold=True)
|
||||
_draw_legend(draw, canvas.width, header_height, legend_font)
|
||||
for match in matches:
|
||||
_draw_match(draw, match, header_height, max(3, round(1.5 * scale)))
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
canvas.save(destination, format="PNG", optimize=True)
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
args = parse_args(argv)
|
||||
if args.dpi < 72:
|
||||
raise SystemExit("--dpi must be at least 72")
|
||||
if not args.audit.is_file():
|
||||
raise SystemExit(f"audit file not found: {args.audit}")
|
||||
|
||||
if args.output_dir.exists() and not args.no_clean:
|
||||
shutil.rmtree(args.output_dir)
|
||||
args.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
audits = json.loads(args.audit.read_text(encoding="utf-8"))
|
||||
scale = args.dpi / 72
|
||||
images: list[dict[str, object]] = []
|
||||
category_counts = {category: 0 for category in CATEGORIES}
|
||||
pages_examined = 0
|
||||
pages_without_matches = 0
|
||||
|
||||
for audit in audits:
|
||||
if audit.get("status") != "ok":
|
||||
continue
|
||||
pdf_path = Path(audit["output"])
|
||||
if not pdf_path.is_file():
|
||||
raise SystemExit(f"output PDF not found: {pdf_path}")
|
||||
try:
|
||||
relative_pdf = pdf_path.relative_to(args.pdf_root)
|
||||
except ValueError:
|
||||
relative_pdf = Path(pdf_path.name)
|
||||
document = pymupdf.open(pdf_path)
|
||||
for page_index, page in enumerate(document):
|
||||
pages_examined += 1
|
||||
matches = _find_matches(page, audit["synthetic_values"], scale)
|
||||
if not matches:
|
||||
pages_without_matches += 1
|
||||
if not args.include_empty_pages:
|
||||
continue
|
||||
image_path = (
|
||||
args.output_dir / relative_pdf.parent / relative_pdf.stem
|
||||
/ f"page_{page_index + 1:03d}.png"
|
||||
)
|
||||
_render_page(page, matches, image_path, args.dpi)
|
||||
for match in matches:
|
||||
category_counts[match.category] += 1
|
||||
images.append({
|
||||
"image": str(image_path),
|
||||
"pdf": str(pdf_path),
|
||||
"page": page_index + 1,
|
||||
"width_points": round(page.rect.width, 3),
|
||||
"height_points": round(page.rect.height, 3),
|
||||
"matches": [asdict(match) for match in matches],
|
||||
})
|
||||
document.close()
|
||||
|
||||
manifest = {
|
||||
"audit": str(args.audit),
|
||||
"pdf_root": str(args.pdf_root),
|
||||
"dpi": args.dpi,
|
||||
"pages_examined": pages_examined,
|
||||
"pages_rendered": len(images),
|
||||
"pages_without_matches": pages_without_matches,
|
||||
"bounding_boxes": sum(category_counts.values()),
|
||||
"category_counts": category_counts,
|
||||
"images": images,
|
||||
}
|
||||
manifest_path = args.output_dir / "manifest.json"
|
||||
manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8")
|
||||
readme = f"""# Synthetic-value visualizations
|
||||
|
||||
This folder contains page images rendered from `{args.pdf_root}` at {args.dpi} DPI.
|
||||
Only pages containing at least one searchable synthetic value are included.
|
||||
|
||||
Color legend:
|
||||
|
||||
- Pink: person name (`person_name`)
|
||||
- Purple: company name in title (`company_title`)
|
||||
- Blue: well name (`well_name`)
|
||||
- Orange: rig name (`rig_name`)
|
||||
- Green: coordinates (`coordinates`)
|
||||
|
||||
Summary:
|
||||
|
||||
- PDF pages examined: {pages_examined}
|
||||
- Page images generated: {len(images)}
|
||||
- Bounding boxes: {manifest['bounding_boxes']}
|
||||
- Person-name boxes: {category_counts['person_name']}
|
||||
- Company-title boxes: {category_counts['company_title']}
|
||||
- Well-name boxes: {category_counts['well_name']}
|
||||
- Rig-name boxes: {category_counts['rig_name']}
|
||||
- Coordinate boxes: {category_counts['coordinates']}
|
||||
|
||||
`manifest.json` records each image, source PDF, one-based page number, synthetic value,
|
||||
category, PDF-space rectangle in points, and image-space rectangle in pixels.
|
||||
|
||||
Recreate this folder from the project root with:
|
||||
|
||||
```bash
|
||||
conda activate ai
|
||||
python visualize_synthetic_values.py
|
||||
```
|
||||
"""
|
||||
(args.output_dir / "README.md").write_text(readme, encoding="utf-8")
|
||||
print(
|
||||
f"Rendered {len(images)}/{pages_examined} pages with "
|
||||
f"{manifest['bounding_boxes']} boxes into {args.output_dir}"
|
||||
)
|
||||
print("Category counts:", ", ".join(f"{k}={v}" for k, v in category_counts.items()))
|
||||
print(f"Manifest: {manifest_path}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user