summaryrefslogtreecommitdiff
path: root/src/mcp_sd15/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mcp_sd15/config.py')
-rw-r--r--src/mcp_sd15/config.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mcp_sd15/config.py b/src/mcp_sd15/config.py
index df2da34..e41bdfd 100644
--- a/src/mcp_sd15/config.py
+++ b/src/mcp_sd15/config.py
@@ -80,12 +80,19 @@ class ServerConfig:
@dataclass(frozen=True)
+class PromptConfig:
+ positive: str = ""
+ negative: str = ""
+
+
+@dataclass(frozen=True)
class AppConfig:
model: ModelConfig
generation: GenerationConfig
controlnet: ControlNetConfig
output: OutputConfig
server: ServerConfig = ServerConfig()
+ prompt: PromptConfig = PromptConfig()
def controlnet_path(self, mode: str) -> Path:
item = self.controlnet.for_mode(mode)
@@ -121,6 +128,13 @@ def _filename(value: str | None, label: str) -> str | None:
return value
+def _read_prompt(path: Path) -> str:
+ try:
+ return path.read_text(encoding="utf-8").strip()
+ except OSError as exc:
+ raise ConfigError(f"cannot read prompt file {path}: {exc}") from exc
+
+
def _bool(table: dict[str, Any], key: str, default: bool) -> bool:
value = table.get(key, default)
if not isinstance(value, bool):
@@ -230,12 +244,25 @@ def load_config(path: str | Path, *, validate_paths: bool = True) -> AppConfig:
):
raise ConfigError("server.port must be an integer between 1 and 65535")
+ prompt_raw = _table(raw, "prompt")
+ positive_file = _filename(_string(prompt_raw, "positive_file"), "prompt.positive_file")
+ negative_file = _filename(_string(prompt_raw, "negative_file"), "prompt.negative_file")
+ prompt_positive = ""
+ prompt_negative = ""
+ if positive_file:
+ positive_path = root / "prompts" / positive_file
+ prompt_positive = _read_prompt(positive_path)
+ if negative_file:
+ negative_path = root / "prompts" / negative_file
+ prompt_negative = _read_prompt(negative_path)
+
config = AppConfig(
model=ModelConfig(root, checkpoint, vae, tuple(loras)),
generation=GenerationConfig(steps_value, cfg_scale, scheduler, default_size),
controlnet=controlnet,
output=OutputConfig(output_dir.resolve(), _bool(output_raw, "enabled", False)),
server=ServerConfig(transport, host, port_value),
+ prompt=PromptConfig(prompt_positive, prompt_negative),
)
if validate_paths:
validate_model_paths(config)