Create Iconic Images with Wallace & Gromit Using SDXL Actions

24 Apr 2025
Create Iconic Images with Wallace & Gromit Using SDXL Actions

In the realm of image generation, the SDXL model offers an exciting opportunity to create and refine images that encapsulate the beloved style of Wallace and Gromit. The Cognitive Actions provided under the marydotdev/sdxl-wg specification empower developers to leverage image inpainting and customization options, allowing for a unique blend of creativity and technology. With these pre-built actions, you can easily integrate powerful image generation capabilities into your applications.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which is required for authentication.
  • A basic understanding of JSON and how to structure API calls.

To authenticate your requests, you will typically pass the API key in the headers of your HTTP requests.

Cognitive Actions Overview

Inpaint and Generate Wallace & Gromit Style Images

This action allows you to utilize the SDXL model trained on Wallace and Gromit stills to generate and refine images. It features inpainting capabilities and customization through various scheduling and refinement options.

Input

The input for this action is structured as follows:

  • mask (string, optional): Input mask for inpaint mode. Black areas will be preserved, while white areas will be inpainted.
  • seed (integer, optional): Random seed value used for reproducibility. Leave blank to use a random seed each time.
  • image (string, optional): URI for the input image. Used in img2img or inpaint modes.
  • width (integer, default: 1024): Width of the output image in pixels.
  • height (integer, default: 1024): Height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): A text prompt guiding the generated image.
  • refine (string, default: "no_refiner"): Select the refinement style to apply.
  • loraScale (number, default: 0.6): Scale for LoRA application, valid between 0 and 1.
  • scheduler (string, default: "K_EULER"): Select the scheduling algorithm for image generation.
  • numOutputs (integer, default: 1): Number of images to generate (1 to 4).
  • loraWeights (string, optional): Specify the LoRA weights file to use.
  • refineSteps (integer, optional): Number of refinement steps for 'base_image_refiner'.
  • guidanceScale (number, default: 7.5): Influences the prompt during generation (1 to 50).
  • highNoiseFrac (number, default: 0.8): Fraction of noise in 'expert_ensemble_refiner'.
  • applyWatermark (boolean, default: true): Apply a watermark to indicate image generation.
  • negativePrompt (string, optional): Elements to avoid in the generated image.
  • promptStrength (number, default: 0.8): Strength of the input prompt in img2img and inpaint modes.
  • numInferenceSteps (integer, default: 50): Specify the number of denoising steps (1 to 500).
  • disableSafetyChecker (boolean, default: false): Disable the safety checker for generated images.
Example Input

Here’s an example of the JSON input payload:

{
  "width": 1024,
  "height": 1024,
  "prompt": "a boy riding a bicycle in the style of TOK",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "numOutputs": 1,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numInferenceSteps": 50
}

Output

The action typically returns a URL of the generated image. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/44f52f90-7683-42da-a260-edb7469394ff/575f27a6-dc8a-46bc-9713-c6212e768a27.png"
]
Conceptual Usage Example (Python)

Here’s how you might invoke the "Inpaint and Generate Wallace & Gromit Style 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 = "c4f5ae21-8bcb-41b8-ab6a-e3fbc29d3b38"  # Action ID for Inpaint and Generate Wallace & Gromit Style Images

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "a boy riding a bicycle in the style of TOK",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "numOutputs": 1,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": True,
    "negativePrompt": "",
    "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 code snippet, you will see how to structure the input payload and specify the action ID. The endpoint URL and request structure are illustrative, so make sure to adapt them according to your application's needs.

Conclusion

The Cognitive Actions under the marydotdev/sdxl-wg specification offer a powerful way to generate and refine images in the iconic style of Wallace and Gromit. By utilizing the capabilities of the SDXL model, developers can create unique visual content and incorporate image generation seamlessly into their applications. Explore these actions further to unlock creative possibilities in your projects!