Generate Customized Images with Cognitive Actions for Supervision-2020/jcesar

21 Apr 2025
Generate Customized Images with Cognitive Actions for Supervision-2020/jcesar

In the realm of AI-driven creativity, the supervision-2020/jcesar specification offers developers powerful Cognitive Actions designed to generate customized images efficiently and effectively. Among these actions, one stands out for its advanced capabilities: Generate Customized Image with Inpainting. This action utilizes sophisticated inpainting techniques, allowing users to define various image properties while delivering high-quality outputs. In this article, we will explore how to integrate this action into your applications, highlighting its features, inputs, outputs, and providing a conceptual usage example.

Prerequisites

Before diving into the integration of the Cognitive Actions, you will need to ensure that you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic familiarity with sending HTTP requests and handling JSON data.
  • A programming environment set up for making API calls, such as Python with the requests library.

Authentication typically involves passing your API key in the headers of your requests, allowing you to access the Cognitive Actions services securely.

Cognitive Actions Overview

Generate Customized Image with Inpainting

The Generate Customized Image with Inpainting action is designed to produce high-quality images by allowing for specific customizations, including aspect ratios, formats, and LoRA weights. By leveraging both the 'dev' and 'schnell' models, this action provides flexibility in speed and inference quality.

Input

The input for this action adheres to the following schema:

{
  "prompt": "string",
  "mask": "string (optional, URI)",
  "image": "string (optional, URI)",
  "width": "integer (optional, 256-1440)",
  "height": "integer (optional, 256-1440)",
  "goFast": "boolean (optional, default: false)",
  "seed": "integer (optional)",
  "aspectRatio": "string (default: '1:1')",
  "numOutputs": "integer (default: 1, 1-4)",
  "outputFormat": "string (default: 'webp')",
  "guidanceScale": "number (default: 3)",
  "outputQuality": "integer (default: 80, 0-100)",
  "loraScale": "number (default: 1, -1-3)",
  "extraLoraScale": "number (default: 1, -1-3)",
  "promptStrength": "number (default: 0.8, 0-1)",
  "imageMegapixels": "string (default: '1')",
  "numInferenceSteps": "integer (default: 28, 1-50)",
  "disableSafetyChecker": "boolean (default: false)"
}

Here’s a practical example of the JSON payload needed to invoke this action:

{
  "goFast": false,
  "prompt": "JULIO dancing in the middle of a crowd at a wedding",
  "loraScale": 0.95,
  "modelType": "dev",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 2.85,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numInferenceSteps": 26
}

Output

Upon successful execution, the action returns a JSON array containing the URIs of the generated images. Here is an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/e5cc764d-1e48-456b-87ae-27ff70c8d138/5d3aefc2-1077-4afd-a22b-dd871d5fa987.webp"
]

This array includes a link to the generated image, which you can then use as needed in your application.

Conceptual Usage Example (Python)

Here’s how a developer might call the Cognitive Actions execution endpoint in 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 = "db176f22-85c1-4644-b3a2-deca98708203" # Action ID for Generate Customized Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": false,
    "prompt": "JULIO dancing in the middle of a crowd at a wedding",
    "loraScale": 0.95,
    "modelType": "dev",
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 2.85,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "numInferenceSteps": 26
}

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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload is structured according to the action's requirements, and the results are printed in a formatted manner.

Conclusion

The Generate Customized Image with Inpainting action from the supervision-2020/jcesar specification offers developers an incredible tool for generating tailored images with high precision and quality. By leveraging this Cognitive Action, you can easily integrate advanced image generation capabilities into your applications, enhancing user experiences and creative possibilities. Whether you are automating content creation or exploring new design avenues, this action serves as a valuable asset in your development toolkit.

Start experimenting with this action today and unlock the full potential of AI-driven image generation!