diff --git a/ai_diffusion/custom_workflow.py b/ai_diffusion/custom_workflow.py index 271ebad3f..afa38fa81 100644 --- a/ai_diffusion/custom_workflow.py +++ b/ai_diffusion/custom_workflow.py @@ -565,13 +565,24 @@ def live_result(self): assert self._last_result and self._last_job, "No live result available" return self._last_result, self._last_job + def try_set_params(self, params: dict): + self.params = _coerce_with_fallback(params, self.params, self.metadata) + self.graph_changed.emit() + def _coerce(params: dict[str, Any], types: list[CustomParam]): - def use(value, default): + return _coerce_with_fallback(params, {}, types) + + +def _coerce_with_fallback( + params: dict[str, Any], fallback: dict[str, Any], types: list[CustomParam] +): + def use(value, fallback, default): + value_or_fallback = value if value is not None else fallback if default is None: - return value - if value is None or not base_type_match(value, default): + return value_or_fallback + if value_or_fallback is None or not base_type_match(value, default): return default - return value + return value_or_fallback - return {t.name: use(params.get(t.name), t.default) for t in types} + return {t.name: use(params.get(t.name), fallback.get(t.name), t.default) for t in types} diff --git a/ai_diffusion/ui/generation.py b/ai_diffusion/ui/generation.py index ee0df1eb2..59b087c4d 100644 --- a/ai_diffusion/ui/generation.py +++ b/ai_diffusion/ui/generation.py @@ -9,7 +9,7 @@ from ..properties import Binding, Bind, bind, bind_combo, bind_toggle from ..image import Bounds, Extent, Image from ..jobs import Job, JobQueue, JobState, JobKind, JobParams -from ..model import Model, InpaintContext, RootRegion, ProgressKind +from ..model import Model, InpaintContext, RootRegion, ProgressKind, Workspace from ..style import Styles from ..root import root from ..workflow import InpaintMode, FillMode @@ -374,6 +374,9 @@ def _copy_prompt(self): if isinstance(active, RootRegion): active.negative = job.params.metadata.get("negative_prompt", "") + if self._model.workspace is Workspace.custom and self._model.document.is_active: + self._model.custom.try_set_params(job.params.metadata) + def _copy_strength(self): if job := self.selected_job: self._model.strength = job.params.strength