- Add MachineCodeParser for Swedish invoice payment line parsing - Fix OCR Reference extraction by normalizing account number spaces - Add cross-validation tests for pipeline and field_extractor - Update UI layout for compact upload and full-width results Key changes: - machine_code_parser.py: Handle spaces in Bankgiro numbers (e.g. "78 2 1 713") - pipeline.py: OCR and Amount override from payment_line, BG/PG comparison only - field_extractor.py: Improved invoice number normalization - app.py: Responsive UI layout changes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
"""
|
|
Web Application Configuration
|
|
|
|
Centralized configuration for the web application.
|
|
"""
|
|
|
|
from dataclasses import dataclass, field
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ModelConfig:
|
|
"""YOLO model configuration."""
|
|
|
|
model_path: Path = Path("runs/train/invoice_fields/weights/best.pt")
|
|
confidence_threshold: float = 0.5
|
|
use_gpu: bool = True
|
|
dpi: int = 150
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ServerConfig:
|
|
"""Server configuration."""
|
|
|
|
host: str = "0.0.0.0"
|
|
port: int = 8000
|
|
debug: bool = False
|
|
reload: bool = False
|
|
workers: int = 1
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class StorageConfig:
|
|
"""File storage configuration."""
|
|
|
|
upload_dir: Path = Path("uploads")
|
|
result_dir: Path = Path("results")
|
|
max_file_size_mb: int = 50
|
|
allowed_extensions: tuple[str, ...] = (".pdf", ".png", ".jpg", ".jpeg")
|
|
|
|
def __post_init__(self) -> None:
|
|
"""Create directories if they don't exist."""
|
|
object.__setattr__(self, "upload_dir", Path(self.upload_dir))
|
|
object.__setattr__(self, "result_dir", Path(self.result_dir))
|
|
self.upload_dir.mkdir(parents=True, exist_ok=True)
|
|
self.result_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
@dataclass
|
|
class AppConfig:
|
|
"""Main application configuration."""
|
|
|
|
model: ModelConfig = field(default_factory=ModelConfig)
|
|
server: ServerConfig = field(default_factory=ServerConfig)
|
|
storage: StorageConfig = field(default_factory=StorageConfig)
|
|
|
|
@classmethod
|
|
def from_dict(cls, config_dict: dict[str, Any]) -> "AppConfig":
|
|
"""Create config from dictionary."""
|
|
return cls(
|
|
model=ModelConfig(**config_dict.get("model", {})),
|
|
server=ServerConfig(**config_dict.get("server", {})),
|
|
storage=StorageConfig(**config_dict.get("storage", {})),
|
|
)
|
|
|
|
|
|
# Default configuration instance
|
|
default_config = AppConfig()
|