Utils¶
MinerU VL utilities for document extraction.
Contains data structures, parsing, prompts, and post-processing functions for MinerU VL document extraction pipeline.
This file contains code adapted from mineru-vl-utils
https://github.com/opendatalab/mineru-vl-utils https://pypi.org/project/mineru-vl-utils/
The original mineru-vl-utils is licensed under AGPL-3.0: Copyright (c) OpenDataLab https://github.com/opendatalab/mineru-vl-utils/blob/main/LICENSE.md
Adapted components
- BlockType enum (from structs.py)
- ContentBlock data structure (from structs.py)
- OTSL to HTML table conversion (from post_process/otsl2html.py)
BlockType
¶
Bases: str, Enum
MinerU VL block types (22 categories).
ContentBlock
¶
Bases: BaseModel
A detected content block with type, bounding box, angle, and content.
Coordinates are normalized to [0, 1] range relative to image dimensions.
to_absolute
¶
Convert normalized bbox to absolute pixel coordinates.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
SamplingParams
dataclass
¶
SamplingParams(
temperature: Optional[float] = None,
top_p: Optional[float] = None,
top_k: Optional[int] = None,
presence_penalty: Optional[float] = None,
frequency_penalty: Optional[float] = None,
repetition_penalty: Optional[float] = None,
no_repeat_ngram_size: Optional[int] = None,
max_new_tokens: Optional[int] = None,
)
Sampling parameters for text generation.
MinerUSamplingParams
¶
MinerUSamplingParams(
temperature: Optional[float] = 0.0,
top_p: Optional[float] = 0.01,
top_k: Optional[int] = 1,
presence_penalty: Optional[float] = 0.0,
frequency_penalty: Optional[float] = 0.0,
repetition_penalty: Optional[float] = 1.0,
no_repeat_ngram_size: Optional[int] = 100,
max_new_tokens: Optional[int] = None,
)
Bases: SamplingParams
Default sampling parameters optimized for MinerU VL.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
convert_bbox
¶
Convert bbox from model output (0-1000) to normalized format (0-1).
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
parse_angle
¶
Parse rotation angle from model output tail string.
parse_layout_output
¶
Parse layout detection model output into ContentBlocks.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
get_rgb_image
¶
Convert image to RGB mode.
prepare_for_layout
¶
prepare_for_layout(
image: Image,
layout_size: Tuple[int, int] = LAYOUT_IMAGE_SIZE,
) -> Image.Image
Prepare image for layout detection.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
resize_by_need
¶
Resize image if needed based on aspect ratio constraints.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
prepare_for_extract
¶
prepare_for_extract(
image: Image,
blocks: List[ContentBlock],
prompts: Dict[str, str] = None,
sampling_params: Dict[str, SamplingParams] = None,
skip_types: set = None,
) -> Tuple[
List[Image.Image],
List[str],
List[SamplingParams],
List[int],
]
Prepare cropped images for content extraction.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
convert_otsl_to_html
¶
Convert OTSL table format to HTML.
Source code in omnidocs/tasks/text_extraction/mineruvl/utils.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
simple_post_process
¶
Simple post-processing: convert OTSL tables to HTML.