File size: 1,979 Bytes
34097e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from abc import ABC, abstractmethod
    from dataclasses import dataclass
    from typing import Any

    import gradio as gr
    from PIL import Image

    from sd_webui.processing import (
        Processed,
        StableDiffusionProcessingImg2Img,
        StableDiffusionProcessingTxt2Img,
    )

    SDPType = StableDiffusionProcessingImg2Img | StableDiffusionProcessingTxt2Img
    AlwaysVisible = object()

    @dataclass
    class PostprocessImageArgs:
        image: Image.Image

    class Script(ABC):
        filename: str
        args_from: int
        args_to: int
        alwayson: bool

        is_txt2img: bool
        is_img2img: bool

        group: gr.Group
        infotext_fields: list[tuple[str, str]]
        paste_field_names: list[str]

        @abstractmethod
        def title(self):
            raise NotImplementedError

        def ui(self, is_img2img: bool):
            pass

        def show(self, is_img2img: bool):
            return True

        def run(self, p: SDPType, *args):
            pass

        def process(self, p: SDPType, *args):
            pass

        def before_process_batch(self, p: SDPType, *args, **kwargs):
            pass

        def process_batch(self, p: SDPType, *args, **kwargs):
            pass

        def postprocess_batch(self, p: SDPType, *args, **kwargs):
            pass

        def postprocess_image(self, p: SDPType, pp: PostprocessImageArgs, *args):
            pass

        def postprocess(self, p: SDPType, processed: Processed, *args):
            pass

        def before_component(self, component, **kwargs):
            pass

        def after_component(self, component, **kwargs):
            pass

        def describe(self):
            return ""

        def elem_id(self, item_id: Any) -> str:
            pass

else:
    from modules.scripts import AlwaysVisible, PostprocessImageArgs, Script