feat: use shared.state

This commit is contained in:
Bingsu
2023-05-26 11:51:46 +09:00
parent 89b018dc33
commit 8ddb7dd7b7
2 changed files with 30 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ from sd_webui.processing import (
create_infotext, create_infotext,
process_images, process_images,
) )
from sd_webui.shared import cmd_opts, opts from sd_webui.shared import cmd_opts, opts, state
try: try:
from rich import print from rich import print
@@ -451,6 +451,9 @@ class AfterDetailerScript(scripts.Script):
`True` if image was processed, `False` otherwise. `True` if image was processed, `False` otherwise.
""" """
if state.interrupted:
return False
i = p._idx i = p._idx
i2i = self.get_i2i_p(p, args, pp.image) i2i = self.get_i2i_p(p, args, pp.image)
@@ -488,6 +491,7 @@ class AfterDetailerScript(scripts.Script):
steps = len(masks) steps = len(masks)
processed = None processed = None
state.job_count += steps
if is_mediapipe: if is_mediapipe:
print(f"mediapipe: {steps} detected.") print(f"mediapipe: {steps} detected.")

View File

@@ -7,6 +7,29 @@ if TYPE_CHECKING:
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Callable from typing import Any, Callable
import torch
from PIL import Image
@dataclass
class State:
skipped: bool = False
interrupted: bool = False
job: str = ""
job_no: int = 0
job_count: int = 0
processing_has_refined_job_count: bool = False
job_timestamp: str = "0"
sampling_step: int = 0
sampling_steps: int = 0
current_latent: torch.Tensor | None = None
current_image: Image.Image | None = None
current_image_sampling_step: int = 0
id_live_preview: int = 0
textinfo: str | None = None
time_start: float | None = None
need_restart: bool = False
server_start: float | None = None
@dataclass @dataclass
class OptionInfo: class OptionInfo:
default: Any = None default: Any = None
@@ -37,6 +60,7 @@ if TYPE_CHECKING:
opts = Option() opts = Option()
cmd_opts = argparse.Namespace() cmd_opts = argparse.Namespace()
state = State()
else: else:
from modules.shared import OptionInfo, cmd_opts, opts from modules.shared import OptionInfo, cmd_opts, opts, state