initial commit

This commit is contained in:
donny committed 2026-01-03 14:42:05 -07:00
commit 5441b0d8ff
10 files changed
+714

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
"""
Test workflow - example ComfyScript workflow.
Each workflow file should have a run_workflow() function that accepts parameters.
comfyscript must be loaded outside of the run_workflow scope
"""
from comfy_script.runtime import *
load('http://127.0.0.1:8188/')
from comfy_script.runtime.nodes import *
import random
def run_workflow(**kwargs):
"""
Execute the test workflow.
Args:
**kwargs: Workflow parameters (e.g., prompt, seed, steps, etc.)
Returns:
dict: Result containing output data and metadata
"""
prompt = kwargs.get('prompt', 'beautiful scenery')
with Workflow(wait=False):
model, clip, vae = CheckpointLoaderSimple(kwargs.get('checkpoint', Checkpoints.anbanIllus_shinv1))
conditioning = CLIPTextEncode(prompt, clip)
conditioning2 = CLIPTextEncode(kwargs.get('negative_prompt', 'text, watermark'), clip)
latent = EmptyLatentImage(512, 512, 1)
seed = kwargs.get('seed', random.randint(0, 15663308700286))
steps = kwargs.get('steps', 20)
latent = KSampler(model, seed, steps, 8, 'euler', 'normal', conditioning, conditioning2, latent, 1)
image = VAEDecode(latent, vae)
preview = PreviewImage(image)
return {
'prompt_id': preview.task.prompt_id,
'status': 'queued',
'parameters': kwargs
}
+67
View File
@@ -0,0 +1,67 @@
"""
Example image generation workflow.
Copy this template to create new workflows.
"""
def run_workflow(**kwargs):
"""
Generate an image using ComfyScript.
Args:
prompt (str): Positive prompt
negative_prompt (str): Negative prompt
checkpoint (str): Model checkpoint name
seed (int): Random seed
steps (int): Number of sampling steps
cfg (float): CFG scale
width (int): Image width
height (int): Image height
Returns:
dict: Contains prompt_id, status, and output data
"""
# Import ComfyScript - only when workflow is called
from comfy_script.runtime import *
load('http://127.0.0.1:8188/')
from comfy_script.runtime.nodes import *
import random
# Parse parameters with defaults
prompt = kwargs.get('prompt', 'beautiful scenery')
negative_prompt = kwargs.get('negative_prompt', 'text, watermark')
checkpoint = kwargs.get('checkpoint', 'anbanIllus_shinv1')
seed = kwargs.get('seed', random.randint(0, 2**32 - 1))
steps = kwargs.get('steps', 20)
cfg = kwargs.get('cfg', 8)
width = kwargs.get('width', 512)
height = kwargs.get('height', 512)
# Execute workflow
with Workflow(wait=True) as wf:
model, clip, vae = CheckpointLoaderSimple(getattr(Checkpoints, checkpoint))
conditioning = CLIPTextEncode(prompt, clip)
conditioning_neg = CLIPTextEncode(negative_prompt, clip)
latent = EmptyLatentImage(width, height, 1)
latent_out = KSampler(
model, seed, steps, cfg, 'euler', 'normal',
conditioning, conditioning_neg, latent, 1
)
image = VAEDecode(latent_out, vae)
preview = PreviewImage(image)
# Wait for results
result = preview.task.wait_result(preview)
return {
'prompt_id': preview.task.prompt_id,
'status': 'completed',
'seed': seed,
'parameters': {
'prompt': prompt,
'negative_prompt': negative_prompt,
'steps': steps,
'cfg': cfg,
'size': f"{width}x{height}"
},
'output': result
}
+52
View File
@@ -0,0 +1,52 @@
from comfy_script.runtime import *
load('http://127.0.0.1:8188/')
from comfy_script.runtime.nodes import *
from dataclasses import dataclass
from typing import List, Optional
import random
def run_workflow(**kwargs):
required = ['prompt', 'checkpoints', 'seed', 'steps', 'negativePrompt', 'width', 'height']
missing = [f for f in required if f not in kwargs]
if missing:
raise ValueError(f"Missing required fields: {', '.join(missing)}")
params = WorkflowParams(**kwargs)
with Workflow(wait=False):
if len(params.checkpoints) > 1:
model1, clip1, vae = CheckpointLoaderSimple(params.checkpoints[0])
model2, clip2, vae = CheckpointLoaderSimple(params.checkpoints[1])
model = ModelMergeSimple(model1, model2, 0.5)
clip = CLIPMergeSimple(clip1, clip2, 0.5)
else:
model, clip, vae = CheckpointLoaderSimple(params.checkpoints[0])
conditioning = CLIPTextEncode(params.prompt, clip)
conditioning2 = CLIPTextEncode(params.negativePrompt, clip)
latent = EmptyLatentImage(params.width, params.height, 1)
seed = params.seed
steps = params.steps
latent = KSampler(model, seed, steps, 8, 'euler', 'normal', conditioning, conditioning2, latent, 1)
image = VAEDecode(latent, vae)
preview = PreviewImage(image)
return {
'prompt_id': preview.task.prompt_id,
'status': 'queued',
'parameters': kwargs
}
# Parameters typing
@dataclass
class WorkflowParams:
prompt: str
checkpoints: List[str]
seed: Optional[int] = random.randint(0, 15663308700286)
steps: int = 20
negativePrompt: str = "text, watermark"
width: int = 512
height: int = 512