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
@@ -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()
|
||||
Reference in new issue
Block a user