-
Notifications
You must be signed in to change notification settings - Fork 6
/
_typing.py
58 lines (49 loc) · 1.31 KB
/
_typing.py
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
import json
from typing import NamedTuple, Any
class ImageMeta(NamedTuple):
size: str
seed: int
steps: int
sampler: str
prompt: str
negative_prompt: str
cfg_scale: float
model: str
model_hash: str
def to_dict(self) -> dict[str, Any]:
return {
"size": self.size,
"seed": self.seed,
"steps": self.steps,
"prompt": self.prompt,
"negative_prompt": self.negative_prompt,
"sampler": self.sampler,
"cfg_scale": self.cfg_scale,
"model": self.model,
"model_hash": self.model_hash,
}
class ModelImage(NamedTuple):
"""用户上传图片"""
id: int
url: str
nsfw: bool
width: int
height: int
meta: ImageMeta
def to_dict(self) -> dict[str, Any]:
return {
"id": self.id,
"url": self.url,
"nsfw": self.nsfw,
"width": self.width,
"height": self.height,
"meta": self.meta.to_dict()
}
def __str__(self) -> str:
return json.dumps(self.to_dict())
def __repr__(self) -> str:
return self.__str__()
def __eq__(self, other: object) -> bool:
if not isinstance(other, ModelImage):
return False
return self.id == other.id