Skip to content

Commit

Permalink
Copy prompt parameters from custom workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ronan36880 authored and Acly committed Nov 25, 2024
1 parent 04c7d08 commit e1c8d06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 16 additions & 5 deletions ai_diffusion/custom_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
5 changes: 4 additions & 1 deletion ai_diffusion/ui/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e1c8d06

Please sign in to comment.