Skip to content

Commit 526af45

Browse files
authored
feat: add rotation detection parameter (#110)
Add to `ParseConfig` the `enable_rotation_detection: bool` parameter, to automatically detect if document pages are rotated or not. This also adds to the response `metadata` which pages were actually detected as rotate, and which rotation was detected.
1 parent 99ad1a5 commit 526af45

File tree

4 files changed

+164
-60
lines changed

4 files changed

+164
-60
lines changed

agentic_doc/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class DocumentMetadata(BaseModel):
134134
processing_time_ms: Optional[int] = None
135135
pages_processed: Optional[int] = None
136136
user_id: Optional[str] = None
137+
pages_rotation_angles: Optional[dict[str, float]] = Field(
138+
default_factory=dict, # type: ignore[arg-type]
139+
)
137140

138141

139142
class ParsedDocument(BaseModel, Generic[T]):

agentic_doc/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(
3333
extraction_schema: Optional[dict[str, Any]] = None,
3434
split_size: Optional[int] = None,
3535
extraction_split_size: Optional[int] = None,
36+
enable_rotation_detection: Optional[bool] = None,
3637
) -> None:
3738
self.api_key = api_key
3839
self.include_marginalia = include_marginalia
@@ -41,6 +42,7 @@ def __init__(
4142
self.extraction_schema = extraction_schema
4243
self.split_size = split_size
4344
self.extraction_split_size = extraction_split_size
45+
self.enable_rotation_detection = enable_rotation_detection
4446

4547

4648
class SettingsOverrides:

agentic_doc/parse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ def _send_parsing_request(
781781
"include_marginalia": include_marginalia,
782782
"include_metadata_in_markdown": include_metadata_in_markdown,
783783
}
784+
if config and config.enable_rotation_detection is not None:
785+
data["enable_rotation_detection"] = config.enable_rotation_detection
784786

785787
def resolve_refs(obj: Any, defs: Dict[str, Any]) -> Any:
786788
if isinstance(obj, dict):

0 commit comments

Comments
 (0)