Create Stunning Images with the daanelson/training-2 Cognitive Actions

22 Apr 2025
Create Stunning Images with the daanelson/training-2 Cognitive Actions

In today's digital landscape, the ability to generate and manipulate images programmatically has transformed creative workflows. The daanelson/training-2 specification offers a powerful Cognitive Action designed for developers looking to integrate image generation capabilities into their applications. This action allows for the creation of images based on text prompts, with advanced features like inpainting, refinement styles, and customizable parameters. By leveraging these pre-built actions, you can save time and focus on building innovative applications.

Prerequisites

To get started with the Cognitive Actions provided by the daanelson/training-2 spec, you will need the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of JSON formatting and HTTP requests.

For authentication, you'll typically include your API key in the request headers as follows:

Authorization: Bearer YOUR_COGNITIVE_ACTIONS_API_KEY

Cognitive Actions Overview

Generate Image with Inpainting and Refinement

Description:
This operation generates an image based on a text prompt with options for inpainting areas, using a mask URI, and refining the output image with different refinement styles. It provides control over image dimensions, guidance scaling, and the number of outputs. The operation leverages scheduler algorithms and allows customization of prompt intensity and denoising steps.

Category: image-generation

Input

The input for this action is structured as a JSON object with several properties:

{
  "mask": "string (optional)",
  "seed": "integer (optional)",
  "image": "string (optional)",
  "width": "integer (default: 1024)",
  "height": "integer (default: 1024)",
  "prompt": "string (default: 'An astronaut riding a rainbow unicorn')",
  "refine": "string (default: 'no_refiner')",
  "scheduler": "string (default: 'DDIM')",
  "guidanceScaling": "number (default: 7.5)",
  "numberOfOutputs": "integer (default: 1)",
  "promptIntensity": "number (default: 0.8)",
  "refinementSteps": "integer (optional)",
  "highNoiseFraction": "number (default: 0.8)",
  "negativePromptText": "string (default: '')",
  "numberOfInferenceSteps": "integer (default: 50)"
}

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "An <s0> riding a rainbow unicorn",
  "refine": "expert_ensemble_refiner",
  "scheduler": "DDIM",
  "guidanceScaling": 7.5,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 50
}

Output

The output of this action typically returns a list of URIs pointing to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/89f52f49-8152-4e54-959e-e3398ae1581f/707660e8-8a48-42ff-9c79-a19f5c2fd102.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how a developer might invoke the Generate Image with Inpainting and Refinement action using a hypothetical Cognitive Actions execution endpoint.

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 = "bfba4b3a-fa71-436c-9fd1-952bff9c936d" # Action ID for Generate Image with Inpainting and Refinement

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "An <s0> riding a rainbow unicorn",
    "refine": "expert_ensemble_refiner",
    "scheduler": "DDIM",
    "guidanceScaling": 7.5,
    "numberOfOutputs": 1,
    "promptIntensity": 0.8,
    "highNoiseFraction": 0.8,
    "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 code:

  • The action_id corresponds to the specific action for generating images.
  • The payload is constructed according to the specified input schema, ensuring all necessary parameters are included.

Conclusion

The daanelson/training-2 Cognitive Action for image generation offers developers a versatile tool for creating and refining images based on textual prompts. With features like inpainting, customizable dimensions, and various refinement styles, this action can enhance applications in creative fields. Consider exploring further use cases, such as integrating this action into creative tools, social media applications, or content creation platforms, to fully leverage its capabilities. Happy coding!