Enhance Your Applications with Image Generation Using DKEEE Cognitive Actions

25 Apr 2025
Enhance Your Applications with Image Generation Using DKEEE Cognitive Actions

In today's digital landscape, the ability to create and manipulate images programmatically opens up a world of possibilities for developers. The DKEEE Cognitive Actions provide a powerful solution for generating images through predictive inpainting with various customization options. These pre-built actions enable developers to leverage advanced image generation capabilities seamlessly, enhancing applications across various domains like art, marketing, and design.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of making HTTP requests and handling JSON data in your programming language of choice.

To authenticate, you typically need to include your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image with Predictive Inpainting

The Generate Image with Predictive Inpainting action allows you to create images based on a textual prompt, with options for customization such as aspect ratio, output format, and image quality. This action is categorized under image generation and supports both fast and detailed models tailored to your needs.

Input

The input for this action follows a schema that requires a prompt and offers various optional fields. Here’s a breakdown:

  • Required:
    • prompt (string): A textual description of the image you want to create. For instance, "A closeup headshot of DKEEE being interviewed on 60 Minutes."
  • Optional:
    • mask (string): URI of an image mask for inpainting mode.
    • seed (integer): For reproducible results.
    • image (string): URI of an input image for transformations.
    • width (integer): Width of the generated image (only if aspect_ratio is custom).
    • height (integer): Height of the generated image (only if aspect_ratio is custom).
    • goFast (boolean): Enable a speed-optimized model.
    • modelType (string): Choose between 'dev' and 'schnell' models.
    • numOutputs (integer): Number of outputs to generate (default is 1).
    • guidanceScale (number): Scale factor for guidance during generation.
    • outputQuality (integer): Quality of output images (0 to 100).
    • And several others related to LoRA weights and scaling.

Here's an example of the input JSON payload:

{
  "goFast": false,
  "prompt": "A closeup headshot of DKEEE being interviewed on 60 Minutes.",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 28
}

Output

The action typically returns a list of URLs pointing to the generated images. Here’s a sample output structure:

[
  "https://assets.cognitiveactions.com/invocations/25e2d042-5639-4127-a2f0-9ac197867407/ea7f612e-832b-4ccf-8e41-aff5105204b9.jpg"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to call the DKEEE 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 = "3b02c7f2-3ce0-4739-9552-7c9d560372af" # Action ID for Generate Image with Predictive Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": false,
    "prompt": "A closeup headshot of DKEEE being interviewed on 60 Minutes.",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "jpg",
    "numInferenceSteps": 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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the action's requirements, including specifying the action ID and the inputs for image generation.

Conclusion

The DKEEE Cognitive Actions provide developers with the tools to harness advanced image generation technologies effortlessly. By integrating these actions into applications, you can create unique and compelling visual content tailored to your specific needs. Whether you are building marketing tools, artistic applications, or enhancing user experience, the possibilities are endless. Start experimenting with these capabilities today and unlock new creative potential in your projects!