fix: make default table_mode configurable via DEFAULT_TABLE_MODE (H1)

TableFormerMode.ACCURATE is very expensive on CPU (~3-5x slower).
The default can now be set to "fast" on resource-constrained
environments (HF Spaces) via the DEFAULT_TABLE_MODE env var.

User-specified table_mode in the request still takes precedence.

Ref #57 (H1)
This commit is contained in:
Pier-Jean Malandrino 2026-04-07 14:40:11 +02:00
parent 6327b13614
commit f58b563a13
2 changed files with 7 additions and 1 deletions

View file

@ -16,6 +16,7 @@ class Settings:
conversion_timeout: int = 900
document_timeout: float = 120.0 # Docling-level per-document timeout (seconds)
max_concurrent_analyses: int = 3
default_table_mode: str = "accurate" # "accurate" or "fast"
max_page_count: int = 0 # 0 = unlimited (upload validation)
max_file_size: int = 0 # 0 = unlimited (Docling-level, bytes)
upload_dir: str = "./uploads"
@ -37,6 +38,7 @@ class Settings:
conversion_timeout=int(os.environ.get("CONVERSION_TIMEOUT", "900")),
document_timeout=float(os.environ.get("DOCUMENT_TIMEOUT", "120.0")),
max_concurrent_analyses=int(os.environ.get("MAX_CONCURRENT_ANALYSES", "3")),
default_table_mode=os.environ.get("DEFAULT_TABLE_MODE", "accurate"),
max_page_count=int(os.environ.get("MAX_PAGE_COUNT", "0")),
max_file_size=int(os.environ.get("MAX_FILE_SIZE", "0")),
upload_dir=os.environ.get("UPLOAD_DIR", "./uploads"),

View file

@ -15,6 +15,7 @@ from typing import TYPE_CHECKING
from domain.models import AnalysisJob, AnalysisStatus
from domain.value_objects import ChunkingOptions, ChunkResult, ConversionOptions, ConversionResult
from infra.settings import settings
if TYPE_CHECKING:
from domain.ports import DocumentChunker, DocumentConverter
@ -151,7 +152,10 @@ class AnalysisService:
await analysis_repo.update_status(job)
logger.info("Analysis started: %s (file: %s)", job_id, filename)
options = ConversionOptions(**(pipeline_options or {}))
opts_dict = pipeline_options or {}
if "table_mode" not in opts_dict:
opts_dict = {**opts_dict, "table_mode": settings.default_table_mode}
options = ConversionOptions(**opts_dict)
result: ConversionResult = await asyncio.wait_for(
self._converter.convert(file_path, options),