File size: 978 Bytes
32c5da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from typing import Callable, Protocol


class ProviderUnavailableError(RuntimeError):
    pass


@dataclass(slots=True)
class ProviderRequest:
    prompt: str
    negative_prompt: str
    count: int
    width: int
    height: int
    seed: int
    steps: int
    guidance: float
    init_image_path: str | None = None
    img2img_strength: float = 0.45
    model_variant: str | None = None


@dataclass(slots=True)
class ProviderResult:
    image_paths: list[Path]


ProgressCallback = Callable[[int, str], None]
CancelCallback = Callable[[], bool]


class IImageProvider(Protocol):
    id: str
    name: str
    description: str

    def is_available(self) -> bool:
        ...

    def generate(
        self,
        request: ProviderRequest,
        output_dir: Path,
        progress: ProgressCallback,
        is_cancelled: CancelCallback,
    ) -> ProviderResult:
        ...