Enhance Image Quality with ComfyUI Image Prediction Actions

26 Apr 2025
Enhance Image Quality with ComfyUI Image Prediction Actions

In the rapidly evolving landscape of digital imagery, developers are continuously seeking ways to enhance image quality and optimize rendering processes. The ComfyUI API offers powerful Cognitive Actions that enable seamless image predictions with advanced techniques, ensuring high-resolution and ultra-detailed photo realism. By leveraging ComfyUI's capabilities, developers can simplify their workflows, reduce processing times, and achieve stunning visual results.

This article will delve into the specific action available within ComfyUI, focusing on its purpose, input requirements, expected outputs, and practical use cases. Whether you're looking to automate image enhancements or create intricate visual compositions, ComfyUI's image prediction actions are designed to meet your needs.

Prerequisites

To get started with ComfyUI's Cognitive Actions, you'll need an API key from the ComfyUI service and a basic understanding of how to make API calls.

Execute ComfyUI Image Prediction

The Execute ComfyUI Image Prediction action is designed to utilize the ComfyUI workflow for executing image predictions with an emphasis on optimizing image quality and efficient sampling. This action solves the problem of achieving high-quality image outputs through advanced rendering techniques.

Input Requirements

The input for this action requires the following:

  • Input File: A URI pointing to the input image, tar, or zip file. You can also use URLs in your JSON workflow for automatic downloading by the model.
  • Workflow JSON: A JSON representation of your ComfyUI workflow, which must be in the correct API format.
  • Randomize Seeds: A boolean to automatically randomize seed values for stochastic operations, defaulting to true.
  • Return Temp Files: A boolean that, when true, will return temporary files for debugging purposes, defaulting to false.

Expected Output

The expected output includes:

  • A list of files generated as a result of the image prediction.
  • A detailed structure of results, indicating the images produced, their types (output or temp), and filenames.

Use Cases for this Specific Action

  • Automated Image Enhancement: Developers can use this action to automatically enhance images in bulk, saving time and ensuring consistency across a project.
  • Creative Compositions: This action is ideal for artists and designers looking to create intricate visual pieces with high detail and realism.
  • Debugging and Testing: The ability to return temporary files aids in debugging workflows, allowing developers to fine-tune their processes and achieve optimal results.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "54717b42-830f-49c2-8fc7-cd6ff66a1d50" # Action ID for: Execute ComfyUI Image Prediction

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "workflowJson": "{\"19\":{\"inputs\":{\"filename_prefix\":\"ComfyUI\",\"images\":[\"60\",5]},\"class_type\":\"SaveImage\",\"_meta\":{\"title\":\"Save Image\"}},\"60\":{\"inputs\":{\"seed\":508755962671027,\"steps\":25,\"cfg\":4,\"sampler_name\":\"dpmpp_2m_sde_gpu\",\"scheduler\":\"karras\",\"denoise\":1,\"preview_method\":\"auto\",\"vae_decode\":\"true\",\"sharpness\":2,\"model\":[\"61\",0],\"positive\":[\"61\",1],\"negative\":[\"61\",2],\"latent_image\":[\"61\",3],\"optional_vae\":[\"61\",4],\"script\":[\"64\",0]},\"class_type\":\"Fooocus_KSamplerEfficient\",\"_meta\":{\"title\":\"KSampler Efficient Fooocus\"}},\"61\":{\"inputs\":{\"ckpt_name\":\"ArcadeXL_v0.1.safetensors\",\"vae_name\":\"Baked VAE\",\"clip_skip\":-2,\"lora_name\":\"Arcade-Lora_v0.1.safetensors\",\"lora_model_strength\":0.25,\"lora_clip_strength\":1,\"positive\":\"architecture rendering, beautiful composition, scenery, best quality, ultra-detailed, high resolution, realistic photography with natural light and high contrast, cinematic 8k, architectural rendering, unreal engine 5, rtx, volumetric light, masterpiece\",\"negative\":\" (Easy Negtive:1.4), (worst quality: 1.4), (low quality:1.4), (normal quality:1.4), nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers,extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, messy, bad chair, bad machine, bad lighting_cigarette, \",\"token_normalization\":\"none\",\"weight_interpretation\":\"A1111\",\"empty_latent_width\":1344,\"empty_latent_height\":768,\"batch_size\":1},\"class_type\":\"Efficient Loader\",\"_meta\":{\"title\":\"Efficient Loader\"}},\"64\":{\"inputs\":{\"rng_source\":\"gpu\",\"cfg_denoiser\":false,\"add_seed_noise\":false,\"seed\":-1,\"weight\":0.015},\"class_type\":\"Noise Control Script\",\"_meta\":{\"title\":\"Noise Control Script\"}}}",
  "randomizeSeeds": true,
  "returnTempFiles": false
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

ComfyUI's Cognitive Actions, particularly the Execute ComfyUI Image Prediction, provide developers with powerful tools to enhance image quality and streamline workflows. By automating processes and utilizing advanced rendering techniques, users can achieve stunning results that meet the demands of modern visual projects.

As a next step, explore the various workflows you can create with ComfyUI and consider integrating these actions into your applications for enhanced image processing capabilities. Dive into the documentation to unlock the full potential of ComfyUI and elevate your image creation processes.