You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
from dataclasses import dataclass, asdict
|
|
|
|
|
|
@dataclass
|
|
class GenerationOptions:
|
|
"""Input options for image generation."""
|
|
prompt: str
|
|
negative_prompt: str = ""
|
|
seed: int | None = None
|
|
steps: int = 20
|
|
guidance_scale: float = 7.5
|
|
count: int = 1
|
|
add_quality_keywords: bool = True
|
|
increment_seed: bool = True
|
|
vary_guidance: bool = False
|
|
guidance_low: float = 5.0
|
|
guidance_high: float = 12.0
|
|
vary_steps: bool = False
|
|
steps_low: int = 20
|
|
steps_high: int = 80
|
|
width: int | None = None
|
|
height: int | None = None
|
|
|
|
|
|
@dataclass
|
|
class ImageParams:
|
|
"""Computed parameters for a single image generation."""
|
|
seed: int
|
|
steps: int
|
|
guidance_scale: float
|
|
|
|
|
|
@dataclass
|
|
class ImageMetadata:
|
|
"""Metadata saved alongside each generated image."""
|
|
prompt: str
|
|
negative_prompt: str
|
|
seed: int
|
|
steps: int
|
|
guidance_scale: float
|
|
width: int
|
|
height: int
|
|
add_quality_keywords: bool
|
|
full_prompt: str = ""
|
|
|
|
def to_dict(self) -> dict:
|
|
return asdict(self)
|
|
|
|
|
|
@dataclass
|
|
class ImageResult:
|
|
"""Result returned for each generated image via SSE."""
|
|
index: int
|
|
total: int
|
|
filename: str
|
|
url: str
|
|
base64: str
|
|
metadata: ImageMetadata
|
|
|
|
def to_dict(self) -> dict:
|
|
"""Flatten metadata into the result dict for JSON serialization."""
|
|
result = asdict(self)
|
|
metadata = result.pop("metadata")
|
|
result.update(metadata)
|
|
return result
|
|
|