Archived
completed phase 2, updated workflows to use yaml and updated workflows scripts to use new system for parameters
This commit is contained in:
1 parent
193e03ce3a
commit
4f8ba22cd2
4 files changed
+209
-438
No files matched your search
+135
-9
@@ -2,12 +2,22 @@
|
||||
Workflow registry for external API.
|
||||
Auto-discovers workflow files from the workflows/ folder.
|
||||
Supports hot reloading - workflows are reloaded from disk on each execution.
|
||||
|
||||
Schema is loaded from YAML files (auto-generated from WorkflowParams).
|
||||
"""
|
||||
import os
|
||||
import glob
|
||||
import importlib.util
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
from typing import Callable, Dict, List, Optional
|
||||
|
||||
# Support both relative and absolute imports
|
||||
try:
|
||||
from . import resources
|
||||
except ImportError:
|
||||
import resources
|
||||
|
||||
# Cache for discovered workflows (refreshed on each list_workflows call)
|
||||
_workflow_cache: Dict[str, dict] = {}
|
||||
|
||||
@@ -24,6 +34,95 @@ def load_workflow_module(workflow_name: str):
|
||||
return module
|
||||
|
||||
|
||||
def load_yaml_schema(workflow_name: str) -> Optional[Dict]:
|
||||
"""Load YAML schema for a workflow if it exists."""
|
||||
yaml_path = os.path.join(os.path.dirname(__file__), "workflows", f"{workflow_name}.yaml")
|
||||
|
||||
if not os.path.exists(yaml_path):
|
||||
return None
|
||||
|
||||
with open(yaml_path, "r", encoding="utf-8") as f:
|
||||
return yaml.safe_load(f)
|
||||
|
||||
|
||||
def ensure_yaml_schema(workflow_name: str, module) -> Optional[Dict]:
|
||||
"""
|
||||
Ensure YAML schema exists for a workflow.
|
||||
Auto-generates from WorkflowParams if missing.
|
||||
Returns the schema dict or None.
|
||||
"""
|
||||
yaml_path = Path(os.path.dirname(__file__)) / "workflows" / f"{workflow_name}.yaml"
|
||||
|
||||
# Try to load existing YAML
|
||||
schema = load_yaml_schema(workflow_name)
|
||||
|
||||
if schema is None and hasattr(module, "WorkflowParams"):
|
||||
# Auto-generate YAML from WorkflowParams
|
||||
try:
|
||||
# Support both relative and absolute imports
|
||||
try:
|
||||
from .schema_generator import generate_workflow_schema
|
||||
except ImportError:
|
||||
from schema_generator import generate_workflow_schema
|
||||
|
||||
py_path = yaml_path.with_suffix(".py")
|
||||
schema = generate_workflow_schema(py_path)
|
||||
print(f"[workflows] Auto-generated schema: {workflow_name}.yaml")
|
||||
except Exception as e:
|
||||
print(f"[workflows] Error generating schema for {workflow_name}: {e}")
|
||||
|
||||
return schema
|
||||
|
||||
|
||||
def get_options_resolver() -> Dict[str, Callable[[], List[Dict]]]:
|
||||
"""
|
||||
Get mapping from options_source to resolver functions.
|
||||
"""
|
||||
return {
|
||||
# Enums
|
||||
"samplers": resources.get_samplers,
|
||||
"schedulers": resources.get_schedulers,
|
||||
"upscale_methods": resources.get_upscale_methods,
|
||||
|
||||
# Models
|
||||
"checkpoints": lambda: resources.get_models_by_type("checkpoints"),
|
||||
"loras": lambda: resources.get_models_by_type("loras"),
|
||||
"vae": lambda: resources.get_models_by_type("vae"),
|
||||
"embeddings": lambda: resources.get_models_by_type("embeddings"),
|
||||
"upscale_models": lambda: resources.get_models_by_type("upscale_models"),
|
||||
"controlnet": lambda: resources.get_models_by_type("controlnet"),
|
||||
"clip": lambda: resources.get_models_by_type("clip"),
|
||||
"clip_vision": lambda: resources.get_models_by_type("clip_vision"),
|
||||
"diffusion_models": lambda: resources.get_models_by_type("diffusion_models"),
|
||||
"unet": lambda: resources.get_models_by_type("unet"),
|
||||
"ipadapters": lambda: resources.get_models_by_type("ipadapter"),
|
||||
}
|
||||
|
||||
|
||||
def resolve_options_source(parameters: List[Dict]) -> List[Dict]:
|
||||
"""
|
||||
Resolve options_source references in parameters to actual options.
|
||||
Returns a new list with resolved options.
|
||||
"""
|
||||
resolvers = get_options_resolver()
|
||||
resolved = []
|
||||
|
||||
for param in parameters:
|
||||
param_copy = param.copy()
|
||||
|
||||
options_source = param_copy.get("options_source")
|
||||
if options_source and options_source in resolvers:
|
||||
try:
|
||||
param_copy["options"] = resolvers[options_source]()
|
||||
except Exception as e:
|
||||
print(f"[workflows] Error resolving {options_source}: {e}")
|
||||
param_copy["options"] = []
|
||||
|
||||
resolved.append(param_copy)
|
||||
|
||||
return resolved
|
||||
|
||||
|
||||
def discover_workflows(force_refresh: bool = False) -> Dict[str, dict]:
|
||||
"""
|
||||
Discover all workflow files in the workflows/ folder.
|
||||
@@ -63,6 +162,13 @@ def discover_workflows(force_refresh: bool = False) -> Dict[str, dict]:
|
||||
|
||||
metadata = module.WORKFLOW_METADATA
|
||||
|
||||
# Check for YAML schema
|
||||
yaml_schema = load_yaml_schema(workflow_id)
|
||||
has_yaml = yaml_schema is not None
|
||||
|
||||
# Check for legacy WORKFLOW_PARAMETERS (for backward compat)
|
||||
has_legacy_params = hasattr(module, "WORKFLOW_PARAMETERS")
|
||||
|
||||
# Build workflow config
|
||||
discovered[workflow_id] = {
|
||||
"script": workflow_id,
|
||||
@@ -70,7 +176,8 @@ def discover_workflows(force_refresh: bool = False) -> Dict[str, dict]:
|
||||
"description": metadata.get("description", ""),
|
||||
"model_types": metadata.get("model_types", []),
|
||||
"category": metadata.get("category", "Uncategorized"),
|
||||
"has_parameters": hasattr(module, "WORKFLOW_PARAMETERS"),
|
||||
"has_parameters": has_yaml or has_legacy_params,
|
||||
"schema_source": "yaml" if has_yaml else ("legacy" if has_legacy_params else None),
|
||||
}
|
||||
|
||||
print(f"[workflows] Discovered: {workflow_id} - {metadata.get('name', workflow_id)}")
|
||||
@@ -106,27 +213,46 @@ def get_workflow_metadata(name: str) -> dict:
|
||||
raise ValueError(f"Workflow '{name}' not found. Available: {list(workflows.keys())}")
|
||||
|
||||
config = workflows[name].copy()
|
||||
config.pop("script") # Don't expose internal file path
|
||||
config.pop("script", None) # Don't expose internal file path
|
||||
config.pop("schema_source", None) # Internal use only
|
||||
return config
|
||||
|
||||
|
||||
def get_workflow_parameters(name: str) -> Optional[List[dict]]:
|
||||
def get_workflow_parameters(name: str, resolve_options: bool = True) -> Optional[List[dict]]:
|
||||
"""
|
||||
Get parameter schema for a specific workflow.
|
||||
Returns None if workflow doesn't define WORKFLOW_PARAMETERS.
|
||||
|
||||
Loads from YAML schema first, falls back to legacy WORKFLOW_PARAMETERS.
|
||||
Auto-generates YAML if WorkflowParams exists but no schema.
|
||||
|
||||
Args:
|
||||
name: Workflow name/ID
|
||||
resolve_options: If True, resolve options_source to actual options
|
||||
|
||||
Returns:
|
||||
List of parameter definitions, or None if no schema exists
|
||||
"""
|
||||
workflows = discover_workflows()
|
||||
|
||||
if name not in workflows:
|
||||
raise ValueError(f"Workflow '{name}' not found. Available: {list(workflows.keys())}")
|
||||
|
||||
# Load the module to get parameters
|
||||
# Load the module
|
||||
module = load_workflow_module(name)
|
||||
|
||||
if not hasattr(module, "WORKFLOW_PARAMETERS"):
|
||||
return None
|
||||
# Try YAML schema first
|
||||
schema = ensure_yaml_schema(name, module)
|
||||
if schema and "parameters" in schema:
|
||||
parameters = schema["parameters"]
|
||||
if resolve_options:
|
||||
parameters = resolve_options_source(parameters)
|
||||
return parameters
|
||||
|
||||
return module.WORKFLOW_PARAMETERS
|
||||
# Fall back to legacy WORKFLOW_PARAMETERS
|
||||
if hasattr(module, "WORKFLOW_PARAMETERS"):
|
||||
return module.WORKFLOW_PARAMETERS
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def list_workflows(refresh: bool = True) -> list:
|
||||
@@ -139,7 +265,7 @@ def list_workflows(refresh: bool = True) -> list:
|
||||
return [
|
||||
{
|
||||
"id": name,
|
||||
**{k: v for k, v in config.items() if k != "script"}
|
||||
**{k: v for k, v in config.items() if k not in ("script", "schema_source")}
|
||||
}
|
||||
for name, config in workflows.items()
|
||||
]
|
||||
+35
-203
@@ -1,16 +1,22 @@
|
||||
"""
|
||||
Basic SDXL Text to Image workflow.
|
||||
Schema is defined in basic_sdxl.yaml (auto-generated from WorkflowParams).
|
||||
"""
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
from base import BaseWorkflow
|
||||
from parameters import Lora
|
||||
from parameter_schema import param, ParameterCategory
|
||||
from parameters import (
|
||||
Prompt, NegativePrompt, Checkpoint, Seed, Sampler, Scheduler,
|
||||
Width, Height, Lora
|
||||
)
|
||||
|
||||
# ============================================
|
||||
# Workflow Metadata
|
||||
@@ -24,210 +30,36 @@ WORKFLOW_METADATA = {
|
||||
}
|
||||
|
||||
# ============================================
|
||||
# Workflow Parameters Schema
|
||||
# ============================================
|
||||
|
||||
WORKFLOW_PARAMETERS = [
|
||||
# Prompts
|
||||
param.text_area(
|
||||
name="prompt",
|
||||
label="Prompt",
|
||||
category=ParameterCategory.PROMPTS,
|
||||
required=True,
|
||||
placeholder="Enter your prompt...",
|
||||
rows=4,
|
||||
),
|
||||
param.text_area(
|
||||
name="negativePrompt",
|
||||
label="Negative Prompt",
|
||||
category=ParameterCategory.PROMPTS,
|
||||
default="text, watermark",
|
||||
placeholder="Enter negative prompt...",
|
||||
rows=2,
|
||||
),
|
||||
|
||||
# Models
|
||||
param.model_select(
|
||||
name="checkpoints",
|
||||
label="Checkpoint",
|
||||
category=ParameterCategory.MODELS,
|
||||
model_type="checkpoints",
|
||||
required=True,
|
||||
multiple=True,
|
||||
max_selections=1,
|
||||
),
|
||||
param.model_select(
|
||||
name="loras",
|
||||
label="LoRAs",
|
||||
category=ParameterCategory.MODELS,
|
||||
model_type="loras",
|
||||
multiple=True,
|
||||
description="Add LoRA models to apply",
|
||||
),
|
||||
|
||||
# Parameters (Sampling)
|
||||
param.slider(
|
||||
name="steps",
|
||||
label="Steps",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
min_val=1,
|
||||
max_val=150,
|
||||
default=20,
|
||||
),
|
||||
param.slider(
|
||||
name="cfg",
|
||||
label="CFG Scale",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
min_val=1.0,
|
||||
max_val=20.0,
|
||||
default=8.0,
|
||||
step=0.5,
|
||||
is_float=True,
|
||||
),
|
||||
param.select(
|
||||
name="sampler",
|
||||
label="Sampler",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
options=[
|
||||
{"value": "euler", "label": "Euler"},
|
||||
{"value": "euler_ancestral", "label": "Euler Ancestral"},
|
||||
{"value": "heun", "label": "Heun"},
|
||||
{"value": "dpm_2", "label": "DPM 2"},
|
||||
{"value": "dpm_2_ancestral", "label": "DPM 2 Ancestral"},
|
||||
{"value": "lms", "label": "LMS"},
|
||||
{"value": "dpmpp_2m", "label": "DPM++ 2M"},
|
||||
{"value": "dpmpp_2m_sde", "label": "DPM++ 2M SDE"},
|
||||
{"value": "dpmpp_sde", "label": "DPM++ SDE"},
|
||||
{"value": "ddim", "label": "DDIM"},
|
||||
],
|
||||
default="euler",
|
||||
searchable=True,
|
||||
),
|
||||
param.select(
|
||||
name="scheduler",
|
||||
label="Scheduler",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
options=[
|
||||
{"value": "normal", "label": "Normal"},
|
||||
{"value": "karras", "label": "Karras"},
|
||||
{"value": "exponential", "label": "Exponential"},
|
||||
{"value": "sgm_uniform", "label": "SGM Uniform"},
|
||||
{"value": "simple", "label": "Simple"},
|
||||
{"value": "ddim_uniform", "label": "DDIM Uniform"},
|
||||
],
|
||||
default="normal",
|
||||
),
|
||||
param.seed_input(
|
||||
name="seed",
|
||||
label="Seed",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
),
|
||||
|
||||
# Composition
|
||||
param.slider(
|
||||
name="width",
|
||||
label="Width",
|
||||
category=ParameterCategory.COMPOSITION,
|
||||
min_val=64,
|
||||
max_val=2048,
|
||||
default=1024,
|
||||
step=8,
|
||||
),
|
||||
param.slider(
|
||||
name="height",
|
||||
label="Height",
|
||||
category=ParameterCategory.COMPOSITION,
|
||||
min_val=64,
|
||||
max_val=2048,
|
||||
default=1024,
|
||||
step=8,
|
||||
),
|
||||
|
||||
# Advanced - Loopback
|
||||
param.toggle(
|
||||
name="loopback",
|
||||
label="Enable Loopback",
|
||||
category=ParameterCategory.ADVANCED,
|
||||
default=False,
|
||||
style="switch",
|
||||
description="Enable iterative upscaling and refinement",
|
||||
),
|
||||
param.slider(
|
||||
name="loopbackIterations",
|
||||
label="Loopback Iterations",
|
||||
category=ParameterCategory.ADVANCED,
|
||||
min_val=1,
|
||||
max_val=5,
|
||||
default=1,
|
||||
depends_on={"loopback": True},
|
||||
),
|
||||
param.slider(
|
||||
name="loopbackUpscale",
|
||||
label="Loopback Upscale",
|
||||
category=ParameterCategory.ADVANCED,
|
||||
min_val=1.0,
|
||||
max_val=2.0,
|
||||
default=1.25,
|
||||
step=0.05,
|
||||
is_float=True,
|
||||
depends_on={"loopback": True},
|
||||
),
|
||||
param.slider(
|
||||
name="loopbackDenoise",
|
||||
label="Loopback Denoise",
|
||||
category=ParameterCategory.ADVANCED,
|
||||
min_val=0.0,
|
||||
max_val=1.0,
|
||||
default=0.5,
|
||||
step=0.05,
|
||||
is_float=True,
|
||||
depends_on={"loopback": True},
|
||||
),
|
||||
param.slider(
|
||||
name="loopbackSteps",
|
||||
label="Loopback Steps",
|
||||
category=ParameterCategory.ADVANCED,
|
||||
min_val=1,
|
||||
max_val=50,
|
||||
default=10,
|
||||
depends_on={"loopback": True},
|
||||
),
|
||||
param.slider(
|
||||
name="loopbackCfg",
|
||||
label="Loopback CFG",
|
||||
category=ParameterCategory.ADVANCED,
|
||||
min_val=1.0,
|
||||
max_val=20.0,
|
||||
default=7.0,
|
||||
step=0.5,
|
||||
is_float=True,
|
||||
depends_on={"loopback": True},
|
||||
),
|
||||
]
|
||||
|
||||
# ============================================
|
||||
# Workflow Parameters Model (for validation)
|
||||
# Workflow Parameters Model
|
||||
# ============================================
|
||||
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
loras: List[Lora] = []
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
cfg: float = 8.0
|
||||
width: int = 1024
|
||||
height: int = 1024
|
||||
sampler: str = 'euler'
|
||||
scheduler: str = 'normal'
|
||||
"""
|
||||
Parameters for SDXL text-to-image generation.
|
||||
Schema is auto-generated to basic_sdxl.yaml from these type annotations.
|
||||
"""
|
||||
# Use annotated types for automatic UI schema
|
||||
prompt: Prompt
|
||||
negativePrompt: NegativePrompt = "text, watermark"
|
||||
checkpoints: Checkpoint
|
||||
loras: List[Lora] = [] # Generator infers params from Lora class
|
||||
sampler: Sampler = "euler"
|
||||
scheduler: Scheduler = "normal"
|
||||
seed: Seed # Required, no default
|
||||
width: Width = 1024
|
||||
height: Height = 1024
|
||||
|
||||
# Inline Field() for one-off constraints
|
||||
steps: int = Field(default=20, ge=1, le=150)
|
||||
cfg: float = Field(default=8.0, ge=1.0, le=20.0, json_schema_extra={"step": 0.5})
|
||||
|
||||
# Plain types fall back to basic inference
|
||||
loopback: bool = False
|
||||
# Flattened loopback parameters
|
||||
loopbackIterations: int = 1
|
||||
loopbackUpscale: float = 1.25
|
||||
loopbackDenoise: float = 0.5
|
||||
loopbackSteps: int = 10
|
||||
loopbackCfg: float = 7.0
|
||||
loopbackIterations: int = Field(default=1, ge=1, le=5, json_schema_extra={"category": "advanced"})
|
||||
loopbackUpscale: float = Field(default=1.25, ge=1.0, le=2.0, json_schema_extra={"category": "advanced", "step": 0.05})
|
||||
loopbackDenoise: float = Field(default=0.5, ge=0.0, le=1.0, json_schema_extra={"category": "advanced", "step": 0.05})
|
||||
loopbackSteps: int = Field(default=10, ge=1, le=50, json_schema_extra={"category": "advanced"})
|
||||
loopbackCfg: float = Field(default=7.0, ge=1.0, le=20.0, json_schema_extra={"category": "advanced", "step": 0.5})
|
||||
|
||||
# Workflow definition
|
||||
class SDXLWorkflow(BaseWorkflow):
|
||||
|
||||
+21
-126
@@ -1,15 +1,22 @@
|
||||
"""
|
||||
Test Workflow 1 (No LoRAs).
|
||||
Schema is defined in basic_test1.yaml (auto-generated from WorkflowParams).
|
||||
"""
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
from base import BaseWorkflow
|
||||
from parameter_schema import param, ParameterCategory
|
||||
from parameters import (
|
||||
Prompt, NegativePrompt, Checkpoint, Seed, Sampler, Scheduler,
|
||||
Width, Height
|
||||
)
|
||||
|
||||
# ============================================
|
||||
# Workflow Metadata
|
||||
@@ -23,133 +30,21 @@ WORKFLOW_METADATA = {
|
||||
}
|
||||
|
||||
# ============================================
|
||||
# Workflow Parameters Schema
|
||||
# ============================================
|
||||
|
||||
WORKFLOW_PARAMETERS = [
|
||||
# Prompts
|
||||
param.text_area(
|
||||
name="prompt",
|
||||
label="Prompt",
|
||||
category=ParameterCategory.PROMPTS,
|
||||
required=True,
|
||||
placeholder="Enter your prompt...",
|
||||
rows=4,
|
||||
),
|
||||
param.text_area(
|
||||
name="negativePrompt",
|
||||
label="Negative Prompt",
|
||||
category=ParameterCategory.PROMPTS,
|
||||
default="text, watermark",
|
||||
placeholder="Enter negative prompt...",
|
||||
rows=2,
|
||||
),
|
||||
|
||||
# Models - NO LORAS
|
||||
param.model_select(
|
||||
name="checkpoints",
|
||||
label="Checkpoint",
|
||||
category=ParameterCategory.MODELS,
|
||||
model_type="checkpoints",
|
||||
required=True,
|
||||
multiple=True,
|
||||
max_selections=1,
|
||||
),
|
||||
|
||||
# Parameters (Sampling)
|
||||
param.slider(
|
||||
name="steps",
|
||||
label="Steps",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
min_val=1,
|
||||
max_val=150,
|
||||
default=20,
|
||||
),
|
||||
param.slider(
|
||||
name="cfg",
|
||||
label="CFG Scale",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
min_val=1.0,
|
||||
max_val=20.0,
|
||||
default=8.0,
|
||||
step=0.5,
|
||||
is_float=True,
|
||||
),
|
||||
param.select(
|
||||
name="sampler",
|
||||
label="Sampler",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
options=[
|
||||
{"value": "euler", "label": "Euler"},
|
||||
{"value": "euler_ancestral", "label": "Euler Ancestral"},
|
||||
{"value": "heun", "label": "Heun"},
|
||||
{"value": "dpm_2", "label": "DPM 2"},
|
||||
{"value": "dpm_2_ancestral", "label": "DPM 2 Ancestral"},
|
||||
{"value": "lms", "label": "LMS"},
|
||||
{"value": "dpmpp_2m", "label": "DPM++ 2M"},
|
||||
{"value": "dpmpp_2m_sde", "label": "DPM++ 2M SDE"},
|
||||
{"value": "dpmpp_sde", "label": "DPM++ SDE"},
|
||||
{"value": "ddim", "label": "DDIM"},
|
||||
],
|
||||
default="euler",
|
||||
searchable=True,
|
||||
),
|
||||
param.select(
|
||||
name="scheduler",
|
||||
label="Scheduler",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
options=[
|
||||
{"value": "normal", "label": "Normal"},
|
||||
{"value": "karras", "label": "Karras"},
|
||||
{"value": "exponential", "label": "Exponential"},
|
||||
{"value": "sgm_uniform", "label": "SGM Uniform"},
|
||||
{"value": "simple", "label": "Simple"},
|
||||
{"value": "ddim_uniform", "label": "DDIM Uniform"},
|
||||
],
|
||||
default="normal",
|
||||
),
|
||||
param.seed_input(
|
||||
name="seed",
|
||||
label="Seed",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
),
|
||||
|
||||
# Composition
|
||||
param.slider(
|
||||
name="width",
|
||||
label="Width",
|
||||
category=ParameterCategory.COMPOSITION,
|
||||
min_val=64,
|
||||
max_val=2048,
|
||||
default=1024,
|
||||
step=8,
|
||||
),
|
||||
param.slider(
|
||||
name="height",
|
||||
label="Height",
|
||||
category=ParameterCategory.COMPOSITION,
|
||||
min_val=64,
|
||||
max_val=2048,
|
||||
default=1024,
|
||||
step=8,
|
||||
),
|
||||
]
|
||||
|
||||
# ============================================
|
||||
# Workflow Parameters Model (for validation)
|
||||
# Workflow Parameters Model
|
||||
# ============================================
|
||||
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
cfg: float = 8.0
|
||||
width: int = 1024
|
||||
height: int = 1024
|
||||
sampler: str = 'euler'
|
||||
scheduler: str = 'normal'
|
||||
"""Parameters for test workflow without LoRAs."""
|
||||
prompt: Prompt
|
||||
negativePrompt: NegativePrompt = "text, watermark"
|
||||
checkpoints: Checkpoint
|
||||
sampler: Sampler = "euler"
|
||||
scheduler: Scheduler = "normal"
|
||||
seed: Seed
|
||||
width: Width = 1024
|
||||
height: Height = 1024
|
||||
steps: int = Field(default=20, ge=1, le=150)
|
||||
cfg: float = Field(default=8.0, ge=1.0, le=20.0, json_schema_extra={"step": 0.5})
|
||||
|
||||
# Workflow definition
|
||||
class TestWorkflow1(BaseWorkflow):
|
||||
|
||||
+18
-100
@@ -1,16 +1,21 @@
|
||||
"""
|
||||
Test Workflow 2 (No Sampler/Scheduler).
|
||||
Schema is defined in basic_test2.yaml (auto-generated from WorkflowParams).
|
||||
"""
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
from base import BaseWorkflow
|
||||
from parameters import Lora
|
||||
from parameter_schema import param, ParameterCategory
|
||||
from parameters import (
|
||||
Prompt, NegativePrompt, Checkpoint, Seed, Width, Height, Lora
|
||||
)
|
||||
|
||||
# ============================================
|
||||
# Workflow Metadata
|
||||
@@ -24,107 +29,20 @@ WORKFLOW_METADATA = {
|
||||
}
|
||||
|
||||
# ============================================
|
||||
# Workflow Parameters Schema
|
||||
# ============================================
|
||||
|
||||
WORKFLOW_PARAMETERS = [
|
||||
# Prompts
|
||||
param.text_area(
|
||||
name="prompt",
|
||||
label="Prompt",
|
||||
category=ParameterCategory.PROMPTS,
|
||||
required=True,
|
||||
placeholder="Enter your prompt...",
|
||||
rows=4,
|
||||
),
|
||||
param.text_area(
|
||||
name="negativePrompt",
|
||||
label="Negative Prompt",
|
||||
category=ParameterCategory.PROMPTS,
|
||||
default="text, watermark",
|
||||
placeholder="Enter negative prompt...",
|
||||
rows=2,
|
||||
),
|
||||
|
||||
# Models
|
||||
param.model_select(
|
||||
name="checkpoints",
|
||||
label="Checkpoint",
|
||||
category=ParameterCategory.MODELS,
|
||||
model_type="checkpoints",
|
||||
required=True,
|
||||
multiple=True,
|
||||
max_selections=1,
|
||||
),
|
||||
param.model_select(
|
||||
name="loras",
|
||||
label="LoRAs",
|
||||
category=ParameterCategory.MODELS,
|
||||
model_type="loras",
|
||||
multiple=True,
|
||||
description="Add LoRA models to apply",
|
||||
),
|
||||
|
||||
# Parameters (Sampling) - NO SAMPLER/SCHEDULER
|
||||
param.slider(
|
||||
name="steps",
|
||||
label="Steps",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
min_val=1,
|
||||
max_val=150,
|
||||
default=20,
|
||||
),
|
||||
param.slider(
|
||||
name="cfg",
|
||||
label="CFG Scale",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
min_val=1.0,
|
||||
max_val=20.0,
|
||||
default=8.0,
|
||||
step=0.5,
|
||||
is_float=True,
|
||||
),
|
||||
param.seed_input(
|
||||
name="seed",
|
||||
label="Seed",
|
||||
category=ParameterCategory.PARAMETERS,
|
||||
),
|
||||
|
||||
# Composition
|
||||
param.slider(
|
||||
name="width",
|
||||
label="Width",
|
||||
category=ParameterCategory.COMPOSITION,
|
||||
min_val=64,
|
||||
max_val=2048,
|
||||
default=1024,
|
||||
step=8,
|
||||
),
|
||||
param.slider(
|
||||
name="height",
|
||||
label="Height",
|
||||
category=ParameterCategory.COMPOSITION,
|
||||
min_val=64,
|
||||
max_val=2048,
|
||||
default=1024,
|
||||
step=8,
|
||||
),
|
||||
]
|
||||
|
||||
# ============================================
|
||||
# Workflow Parameters Model (for validation)
|
||||
# Workflow Parameters Model
|
||||
# ============================================
|
||||
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
"""Parameters for test workflow without sampler/scheduler."""
|
||||
prompt: Prompt
|
||||
negativePrompt: NegativePrompt = "text, watermark"
|
||||
checkpoints: Checkpoint
|
||||
loras: List[Lora] = []
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
cfg: float = 8.0
|
||||
width: int = 1024
|
||||
height: int = 1024
|
||||
seed: Seed
|
||||
width: Width = 1024
|
||||
height: Height = 1024
|
||||
steps: int = Field(default=20, ge=1, le=150)
|
||||
cfg: float = Field(default=8.0, ge=1.0, le=20.0, json_schema_extra={"step": 0.5})
|
||||
|
||||
# Workflow definition
|
||||
class TestWorkflow2(BaseWorkflow):
|
||||
|
||||
Reference in new issue
Block a user