Files
HVideoTool/hvideotool/core/restore/factory.py
T

35 lines
1.3 KiB
Python

"""Restorer factory: build a Restorer from the app config.
- ``inpaint``: cv2 baseline (no weights, no GPU; fills, doesn't reconstruct).
- ``deepmosaics``: real generative mosaic removal via a user-installed DeepMosaics
(subprocess). Needs the DeepMosaics folder + clean weights + (ideally) a CUDA GPU.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from .base import Restorer
from .inpaint import InpaintRestorer
if TYPE_CHECKING: # avoid importing AppConfig at runtime here (not needed)
from ...config import AppConfig
def build_restorer(name: str = "inpaint", config: "AppConfig | None" = None) -> Restorer:
if name == "inpaint":
return InpaintRestorer()
if name == "deepmosaics":
from .deepmosaics import DeepMosaicsRestorer
if config is None:
raise ValueError("Для DeepMosaics нужны настройки (config).")
return DeepMosaicsRestorer(
config.dm_dir, config.dm_model, config.dm_python, config.dm_gpu
)
if name == "lada":
raise ValueError(
"Движок LADA пока не подключён. Используйте DeepMosaics или inpaint. См. README."
)
raise ValueError(f"Неизвестный режим восстановления: {name!r}")