Archived
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
"""
|
|
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
|
|
}
|