Archived
added basic workflow scripts
This commit is contained in:
1 parent
7d2b95df19
commit
9ae3f05809
7 files changed
+273
-117
No files matched your search
+29
-8
@@ -26,16 +26,37 @@ WORKFLOW_FILES: Dict[str, dict] = {
|
||||
"name": "Test Workflow",
|
||||
"description": "Simple test workflow for image generation",
|
||||
"model_types": ["SDXL", "Pony", "Illustrious"],
|
||||
"category": "generation"
|
||||
"category": "Image Generation"
|
||||
},
|
||||
# Add more workflows here as you create them
|
||||
# "image_generation": {
|
||||
# "file": "example_image_gen",
|
||||
# "name": "Image Generation",
|
||||
# "description": "Advanced image generation with controlnets",
|
||||
# "model_types": ["checkpoint", "lora", "controlnet"],
|
||||
# "category": "generation"
|
||||
# },
|
||||
"basic_sdxl": {
|
||||
"file": "basic_sdxl",
|
||||
"name": "Basic SDXL Text to Image",
|
||||
"description": "Workflow with SDXL presets for quick iteration.",
|
||||
"model_types": ["SDXL"],
|
||||
"category": "Image Generation"
|
||||
},
|
||||
"basic_sd15": {
|
||||
"file": "basic_sd15",
|
||||
"name": "Basic SD15 Text to Image",
|
||||
"description": "Workflow with SD15 presets for quick iteration.",
|
||||
"model_types": ["SD15"],
|
||||
"category": "Image Generation"
|
||||
},
|
||||
"basic_pony": {
|
||||
"file": "basic_pony",
|
||||
"name": "Basic Pony Text to Image",
|
||||
"description": "Workflow with Pony presets for quick iteration.",
|
||||
"model_types": ["Pony"],
|
||||
"category": "Image Generation"
|
||||
},
|
||||
"basic_illustrious": {
|
||||
"file": "basic_illustrious",
|
||||
"name": "Basic Illustrious Text to Image",
|
||||
"description": "Workflow with Illustrious presets for quick iteration.",
|
||||
"model_types": ["Illustrious"],
|
||||
"category": "Image Generation"
|
||||
},
|
||||
}
|
||||
|
||||
def get_workflow(name: str) -> Callable:
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
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
|
||||
|
||||
# Workflow-specific parameters
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
loras: List[Lora] = []
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
width: int = 512
|
||||
height: int = 512
|
||||
|
||||
# Workflow definition
|
||||
class TestWorkflow(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.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': self.params.model_dump()
|
||||
}
|
||||
|
||||
# Module-level entry point
|
||||
def run_workflow(**kwargs):
|
||||
"""Entry point for the workflow."""
|
||||
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)
|
||||
|
||||
# Create and run workflow
|
||||
workflow = TestWorkflow(params)
|
||||
return workflow.run()
|
||||
@@ -0,0 +1,61 @@
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
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
|
||||
|
||||
# Workflow-specific parameters
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
loras: List[Lora] = []
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
width: int = 512
|
||||
height: int = 512
|
||||
|
||||
# Workflow definition
|
||||
class TestWorkflow(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.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': self.params.model_dump()
|
||||
}
|
||||
|
||||
# Module-level entry point
|
||||
def run_workflow(**kwargs):
|
||||
"""Entry point for the workflow."""
|
||||
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)
|
||||
|
||||
# Create and run workflow
|
||||
workflow = TestWorkflow(params)
|
||||
return workflow.run()
|
||||
@@ -0,0 +1,61 @@
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
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
|
||||
|
||||
# Workflow-specific parameters
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
loras: List[Lora] = []
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
width: int = 512
|
||||
height: int = 512
|
||||
|
||||
# Workflow definition
|
||||
class TestWorkflow(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.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': self.params.model_dump()
|
||||
}
|
||||
|
||||
# Module-level entry point
|
||||
def run_workflow(**kwargs):
|
||||
"""Entry point for the workflow."""
|
||||
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)
|
||||
|
||||
# Create and run workflow
|
||||
workflow = TestWorkflow(params)
|
||||
return workflow.run()
|
||||
@@ -0,0 +1,61 @@
|
||||
from comfy_script.runtime import *
|
||||
load('http://127.0.0.1:8188/')
|
||||
from comfy_script.runtime.nodes import *
|
||||
|
||||
from pydantic import BaseModel
|
||||
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
|
||||
|
||||
# Workflow-specific parameters
|
||||
class WorkflowParams(BaseModel):
|
||||
prompt: str
|
||||
negativePrompt: str = "text, watermark"
|
||||
checkpoints: List[str]
|
||||
loras: List[Lora] = []
|
||||
steps: int = 20
|
||||
seed: int = None
|
||||
width: int = 512
|
||||
height: int = 512
|
||||
|
||||
# Workflow definition
|
||||
class TestWorkflow(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.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': self.params.model_dump()
|
||||
}
|
||||
|
||||
# Module-level entry point
|
||||
def run_workflow(**kwargs):
|
||||
"""Entry point for the workflow."""
|
||||
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)
|
||||
|
||||
# Create and run workflow
|
||||
workflow = TestWorkflow(params)
|
||||
return workflow.run()
|
||||
@@ -1,42 +0,0 @@
|
||||
"""
|
||||
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
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
"""
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user