Enhance Your Image Generation with the FOFR/SDXL-ENID Cognitive Action

21 Apr 2025
Enhance Your Image Generation with the FOFR/SDXL-ENID Cognitive Action

In the realm of artificial intelligence and image generation, the FOFR/SDXL-ENID API offers a powerful set of pre-built Cognitive Actions designed to streamline and enhance the creative process. One standout action, Generate Inpainted Image, utilizes advanced inpainting techniques to manipulate images based on user-defined parameters. This article will guide you through understanding and integrating this Cognitive Action into your applications, highlighting its capabilities and how it can elevate your image generation projects.

Prerequisites

Before diving into the integration process, ensure you have the following prerequisites in place:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with making API requests in the programming language of your choice (e.g., Python).
  • Basic understanding of JSON structure, as the Cognitive Actions will require input and output in this format.

For authentication, you'll typically pass your API key in the headers of your requests, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows developers to create images by preserving specific areas defined by a mask and inpainting others. This action is particularly useful for artistic creation, image restoration, or when you want to modify images while keeping certain elements intact.

Input:

The input for this action is structured as a JSON object, adhering to the following schema:

{
  "mask": "string (uri)",
  "seed": "integer (optional)",
  "image": "string (uri)",
  "width": "integer (default: 1024)",
  "height": "integer (default: 1024)",
  "inputPrompt": "string (default: 'An astronaut riding a rainbow unicorn')",
  "modelWeights": "string (optional)",
  "scheduleType": "string (default: 'K_EULER')",
  "guidanceScale": "number (default: 7.5)",
  "applyWatermark": "boolean (default: true)",
  "numberOfOutputs": "integer (default: 1, range: 1-4)",
  "refinementSteps": "integer (optional)",
  "refinementStyle": "string (default: 'no_refiner')",
  "highNoiseFraction": "number (default: 0.8)",
  "loraAdditionScale": "number (default: 0.6)",
  "inputNegativePrompt": "string (default: '')",
  "inputPromptStrength": "number (default: 0.8)",
  "disableSafetyChecker": "boolean (default: false)",
  "numberOfInferenceSteps": "integer (default: 50)"
}

Here’s an example input JSON payload:

{
  "width": 1152,
  "height": 768,
  "inputPrompt": "Close-up illustration of person TOK named Enid, bobbed hair, large round glasses, black top with a skull design, and plaid skirt, on a city street, blurred background",
  "scheduleType": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "numberOfOutputs": 1,
  "refinementStyle": "expert_ensemble_refiner",
  "highNoiseFraction": 0.8,
  "loraAdditionScale": 0.4,
  "inputNegativePrompt": "warm tones, ugly, broken, distorted",
  "inputPromptStrength": 0.8,
  "numberOfInferenceSteps": 50
}

Output:

Upon successful execution, the action returns a URL pointing to the generated image:

[
  "https://assets.cognitiveactions.com/invocations/aa0a3517-7b8d-4e9a-9581-ffd37759d3ca/05d57342-700e-4fde-96bd-be0245543b52.png"
]

Conceptual Usage Example (Python):

Here’s how you can invoke 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 = "5a8dae1e-b0b0-4014-9bf9-dfb819c75539" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1152,
    "height": 768,
    "inputPrompt": "Close-up illustration of person TOK named Enid, bobbed hair, large round glasses, black top with a skull design, and plaid skirt, on a city street, blurred background",
    "scheduleType": "K_EULER",
    "guidanceScale": 7.5,
    "applyWatermark": False,
    "numberOfOutputs": 1,
    "refinementStyle": "expert_ensemble_refiner",
    "highNoiseFraction": 0.8,
    "loraAdditionScale": 0.4,
    "inputNegativePrompt": "warm tones, ugly, broken, distorted",
    "inputPromptStrength": 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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Generate Inpainted Image action. The constructed payload includes all necessary parameters to guide the image generation. The provided endpoint URL and request structure are illustrative; ensure you adapt them to your real API setup.

Conclusion

Integrating the Generate Inpainted Image action from the FOFR/SDXL-ENID API can significantly enhance your applications' image generation capabilities. By leveraging its powerful inpainting features, you can create visually stunning images tailored to your specific needs. Explore further use cases, experiment with the parameters, and unleash your creativity with this robust Cognitive Action!