-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow backends to report fixable errors
- Loading branch information
1 parent
e8113d0
commit c8ef88a
Showing
14 changed files
with
320 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from typing import Callable, Any | ||
from .generation_arguments import GenerationArguments | ||
from dataclasses import dataclass | ||
|
||
class FixItError(Exception): | ||
"""An exception with a solution. | ||
Call the `draw` method to render the UI elements responsible for resolving this error. | ||
""" | ||
def __init__(self, message, solution: 'Solution'): | ||
super().__init__(message) | ||
|
||
self._solution = solution | ||
|
||
def _draw(self, dream_prompt, context, layout): | ||
self._solution._draw(dream_prompt, context, layout) | ||
|
||
@dataclass | ||
class Solution: | ||
def _draw(self, dream_prompt, context, layout): | ||
... | ||
|
||
@dataclass | ||
class ChangeProperty(Solution): | ||
"""Prompts the user to change the given `property` of the `GenerationArguments`.""" | ||
property: str | ||
|
||
def _draw(self, dream_prompt, context, layout): | ||
layout.prop(dream_prompt, self.property) | ||
|
||
@dataclass | ||
class RunOperator(Solution): | ||
"""Runs the given operator""" | ||
title: str | ||
operator: str | ||
modify_operator: Callable[[Any], None] | ||
|
||
def _draw(self, dream_prompt, context, layout): | ||
self.modify_operator( | ||
layout.operator(self.operator, text=self.title) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from dataclasses import dataclass | ||
from typing import Tuple, List | ||
from ..models.task import Task | ||
from ..models.model import Model | ||
from ..models.prompt import Prompt | ||
from ..models.seamless_axes import SeamlessAxes | ||
from ..models.step_preview_mode import StepPreviewMode | ||
|
||
@dataclass | ||
class GenerationArguments: | ||
task: Task | ||
"""The type of generation to perform. | ||
Use a match statement to perform different actions based on the selected task. | ||
```python | ||
match task: | ||
case PromptToImage(): | ||
... | ||
case ImageToImage(image=image, strength=strength, fit=fit): | ||
... | ||
case Inpaint(image=image, fit=fit, strength=strength, mask_source=mask_source, mask_prompt=mask_prompt, confidence=confidence): | ||
... | ||
case DepthToImage(depth=depth, image=image, strength=strength): | ||
... | ||
case Outpaint(image=image, origin=origin): | ||
... | ||
case _: | ||
raise NotImplementedError() | ||
``` | ||
""" | ||
|
||
model: Model | ||
"""The selected model. | ||
This is one of the options provided by `Backend.list_models`. | ||
""" | ||
|
||
prompt: Prompt | ||
"""The positive and (optionally) negative prompt. | ||
If `prompt.negative` is `None`, then the 'Negative Prompt' panel was disabled by the user. | ||
""" | ||
|
||
size: Tuple[int, int] | None | ||
"""The target size of the image, or `None` to use the native size of the model.""" | ||
|
||
seed: int | ||
"""The random or user-provided seed to use.""" | ||
|
||
steps: int | ||
"""The number of inference steps to perform.""" | ||
|
||
guidance_scale: float | ||
"""The selected classifier-free guidance scale.""" | ||
|
||
scheduler: str | ||
"""The selected scheduler. | ||
This is one of the options provided by `Backend.list_schedulers`. | ||
""" | ||
|
||
seamless_axes: SeamlessAxes | ||
"""Which axes to tile seamlessly.""" | ||
|
||
step_preview_mode: StepPreviewMode | ||
"""The style of preview to display at each step.""" | ||
|
||
iterations: int | ||
"""The number of images to generate. | ||
The value sent to `callback` should contain the same number of `GenerationResult` instances in a list. | ||
""" | ||
|
||
@staticmethod | ||
def _map_property_name(name: str) -> str | List[str] | None: | ||
"""Converts a property name from `GenerationArguments` to the corresponding property of a `DreamPrompt`.""" | ||
match name: | ||
case "model": | ||
return "model" | ||
case "prompt": | ||
return ["prompt", "use_negative_prompt", "negative_prompt"] | ||
case "prompt.positive": | ||
return "prompt" | ||
case "prompt.negative": | ||
return ["use_negative_prompt", "negative_prompt"] | ||
case "size": | ||
return ["use_size", "width", "height"] | ||
case "seed": | ||
return "seed" | ||
case "steps": | ||
return "steps" | ||
case "guidance_scale": | ||
return "cfg_scale" | ||
case "scheduler": | ||
return "scheduler" | ||
case "seamless_axes": | ||
return "seamless_axes" | ||
case "step_preview_mode": | ||
return "step_preview_mode" | ||
case "iterations": | ||
return "iterations" | ||
case _: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.