Generate Stunning Images with the crdbello/cblabs Cognitive Actions

22 Apr 2025
Generate Stunning Images with the crdbello/cblabs Cognitive Actions

In today's digital world, the ability to create customized images quickly and efficiently is more important than ever. The crdbello/cblabs Cognitive Actions provide powerful tools for developers looking to harness image generation capabilities in their applications. Among these actions is the ability to generate variations of an existing image based on specific parameters and text prompts, enabling a high degree of customization. This article will guide you through the Generate Image Variations action, outlining its purpose, input requirements, and how to integrate it into your projects.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • A basic understanding of JSON structure and HTTP requests.

Authentication typically works by passing your API key in the request headers, allowing secure access to the services.

Cognitive Actions Overview

Generate Image Variations

The Generate Image Variations action allows developers to create multiple variations of a specified image by leveraging text prompts and customizable parameters. This function supports various options, such as controlling the output dimensions, adjusting the focus on the prompt, and excluding unwanted elements.

Input

The input for this action requires a schema that includes the following fields:

  • image (required): A complete URI to the initial image for generating variations.
  • prompt: A text description guiding the characteristics of the generated image.
  • width: (optional) The output image width in pixels.
  • height: (optional) The output image height in pixels.
  • guidanceScale: (optional) A floating-point number (1-20) dictating how closely the model should follow the prompt.
  • negativePrompt: (optional) A list of undesired elements to avoid in the output image.
  • numberOfOutputs: (optional) Specifies how many variations to generate (1-8).
  • denoisingStrength: (optional) A value (0.0-1.0) indicating how much alteration should be applied to the original image.
  • numberOfInferenceSteps: (optional) The number of steps for sampling, affecting output detail (1-500).

Example Input:

{
  "image": "https://replicate.delivery/pbxt/LupkwIU1wHMZkI87Mirg7XCVtonyYB8UOM3nwKWnO71yQTDz/bedroom_4.webp",
  "prompt": "photorealistic standard bedroom, queen bed centered against wall with crisp bedding, tucked bedding, matching wooden nightstands, standard table lamps, neutral area rug, standard wall art",
  "guidanceScale": 15,
  "negativePrompt": "lowres, watermark, banner, logo, watermark, contactinfo, text, deformed, blurry, blur, out of focus, out of frame, surreal, extra, ugly, upholstered walls, fabric walls, plush walls, mirror, mirrored, functional, realistic",
  "numberOfInferenceSteps": 50
}

Output

The output of this action typically returns an array of URLs pointing to the generated image variations. Here is an example of what you might receive:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/f49852d8-1f58-4d9a-8cb0-8d9fec0ba968/922f9513-213e-4851-a49d-0759c1b4df0f.png"
]

Conceptual Usage Example (Python)

Here’s how you might invoke the Generate Image Variations action using Python. This code snippet illustrates the structure of the request, including the input payload:

import requests
import json

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

action_id = "1d5e6b44-ebac-4207-ab85-eb440ca62f1b"  # Action ID for Generate Image Variations

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/LupkwIU1wHMZkI87Mirg7XCVtonyYB8UOM3nwKWnO71yQTDz/bedroom_4.webp",
    "prompt": "photorealistic standard bedroom, queen bed centered against wall with crisp bedding, tucked bedding, matching wooden nightstands, standard table lamps, neutral area rug, standard wall art",
    "guidanceScale": 15,
    "negativePrompt": "lowres, watermark, banner, logo, watermark, contactinfo, text, deformed, blurry, blur, out of focus, out of frame, surreal, extra, ugly, upholstered walls, fabric walls, plush walls, mirror, mirrored, functional, realistic",
    "numberOfInferenceSteps": 50
}

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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID is specified, and the input payload is structured according to the requirements of the Generate Image Variations action.

Conclusion

The Generate Image Variations action from the crdbello/cblabs Cognitive Actions suite enables developers to create tailored images efficiently. By understanding the input and output structures, as well as how to invoke the action programmatically, you can leverage this powerful tool to enhance your applications. Explore further use cases, such as integrating generated images into user interfaces or workflows, and unlock the full potential of image generation in your projects. Happy coding!