Create Stunning Visuals with the andrewg4/sdxl-harold Cognitive Actions

21 Apr 2025
Create Stunning Visuals with the andrewg4/sdxl-harold Cognitive Actions

In the world of digital creativity, the andrewg4/sdxl-harold API offers powerful Cognitive Actions that enable developers to generate AI-enhanced images effortlessly. By utilizing advanced techniques such as inpainting and img2img, along with customizable parameters, these actions empower developers to create stunning visuals that cater to various artistic needs. In this article, we'll explore how to integrate and leverage these capabilities in your applications.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform, which will allow you to authenticate your requests.
  • Basic familiarity with making HTTP requests and handling JSON data in your application.

Authentication typically involves passing your API key in the request headers to ensure secure access to the actions.

Cognitive Actions Overview

Generate AI-Enhanced Images

This action generates AI-enhanced images through inpainting and img2img techniques, guided by text prompts. It provides options for customizing the output, such as image size, style refinement, and various tuning parameters, allowing for artistic exploration.

  • Category: Image Generation

Input

The input schema for this action includes a variety of fields, some of which are optional. Here’s a breakdown of the required and optional inputs based on the schema:

{
  "prompt": "string",             // Required - Description of the desired output.
  "width": 1024,                 // Optional - Width of the output image in pixels (default is 1024).
  "height": 1024,                // Optional - Height of the output image in pixels (default is 1024).
  "numberOfOutputs": 1,          // Optional - Number of images to generate (1 to 4, default is 1).
  "guidanceScale": 7.5,          // Optional - Scale factor for classifier-free guidance (default is 7.5).
  "promptStrength": 0.8,          // Optional - Strength of the prompt's influence (0 to 1, default is 0.8).
  "scheduler": "K_EULER",        // Optional - Algorithm for scheduling the process (default is 'K_EULER').
  "loraScale": 0.6,              // Optional - Scaling factor for LoRA adjustments (0 to 1, default is 0.6).
  "applyWatermark": true,        // Optional - Whether to apply a watermark to the images (default is true).
  "negativePrompt": "",          // Optional - Aspects to avoid in the generated image.
  "numberOfDenoisingSteps": 50,  // Optional - Number of denoising steps (default is 50).
  "highNoiseFraction": 0.8,      // Optional - Fraction of noise for refinement (default is 0.8).
  "refineStyle": "no_refiner"    // Optional - Style for refinement (default is 'no_refiner').
}

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "TOK as Hary Potter with a magic stick",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numberOfDenoisingSteps": 50
}

Output

The output from this action is typically a URL pointing to the generated image. Here’s an example of the output you might receive:

[
  "https://assets.cognitiveactions.com/invocations/2fdb28fd-6254-4c40-8829-a32e5e59dde2/b1eb9d02-594a-4e65-ae38-e1f9fd9e0510.png"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate AI-Enhanced Images 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 = "cd435f8e-3ac7-450b-8111-f8a0e1b4b685"  # Action ID for Generate AI-Enhanced Images

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "TOK as Hary Potter with a magic stick",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": true,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "numberOfDenoisingSteps": 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 the example above, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured based on the input requirements for generating an AI-enhanced image.

Conclusion

The andrewg4/sdxl-harold Cognitive Actions offer developers robust tools for creating high-quality images enriched by AI techniques. With customizable parameters and flexible options, integrating these actions into your applications can significantly enhance your creative projects. Explore the possibilities, and start generating stunning visuals today!