Archived
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
"""
|
|
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, 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 (
|
|
Prompt, NegativePrompt, Checkpoint, Seed, Dimensions, Loras
|
|
)
|
|
|
|
# ============================================
|
|
# Workflow Metadata
|
|
# ============================================
|
|
|
|
WORKFLOW_METADATA = {
|
|
"name": "Test Workflow 2 (No Sampler/Scheduler)",
|
|
"description": "Test workflow without sampler/scheduler selection.",
|
|
"model_types": ["SDXL"],
|
|
"category": "Testing",
|
|
}
|
|
|
|
# ============================================
|
|
# Workflow Parameters Model
|
|
# ============================================
|
|
|
|
class WorkflowParams(BaseModel):
|
|
"""Parameters for test workflow without sampler/scheduler."""
|
|
prompt: Prompt
|
|
negativePrompt: NegativePrompt = "text, watermark"
|
|
checkpoints: Checkpoint
|
|
loras: Loras
|
|
seed: Seed
|
|
dimensions: Dimensions
|
|
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):
|
|
def run(self):
|
|
params: WorkflowParams = self.params
|
|
|
|
with Workflow(wait=False):
|
|
model, clip, vae = self.load_checkpoints()
|
|
model, clip = self.apply_loras(model, clip)
|
|
|
|
conditioning = CLIPTextEncode(params.prompt, clip)
|
|
conditioning2 = CLIPTextEncode(params.negativePrompt, clip)
|
|
latent = EmptyLatentImage(params.dimensions.width, params.dimensions.height, 1)
|
|
|
|
# Hardcoded sampler/scheduler
|
|
latent = KSampler(model, params.seed, params.steps, params.cfg, 'euler', 'normal', conditioning, conditioning2, latent, 1)
|
|
|
|
image = VAEDecode(latent, vae)
|
|
preview = PreviewImage(image)
|
|
|
|
return {
|
|
'prompt_id': preview.task.prompt_id,
|
|
'status': 'queued',
|
|
'parameters': self.params.model_dump(mode='json')
|
|
}
|
|
|
|
# Module-level entry point
|
|
def run_workflow(**kwargs):
|
|
"""Entry point for the workflow."""
|
|
required = ['prompt', 'checkpoints', 'seed', 'steps', 'negativePrompt', 'dimensions', 'cfg']
|
|
missing = [f for f in required if f not in kwargs]
|
|
if missing:
|
|
raise ValueError(f"Missing required fields: {', '.join(missing)}")
|
|
|
|
params = WorkflowParams(**kwargs)
|
|
|
|
# Create and run workflow
|
|
workflow = TestWorkflow2(params)
|
|
return workflow.run()
|