initial commit
This commit is contained in:
153
python_server/config_loader.py
Normal file
153
python_server/config_loader.py
Normal file
@@ -0,0 +1,153 @@
|
||||
"""
|
||||
兼容层:从 Python 配置模块中构造 zoe_loader 需要的 ZoeConfig。
|
||||
|
||||
后端其它代码尽量只依赖这里的函数,而不直接依赖 config.py 的具体结构,
|
||||
便于以后扩展。
|
||||
"""
|
||||
|
||||
from model.Depth.zoe_loader import ZoeConfig
|
||||
from model.Depth.depth_anything_v2_loader import DepthAnythingV2Config
|
||||
from model.Depth.dpt_loader import DPTConfig
|
||||
from model.Depth.midas_loader import MiDaSConfig
|
||||
from config import AppConfig, DEFAULT_CONFIG
|
||||
|
||||
|
||||
def load_app_config() -> AppConfig:
|
||||
"""
|
||||
当前直接返回 DEFAULT_CONFIG。
|
||||
如未来需要支持多环境 / 覆盖配置,可以在这里加逻辑。
|
||||
"""
|
||||
return DEFAULT_CONFIG
|
||||
|
||||
|
||||
def build_zoe_config_from_app(app_cfg: AppConfig | None = None) -> ZoeConfig:
|
||||
"""
|
||||
将 AppConfig.depth 映射为 ZoeConfig,供 zoe_loader 使用。
|
||||
如果未显式传入 app_cfg,则使用全局 DEFAULT_CONFIG。
|
||||
"""
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
|
||||
return ZoeConfig(
|
||||
model=app_cfg.depth.zoe_model,
|
||||
device=app_cfg.depth.device,
|
||||
)
|
||||
|
||||
|
||||
def build_depth_anything_v2_config_from_app(
|
||||
app_cfg: AppConfig | None = None,
|
||||
) -> DepthAnythingV2Config:
|
||||
"""
|
||||
将 AppConfig.depth 映射为 DepthAnythingV2Config。
|
||||
"""
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
|
||||
return DepthAnythingV2Config(
|
||||
encoder=app_cfg.depth.da_v2_encoder,
|
||||
device=app_cfg.depth.device,
|
||||
)
|
||||
|
||||
|
||||
def build_dpt_config_from_app(app_cfg: AppConfig | None = None) -> DPTConfig:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return DPTConfig(
|
||||
model_type=app_cfg.depth.dpt_model_type,
|
||||
device=app_cfg.depth.device,
|
||||
)
|
||||
|
||||
|
||||
def build_midas_config_from_app(app_cfg: AppConfig | None = None) -> MiDaSConfig:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return MiDaSConfig(
|
||||
model_type=app_cfg.depth.midas_model_type,
|
||||
device=app_cfg.depth.device,
|
||||
)
|
||||
|
||||
|
||||
def get_depth_backend_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.depth.backend
|
||||
|
||||
|
||||
def get_inpaint_backend_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.inpaint.backend
|
||||
|
||||
|
||||
def get_sdxl_base_model_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.inpaint.sdxl_base_model
|
||||
|
||||
|
||||
def get_controlnet_base_model_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.inpaint.controlnet_base_model
|
||||
|
||||
|
||||
def get_controlnet_model_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.inpaint.controlnet_model
|
||||
|
||||
|
||||
def get_animation_backend_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.backend
|
||||
|
||||
|
||||
def get_animatediff_root_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.animate_diff_root
|
||||
|
||||
|
||||
def get_animatediff_pretrained_model_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.pretrained_model_path
|
||||
|
||||
|
||||
def get_animatediff_inference_config_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.inference_config
|
||||
|
||||
|
||||
def get_animatediff_motion_module_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.motion_module
|
||||
|
||||
|
||||
def get_animatediff_dreambooth_model_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.dreambooth_model
|
||||
|
||||
|
||||
def get_animatediff_lora_model_from_app(app_cfg: AppConfig | None = None) -> str:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.lora_model
|
||||
|
||||
|
||||
def get_animatediff_lora_alpha_from_app(app_cfg: AppConfig | None = None) -> float:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.lora_alpha
|
||||
|
||||
|
||||
def get_animatediff_without_xformers_from_app(app_cfg: AppConfig | None = None) -> bool:
|
||||
if app_cfg is None:
|
||||
app_cfg = load_app_config()
|
||||
return app_cfg.animation.without_xformers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user