-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectable_document_reader.py
More file actions
79 lines (68 loc) · 2.79 KB
/
Copy pathselectable_document_reader.py
File metadata and controls
79 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Run registration review with a native, Docling, or hash-bound manifest reader."""
from __future__ import annotations
import argparse
import json
import sys
import uuid
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
if str(SRC) not in sys.path:
sys.path.insert(0, str(SRC))
from axcalib import AXCalib # noqa: E402
from axcalib.ingest import HashBoundManifestDocumentReader # noqa: E402
DEFAULT_PPTX = ROOT / "tests" / "sources" / "oled_qc_project_outline.pptx"
DEFAULT_SIDECAR = ROOT / "tests" / "sources" / "oled_qc_project_outline.axcalib.json"
def main() -> int:
"""Select one reader, then stop at the mandatory registration human gate."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--workspace", type=Path, required=True)
parser.add_argument("--proposal", type=Path, default=DEFAULT_PPTX)
parser.add_argument("--sidecar", type=Path, default=DEFAULT_SIDECAR)
parser.add_argument("--reader", choices=("native", "docling", "manifest"), default="native")
parser.add_argument("--reader-manifest", type=Path, action="append", default=[])
parser.add_argument("--allow-external-reader", action="store_true")
parser.add_argument("--project-id", default=f"reader-{uuid.uuid4()}")
args = parser.parse_args()
selection: str | HashBoundManifestDocumentReader
if args.reader == "manifest":
if not args.reader_manifest:
parser.error("--reader manifest requires at least one --reader-manifest")
selection = HashBoundManifestDocumentReader(args.reader_manifest)
else:
selection = args.reader
ax = AXCalib(
args.workspace,
document_reader=selection,
allow_external_document_reader=args.allow_external_reader,
)
case = ax.register_case(
args.proposal,
title="선택형 문서 리더 등록심의 예제",
sidecar_path=args.sidecar,
project_id=args.project_id,
)
ax.submit_registration(case.project_id)
result = ax.evaluate(case.project_id, "registration")
print(
json.dumps(
{
"project_id": case.project_id,
"reader": (
selection.reader_id
if isinstance(selection, HashBoundManifestDocumentReader)
else selection
),
"status": result.dossier_status.value,
"report_id": result.report_id,
"allowed_commands": list(result.allowed_commands),
"human_boundary": "관리자가 보고서를 검토한 뒤 approve/reject해야 합니다.",
},
ensure_ascii=False,
indent=2,
sort_keys=True,
)
)
return 0
if __name__ == "__main__":
raise SystemExit(main())