Generate Stunning Images with the cbh123/sdxl-illusions Cognitive Actions

23 Apr 2025
Generate Stunning Images with the cbh123/sdxl-illusions Cognitive Actions

In the world of digital creativity, the ability to generate and manipulate images has taken center stage. The cbh123/sdxl-illusions API introduces an innovative set of Cognitive Actions designed to harness the power of image generation through sophisticated techniques like inpainting. These pre-built actions allow developers to create high-quality images tailored to specific needs, complete with customizable parameters for optimal control and output quality.

In this article, we will explore how to leverage these Cognitive Actions to enhance your applications with dynamic image generation capabilities.

Prerequisites

To get started with the Cognitive Actions in the cbh123/sdxl-illusions API, you will need an API key for authentication. This key should be passed in the headers of your requests. Ensure that you have the necessary permissions to access the actions you intend to use.

Cognitive Actions Overview

Generate Image with Inpainting

This action enables developers to generate images by applying inpainting techniques based on specified input masks. Users can dictate areas of the image to preserve or modify, allowing for creative flexibility and high-quality outputs.

  • Category: Image Generation

Input

The input for this action is structured as follows:

PropertyTypeDescription
maskstringThe URI of the input mask for inpainting (black areas preserved, white areas inpainted).
seedintegerRandom seed for image generation (optional).
imagestringThe URI of the input image for img2img or inpaint mode.
widthintegerThe width of the output image (default is 1024).
heightintegerThe height of the output image (default is 1024).
promptstringInput prompt guiding the image generation process (default: "An astronaut riding a rainbow unicorn").
refineStylestringStyle of refinement to use (options: 'no_refiner', 'expert_ensemble_refiner', 'base_image_refiner'; default: 'no_refiner').
applyWatermarkbooleanWhether to apply a watermark to the generated image (default: true).
numberOfOutputsintegerThe number of images to output (1 to 4; default: 1).
refinementStepsintegerNumber of refinement steps for 'base_image_refiner'.
schedulingMethodstringThe scheduling algorithm for image generation (default: 'K_EULER').
highNoiseFractionnumberFraction of noise for 'expert_ensemble_refiner' (must be between 0 and 1; default: 0.8).
loraAdditiveScalenumberThe LoRA additive scale (applicable only to trained models; should be between 0 and 1; default: 0.6).
guidanceScaleFactornumberScale for classifier-free guidance (must be between 1 and 50; default: 7.5).
inputPromptStrengthnumberStrength of the prompt when using img2img or inpaint (must be between 0 and 1; default: 0.8).
negativeInputPromptstringA negative prompt discouraging certain elements in the generated image.
numberOfInferenceStepsintegerTotal number of denoising steps to perform (must be between 1 and 500; default: 50).

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "an image in the style of TOK",
  "refineStyle": "no_refiner",
  "applyWatermark": true,
  "numberOfOutputs": 1,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.8,
  "loraAdditiveScale": 0.6,
  "guidanceScaleFactor": 7.5,
  "inputPromptStrength": 0.8,
  "numberOfInferenceSteps": 50
}

Output

Upon successful execution, the action typically returns a generated image as a URI:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/8268740e-ad4b-49b6-811c-96f131ffbab5/cbe529a4-bbe9-4b35-b38c-dee8f0434ba7.png"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet to demonstrate how you might call this 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 = "f273150c-372d-4344-81e7-493a1378935f"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "an image in the style of TOK",
    "refineStyle": "no_refiner",
    "applyWatermark": True,
    "numberOfOutputs": 1,
    "schedulingMethod": "K_EULER",
    "highNoiseFraction": 0.8,
    "loraAdditiveScale": 0.6,
    "guidanceScaleFactor": 7.5,
    "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 code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the defined requirements for the "Generate Image with Inpainting" action. This example demonstrates how to make a POST request to the Cognitive Actions execution endpoint, handling both success and error scenarios.

Conclusion

The cbh123/sdxl-illusions Cognitive Action for generating images with inpainting is a powerful tool for developers seeking to integrate advanced image generation capabilities into their applications. With a wide range of customizable options, you can create unique images tailored to specific requirements while ensuring ethical usage through watermarking.

Consider exploring additional use cases such as content generation, artistic creation, or even enhancing existing images by manipulating them with inpainting techniques. With these tools at your disposal, the possibilities are endless! Happy coding!