Overview
Image-to-table modules for extracting tables from images as HTML.
LMBasedImageToTable(lm_request_processor)
Bases: BaseImageToTable, UsesLM
LM-based implementation for extracting a table from an image as HTML.
The image is sent as an attachment to a multimodal LM. An optional draft HTML table, such as the table returned by an OCR engine, is sent in the prompt so the model corrects it against the image.
Inherits
BaseImageToTable: Base class defining the image-to-table interface. UsesLM: Mixin providing shared logic for components using language models.
Attributes:
| Name | Type | Description |
|---|---|---|
lm_request_processor |
LMRequestProcessor
|
Handles prompt creation, LM invocation, and output parsing. |
Usage
Use from_preset to easily instantiate with predefined configuration:
from gllm_multimodal.modality_converter.image_to_text.image_to_table.lm_based_image_to_table import (
LMBasedImageToTable,
)
converter = LMBasedImageToTable.from_preset()
Initializes the LMBasedImageToTable instance with a language model request processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lm_request_processor
|
LMRequestProcessor
|
The processor handling prompt creation, LM invocation, and output parsing. |
required |
convert(source, **kwargs)
async
Extract the table in an image as HTML, optionally correcting a draft table.
Behavior
- Validates and loads image bytes from supported source formats.
- Fills the prompt with the draft table, using
not_givenwhen absent. - Sends the image as an attachment to the LM request processor.
- Extracts the
<table>...</table>element from the LM output. - Returns the HTML table wrapped in
TextResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | bytes
|
Image of the table. Supported forms: 1. Raw image bytes. 2. Local file path. 3. URL string. 4. Base64 encoded image string. |
required |
**kwargs
|
Any
|
See Other Parameters below. |
{}
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
draft_table |
str | None
|
Draft HTML table of the same image, such as an OCR result, to be corrected against the image. Defaults to None. |
event_emitter |
Any
|
Event emitter forwarded to LM request processing. |
hyperparameters |
dict[str, Any]
|
Hyperparameters forwarded to the LM invocation. |
Returns:
| Name | Type | Description |
|---|---|---|
TextResult |
TextResult
|
The HTML table, tagged |
Raises:
| Type | Description |
|---|---|
MediaInputInvalidError
|
If the source cannot be loaded, or |
MediaOperationFailedError
|
If the LM request fails with a non-GLLM error. |
MediaResultOperationError
|
If the LM output contains no HTML table. |
BaseError
|
Any GLLM error raised by the LM request is re-raised unchanged. |
Example
ocr = GLAIRVisionImageToOcr(..., include_detected_objects=True)
table_converter = LMBasedImageToTable.from_preset()
ocr_result = await ocr.convert("table.png")
draft = next(
obj.content for obj in ocr_result.metadata.detected_objects if obj.class_name == "table"
)
result = await table_converter.convert("table.png", draft_table=draft)
print(result.result) # "<table>...</table>"
from_preset(preset_name='default', lm_invoker_kwargs=None, prompt_builder_kwargs=None, **kwargs)
classmethod
Constructs an LMBasedImageToTable instance using a named preset configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset_name
|
str | None
|
Name of the predefined preset configuration to use. Defaults to "default". |
'default'
|
lm_invoker_kwargs
|
dict | None
|
Keyword arguments passed to LM invoker
creation in the preset factory. Defaults to None. Valid keys follow
[ |
None
|
prompt_builder_kwargs
|
dict | None
|
Keyword arguments passed to prompt
builder creation in the preset factory. Defaults to None. Valid keys follow
|
None
|
**kwargs
|
Any
|
Additional kwargs for current-class |
{}
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
**kwargs |
Any
|
Any additional kwargs forwarded to |
Returns:
| Name | Type | Description |
|---|---|---|
LMBasedImageToTable |
LMBasedImageToTable
|
An instance initialized with the preset's components. |
Raises:
| Type | Description |
|---|---|
ComponentConfigError
|
If the preset name, model settings, or credentials are invalid. |
BaseError
|
If an underlying gllm component raises a taxonomy error during preset construction. |
Example
from gllm_multimodal.modality_converter.image_to_text.image_to_table import LMBasedImageToTable
# Use default preset (DeepSeek through OpenRouter, needs OPENROUTER_API_KEY)
converter = LMBasedImageToTable.from_preset()
# Override model via lm_invoker_kwargs
converter = LMBasedImageToTable.from_preset(
lm_invoker_kwargs={"model_id": "google/gemini-3.1-flash-lite"},
)