"""Application configuration and tunable defaults. Plain dataclasses. Detection is YOLO-only and restoration is DeepMosaics-only, so the knobs here are the YOLO inference params, the overlay style, and the DeepMosaics weights. """ from __future__ import annotations from dataclasses import dataclass, field @dataclass(frozen=True) class DetectionConfig: """Parameters for the YOLO detector.""" yolo_conf: float = 0.2 # confidence threshold (LADA recommends ~0.2) yolo_imgsz: int = 640 # inference image size yolo_device: str | None = None # None => auto ("cuda" if available, else "cpu") @dataclass(frozen=True) class OverlayConfig: """How detections are drawn over the image.""" # RGB per detection category/label (the models/yolo/ folder name, or the # CensorType for legacy detections). Unknown categories get a stable palette colour. colors: dict[str, tuple[int, int, int]] = field( default_factory=lambda: { "mosaic": (231, 76, 60), # red "blur": (241, 196, 15), # yellow "black_bar": (26, 188, 156), # teal "unknown": (155, 89, 182), # purple "face": (46, 204, 113), # green "hand": (52, 152, 219), # blue "person": (230, 126, 34), # orange "eyes": (155, 89, 182), # purple "text": (149, 165, 166), # grey } ) # Fallback colours cycled (deterministically) for categories not listed above. palette: tuple[tuple[int, int, int], ...] = ( (231, 76, 60), (46, 204, 113), (52, 152, 219), (241, 196, 15), (155, 89, 182), (26, 188, 156), (230, 126, 34), (149, 165, 166), ) line_width: int = 2 fill_alpha: int = 48 # 0..255 translucency of the region fill show_labels: bool = True @dataclass class AppConfig: detection: DetectionConfig = field(default_factory=DetectionConfig) overlay: OverlayConfig = field(default_factory=OverlayConfig) detector: str = "yolo" # only "yolo" # Active YOLO models (paths under models/yolo//). A detect runs every # selected model and merges results — see core/detection/multi.MultiYoloDetector. detector_models: list[str] = field(default_factory=list) default_threshold: float = 0.20 # initial overlay confidence threshold # Per-model overlay threshold overrides, keyed by the model file **stem** (e.g. # "penis" -> 0.4). A detection from a model with no entry uses default_threshold. # Display-only (filters what's drawn/counted as a hit), not the detection conf. model_thresholds: dict[str, float] = field(default_factory=dict) # Merge overlapping detections across models (greedy IoU NMS, keep higher score). # Off by default — different categories are meant to coexist; on, it removes the # duplicate boxes you get when overlapping models (e.g. penis + cockAndBall) fire. cross_model_nms: bool = False nms_iou: float = 0.6 # IoU above which two boxes are deemed duplicates # --- restoration ("расцензурить") --- restorer: str = "deepmosaics" # "deepmosaics" | "deepmosaics_video" dm_dir: str | None = None # optional extra dir to search for mosaic_position.pth dm_model: str | None = None # DeepMosaics clean weights (clean_*.pth) dm_gpu: str = "0" # CUDA device id, "-1" for CPU # Temporal engine only: feed already-restored PAST frames into the BVDNet window # (instead of the original mosaic frames) for stronger temporal coherence. Slightly # out-of-distribution for the net (trained on mosaic windows) — toggle in the dialog. dm_feed_restored: bool = True # --- diffusion-inpaint restoration ("diffusion" restorer) --- # Regenerates the masked (detected) regions via an external diffusion server. Needs # YOLO detections for the mask; the model runs out-of-process (no torch dep here). # The backend is pluggable; only SwarmUI is wired so far. diff_backend: str = "swarmui" # only "swarmui" implemented diff_url: str = "http://localhost:7801" # SwarmUI server base URL diff_model: str | None = None # checkpoint name as the server knows it diff_prompt: str = "" diff_negative: str = "" diff_steps: int = 30 diff_cfg: float = 7.0 diff_denoise: float = 1.0 # 0..1, 1 = fully regenerate under the mask diff_seed: int = -1 # -1 = random each call diff_mask_dilate: int = 4 # px to grow the mask before inpaint diff_mask_blur: int = 8 # px feather of the mask edge