IOPaint/iopaint/plugins/__init__.py

74 lines
2.3 KiB
Python
Raw Normal View History

from typing import Dict
2023-12-25 04:31:49 +01:00
from loguru import logger
from .anime_seg import AnimeSeg
from .gfpgan_plugin import GFPGANPlugin
2023-04-06 15:55:20 +02:00
from .interactive_seg import InteractiveSeg
2023-03-25 02:53:22 +01:00
from .realesrgan import RealESRGANUpscaler
from .remove_bg import RemoveBG
2023-03-30 10:07:38 +02:00
from .restoreformer import RestoreFormerPlugin
2023-12-28 03:48:52 +01:00
from ..const import InteractiveSegModel, Device, RealESRGANModel
2023-12-25 04:31:49 +01:00
def build_plugins(
enable_interactive_seg: bool,
interactive_seg_model: InteractiveSegModel,
interactive_seg_device: Device,
enable_remove_bg: bool,
enable_anime_seg: bool,
enable_realesrgan: bool,
realesrgan_device: Device,
2023-12-28 03:48:52 +01:00
realesrgan_model: RealESRGANModel,
2023-12-25 04:31:49 +01:00
enable_gfpgan: bool,
gfpgan_device: Device,
enable_restoreformer: bool,
restoreformer_device: Device,
no_half: bool,
) -> Dict:
2023-12-30 16:36:44 +01:00
plugins = {}
2023-12-25 04:31:49 +01:00
if enable_interactive_seg:
logger.info(f"Initialize {InteractiveSeg.name} plugin")
2023-12-30 16:36:44 +01:00
plugins[InteractiveSeg.name] = InteractiveSeg(
2023-12-25 04:31:49 +01:00
interactive_seg_model, interactive_seg_device
)
if enable_remove_bg:
logger.info(f"Initialize {RemoveBG.name} plugin")
2023-12-30 16:36:44 +01:00
plugins[RemoveBG.name] = RemoveBG()
2023-12-25 04:31:49 +01:00
if enable_anime_seg:
logger.info(f"Initialize {AnimeSeg.name} plugin")
2023-12-30 16:36:44 +01:00
plugins[AnimeSeg.name] = AnimeSeg()
2023-12-25 04:31:49 +01:00
if enable_realesrgan:
logger.info(
f"Initialize {RealESRGANUpscaler.name} plugin: {realesrgan_model}, {realesrgan_device}"
)
2023-12-30 16:36:44 +01:00
plugins[RealESRGANUpscaler.name] = RealESRGANUpscaler(
2023-12-25 04:31:49 +01:00
realesrgan_model,
realesrgan_device,
no_half=no_half,
)
if enable_gfpgan:
logger.info(f"Initialize {GFPGANPlugin.name} plugin")
if enable_realesrgan:
logger.info("Use realesrgan as GFPGAN background upscaler")
else:
logger.info(
f"GFPGAN no background upscaler, use --enable-realesrgan to enable it"
)
2023-12-30 16:36:44 +01:00
plugins[GFPGANPlugin.name] = GFPGANPlugin(
2023-12-25 04:31:49 +01:00
gfpgan_device,
2023-12-30 16:36:44 +01:00
upscaler=plugins.get(RealESRGANUpscaler.name, None),
2023-12-25 04:31:49 +01:00
)
if enable_restoreformer:
logger.info(f"Initialize {RestoreFormerPlugin.name} plugin")
2023-12-30 16:36:44 +01:00
plugins[RestoreFormerPlugin.name] = RestoreFormerPlugin(
2023-12-25 04:31:49 +01:00
restoreformer_device,
2023-12-30 16:36:44 +01:00
upscaler=plugins.get(RealESRGANUpscaler.name, None),
2023-12-25 04:31:49 +01:00
)
2023-12-30 16:36:44 +01:00
return plugins