This repository has been archived on 2026-10-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
imagelab_v3_extension/parameters.py
T

106 lines
3.6 KiB
Python

"""
Shared type definitions for workflows.
Keep all reusable parameter types here.
"""
from pydantic import BaseModel, Field
from typing import Annotated, List, Optional
# =============================================================================
# Annotated Types for UI Schema Generation
# =============================================================================
#
# Each type specifies:
# - component: The frontend UI component to render (optional, for custom UX)
# - category: Which tab/section to display the field in
# - options_source: For selections, where to get the options from
#
# If no component is specified, frontend uses generic components based on type.
# Text fields
Prompt = Annotated[str, Field(
json_schema_extra={"component": "prompt", "category": "prompts", "multiline": True, "rows": 4}
)]
NegativePrompt = Annotated[str, Field(
json_schema_extra={"component": "negative_prompt", "category": "prompts", "multiline": True, "rows": 2}
)]
# Special types
Seed = Annotated[int, Field(
json_schema_extra={"component": "seed", "category": "parameters"}
)]
# Enum types (selections from options_source)
Sampler = Annotated[str, Field(
json_schema_extra={"component": "sampler", "options_source": "samplers", "category": "parameters"}
)]
Scheduler = Annotated[str, Field(
json_schema_extra={"component": "scheduler", "options_source": "schedulers", "category": "parameters"}
)]
# Model selectors
Checkpoint = Annotated[List[str], Field(
json_schema_extra={"component": "checkpoints", "options_source": "checkpoints", "category": "models"}
)]
# Loras - uses Lora class defined below
# The actual type is defined after Lora class, see Loras below
# Dimension fields (uses Pydantic's built-in constraints)
# No component specified - frontend uses generic slider based on type + constraints
Width = Annotated[int, Field(
ge=64, le=2048, multiple_of=8,
json_schema_extra={"component": "dimensions", "category": "composition"}
)]
Height = Annotated[int, Field(
ge=64, le=2048, multiple_of=8,
json_schema_extra={"component": "dimensions", "category": "composition"}
)]
# =============================================================================
# Models with Parameters (for model_with_params type)
# =============================================================================
class LoopbackParameters(BaseModel):
iterations: int = 1
upscale: float = 1.0
denoise: float = 0.5
steps: int = 10
cfg: float = 7.0
class LoraParameters(BaseModel):
strength_model: float = 1.0
strength_clip: float = 1.0
class Lora(BaseModel):
apiName: str
disabled: bool = False
parameters: LoraParameters = LoraParameters()
class ControlnetParameters(BaseModel):
strength: float = 1.0
start_percent: float = 0.0
end_percent: float = 1.0
class Controlnet(BaseModel):
apiName: str
disabled: bool = False
parameters: ControlnetParameters = ControlnetParameters()
# =============================================================================
# Annotated List Types (for model_with_params with category)
# =============================================================================
# Loras - List of Lora models with parameters
Loras = Annotated[List[Lora], Field(
default=[],
json_schema_extra={"component": "loras", "options_source": "loras", "category": "models"}
)]
# Controlnets - List of Controlnet models with parameters
Controlnets = Annotated[List[Controlnet], Field(
default=[],
json_schema_extra={"component": "controlnets", "options_source": "controlnets", "category": "models"}
)]
# Add more shared types as needed