Files
comfy-adapter/app/config.py
T

56 lines
2.0 KiB
Python

"""Environment settings and the parameter -> workflow node mapping."""
import json
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
REPO_ROOT = Path(__file__).resolve().parent.parent
CREATE_MODEL = "z-image-turbo"
EDIT_MODEL = "qwen-image-edit"
AVAILABLE_MODELS = [CREATE_MODEL, EDIT_MODEL]
# Node ids refer to workflow_create.json / workflow_edit.json.
# Override the whole map via MAPPING_FILE (JSON with "create" and "edit" keys).
DEFAULT_MAPPING: dict[str, dict[str, dict[str, str]]] = {
"create": {
"prompt": {"node": "83:27", "field": "text"},
"size": {"node": "83:13", "width_field": "width", "height_field": "height"},
"seed": {"node": "83:3", "field": "seed"},
},
"edit": {
"prompt": {"node": "115:111", "field": "prompt"},
"negative": {"node": "115:110", "field": "prompt"},
"seed": {"node": "115:3", "field": "seed"},
"image": {"node": "78", "field": "image"},
},
}
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
comfy_base_url: str = "http://192.168.0.3:8188"
adapter_api_key: str = ""
execution_timeout: float = 300.0
poll_interval: float = 1.5
create_template_path: Path = REPO_ROOT / "workflow_create.json"
edit_template_path: Path = REPO_ROOT / "workflow_edit.json"
mapping_file: Path | None = None
# Validate graphs on the ComfyUI server (POST /prompt?front=false) at startup.
validate_templates_on_server: bool = True
def mapping(self) -> dict[str, dict[str, dict[str, str]]]:
if self.mapping_file is None:
return DEFAULT_MAPPING
with open(self.mapping_file, encoding="utf-8") as f:
loaded = json.load(f)
merged = {k: dict(v) for k, v in DEFAULT_MAPPING.items()}
for section, section_map in loaded.items():
merged.setdefault(section, {}).update(section_map)
return merged
def get_settings() -> Settings:
return Settings()