Create Stunning Images with the EOM Phase 2 Cognitive Actions

24 Apr 2025
Create Stunning Images with the EOM Phase 2 Cognitive Actions

In the world of digital creativity, the ability to generate and manipulate images efficiently is invaluable. The EOM Phase 2 Cognitive Actions provide developers with powerful tools to create inpainted images using customizable prompts and input masks. These pre-built actions simplify the integration of advanced image generation capabilities into your applications, enabling you to focus on innovation rather than the underlying complexities.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which enables authentication and access to the services.
  • Basic knowledge of JSON and API requests, as you'll be structuring input payloads in JSON format to interact with the Cognitive Actions.

Authentication typically involves passing the API key in the request headers, allowing you to securely make calls to the API.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create inpainted images by utilizing input masks alongside customizable prompts. It supports various refinement styles and scheduler types, making it a versatile option for developers looking to enhance their image manipulation capabilities.

Input

The required fields for this action are defined in the input_schema, with an example input payload shown below:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A full-body TOK game character on a green background, a cowboy octopus, empty background",
  "loraScale": 0.6,
  "numOutputs": 1,
  "refineStyle": "no_refiner",
  "scheduleType": "K_EULER",
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "out of frame, mutated, deformed, extras, sprites",
  "promptStrength": 0.8,
  "numInferenceSteps": 50
}
  • mask: (string) URI for the input mask in inpaint mode.
  • seed: (integer) Random seed for image generation.
  • image: (string) URI for the input image used in img2img or inpaint mode.
  • width: (integer) Width of the output image in pixels (default: 1024).
  • height: (integer) Height of the output image in pixels (default: 1024).
  • prompt: (string) Text prompt that guides the content of the output image.
  • numOutputs: (integer) Number of images to generate (must be between 1 and 4).
  • refineStyle: (string) Select the refinement style.
  • scheduleType: (string) Choose the type of scheduler.
  • guidanceScale: (number) Guidance scale for classifier-free guidance (range: 1 to 50).
  • promptStrength: (number) Strength of the prompt when using img2img or inpaint mode (range: 0 to 1).
  • applyWatermark: (boolean) Applies a watermark to generated images (default: true).
  • negativePrompt: (string) Text prompt to specify elements to avoid in the generated image.

Output

The action typically returns an array of generated image URLs. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/76dd53a1-90ab-490c-8cb4-d67318029138/dba9b2cb-bf5b-4a7d-a075-ac178e7b1e40.png"
]

This output provides direct access to the generated image, which can be utilized in your application as needed.

Conceptual Usage Example (Python)

Here’s how you might call the Generate Inpainted Image action using Python:

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 = "7c74d415-9a2a-4347-b0de-1bead705a66e"  # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A full-body TOK game character on a green background, a cowboy octopus, empty background",
    "loraScale": 0.6,
    "numOutputs": 1,
    "refineStyle": "no_refiner",
    "scheduleType": "K_EULER",
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": True,
    "negativePrompt": "out of frame, mutated, deformed, extras, sprites",
    "promptStrength": 0.8,
    "numInferenceSteps": 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, you need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload is structured according to the action's requirements, and the action ID corresponds to the Generate Inpainted Image action.

Conclusion

The EOM Phase 2 Cognitive Actions empower developers to create stunning images effortlessly with advanced features tailored for image generation. By integrating these actions into your applications, you can unlock new creative possibilities and enhance user experiences. Whether you’re looking to create unique artwork or enhance existing images, these Cognitive Actions provide a robust solution. Explore the potential and start innovating today!