Unlock Image Generation with the Chopping Board Cognitive Actions

22 Apr 2025
Unlock Image Generation with the Chopping Board Cognitive Actions

In the realm of creative applications, the Chopping Board Cognitive Actions offer a robust solution for developers looking to generate images through innovative techniques. This API simplifies the process of image creation and manipulation, allowing developers to leverage inpainting capabilities effectively. By utilizing these pre-built actions, you can enhance your applications with dynamic image content, whether for artistic projects, product visualizations, or other creative endeavors.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with JSON format, as the input and output will be structured in JSON.
  • Basic knowledge of making HTTP requests in Python (or your preferred programming language).

To authenticate, you will typically pass the API key in the request headers.

Cognitive Actions Overview

Generate Image with Inpainting

This action generates images using sophisticated inpainting techniques, allowing for customization through various parameters such as masks, aspect ratios, and more. It supports two models—dev for detailed output and schnell for faster processing.

Input:

The input for this action follows the CompositeRequest schema. Here’s a breakdown:

  • Required:
    • prompt: The text prompt for generating the image.
  • Optional:
    • mask: URI for an image mask (overrides dimensions).
    • image: URI for an input image.
    • width: Width of the generated image (if custom aspect ratio).
    • height: Height of the generated image (if custom aspect ratio).
    • goFast: Enables faster predictions.
    • aspectRatio: Specifies the aspect ratio of the generated image.
    • numberOfOutputs: How many images to generate (1-4).
    • numberOfInferenceSteps: Steps for the diffusion process (1-50).
    • And several others that customize the image generation process.

Example Input:

{
  "prompt": "CPBOARD is a chopping board . an image of CPBOARD in its true size and colour with some veggies kept on it and a knife. Maintain the correct dimensions of CPBOARD",
  "aspectRatio": "1:1",
  "loraStrength": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 28
}

Output:

On execution, the action returns a URL to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/b06e16da-fbdb-4140-8385-b49ee6dc65c3/562c47ee-3a5d-4f49-a170-d777a3f85a43.webp"
]

Conceptual Usage Example (Python):

Here’s how you might structure a call to this action:

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 = "94b986ca-cbba-4716-b5f3-291050aa0549"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "CPBOARD is a chopping board . an image of CPBOARD in its true size and colour with some veggies kept on it and a knife. Maintain the correct dimensions of CPBOARD",
    "aspectRatio": "1:1",
    "loraStrength": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 28
}

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 the placeholder values with your actual API key and adjust the input payload as needed. The endpoint URL and request structure are illustrative, focusing on the action's capabilities.

Conclusion

The Chopping Board Cognitive Actions provide a powerful toolset for generating images through inpainting. By harnessing these actions, developers can easily integrate dynamic imagery into their applications, enhancing user experiences and enriching content offerings. Consider experimenting with the various parameters to find the optimal settings for your specific use cases, and take your image generation capabilities to the next level!