Automate Image Processing with the kelvincai522/any-comfyui-workflow Actions

23 Apr 2025
Automate Image Processing with the kelvincai522/any-comfyui-workflow Actions

Integrating advanced image processing capabilities into your applications just got easier with the kelvincai522/any-comfyui-workflow cognitive actions. This set of actions allows developers to execute workflows defined in ComfyUI, enabling the transformation and generation of high-quality images from various input files. Features like optional seed randomization and cache management enhance the flexibility and control of your image processing tasks.

Prerequisites

To utilize the Cognitive Actions, you'll need an API key from the Cognitive Actions platform. This key should be included in the request headers for authentication. Ensure to set your headers appropriately when making API calls.

Cognitive Actions Overview

Execute ComfyUI Workflow

The Execute ComfyUI Workflow action allows you to run a ComfyUI workflow that processes input files, applies transformations, and generates high-quality output images in your desired format. This action falls under the category of image-processing.

Input

The input required for this action is structured as follows:

  • inputFile (string, required): This is the input image, video, tar, or zip file that you want to process. You can also use URLs in your JSON workflow.
  • outputFormat (string, optional): The format of the output images. Options include webp, jpg, and png. The default value is webp.
  • workflowJson (string, required): Your ComfyUI workflow in JSON format, which can be obtained from the ComfyUI interface.
  • outputQuality (integer, optional): The quality of the output images ranging from 0 to 100, where 100 is the best quality.
  • randomizeSeeds (boolean, optional): Indicates if the seeds should be randomized. Default is true.
  • forceResetCache (boolean, optional): Forces a reset of the cache before executing the workflow. Default is false.
  • returnTempFiles (boolean, optional): Indicates if temporary files should be returned for debugging purposes. Default is false.

Example Input:

{
  "outputFormat": "webp",
  "workflowJson": "{...}",  // Your JSON workflow here
  "outputQuality": 95,
  "randomizeSeeds": true,
  "forceResetCache": false,
  "returnTempFiles": false
}

Output

Upon successful execution, this action returns a URL to the generated output image. The response might look like this:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/4180511e-1c46-4095-a103-cdd46cb99fa5/62c60357-8d76-4426-9850-63322b39ace2.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Execute ComfyUI Workflow action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and hypothetical endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "99fd10af-b4b6-4d6a-80e7-7b75038dd033" # Action ID for Execute ComfyUI Workflow

# Construct the input payload based on the action's requirements
payload = {
    "outputFormat": "webp",
    "workflowJson": "{...}",  # Your JSON workflow here
    "outputQuality": 95,
    "randomizeSeeds": True,
    "forceResetCache": False,
    "returnTempFiles": False
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, replace the placeholder for workflowJson with your actual JSON workflow. The endpoint URL and request structure are illustrative and may differ based on actual implementation.

Conclusion

The kelvincai522/any-comfyui-workflow Cognitive Actions provide a robust framework for automating image processing tasks within your applications. By leveraging these pre-built actions, you can streamline the generation of high-quality images tailored to your specific workflows. Consider exploring additional functionalities and integrating them into your projects to enhance your image processing capabilities.