Chaoses-Ib / ComfyScript

A Python frontend and library for ComfyUI
MIT License
369 stars 20 forks source link

Using workflows with input nodes #62

Open DiffusionDen opened 1 month ago

DiffusionDen commented 1 month ago

Hi, I'm wanting to set up my workflows so that they have input nodes like the image attached. The problem is that when the transpiler is naming the varables, they just appear as int, string, float etc.

I wanted to set it up like this so I can run the transpile output through more scripts to set up things like dynamically adding UI elements to the web interface I'm creating to control them.

Here's my workflow:

image

Which outputs as:

string = ACEText('')
int = ACEInteger(-1)
int2 = ACEInteger(25)
float = ACEFloat(6.5)
model, clip, vae = CheckpointLoaderSimple(r'pony\autismmixSDXL_autismmixConfetti.safetensors')
string2 = ACEText('')
conditioning = CLIPTextEncode(string2, clip)
string3 = ACEText('')
conditioning2 = CLIPTextEncode(string3, clip)
int3 = ACEInteger(1024)
int4 = ACEInteger(1024)
int5 = ACEInteger(1)
latent = EmptyLatentImage(int3, int4, int5)
latent = KSampler(model, int, int2, float, 'dpmpp_2m', 'karras', conditioning, conditioning2, latent, 1)
image = VAEDecode(latent, vae)
SaveImage(image, string)

I know I could go through and edit them manually, but I'm planning on adding a large amount of workflows to my site. Do you have any suggestions on how I could get it to work in a more automatic way?

Chaoses-Ib commented 1 month ago

I can add a method for transpiler to get inputs. But there are still ohter problems: how does one modify them? And after running the workflow, how does one get the outputs? Ideally, this should be a workflow class:

@dataclass
class WorkflowInput:
    class_type: str
    node_name: str
    default_value: Any

@dataclass
class WorkflowOutput:
    class_type: str
    node_name: str
    value: Any

class TranspiledWorkflow:
    def inputs(self) -> list[WorkflowInput]:
        pass

    def run(self, inputs: list[Any]) -> list[WorkflowOutput]:
        int, int2, float, ... = inputs
        ...

However, I'm not sure if transpiling is really needed in your case. If you don't need to edit the workflow, maybe directly using the API format JSON is easier? Parsing the inputs and outputs is not hard for API format.