Enhance Your Images with Cognitive Actions from fofr/sdxl-levon

24 Apr 2025
Enhance Your Images with Cognitive Actions from fofr/sdxl-levon

In the world of digital content creation, the ability to quickly generate and enhance images is invaluable. The fofr/sdxl-levon specification offers a powerful Cognitive Action for image generation called Generate Enhanced Image with Inpainting. This action leverages an advanced image generation model to create or enhance images with customizable parameters, allowing developers to integrate sophisticated image manipulation capabilities into their applications seamlessly.

Prerequisites

Before you can start using the Cognitive Actions, ensure you have the following:

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform. This is typically passed in the request headers.
  • Cognitive Actions Endpoint: Familiarize yourself with the base URL for invoking the actions, as this will be essential for making API calls.

Cognitive Actions Overview

Generate Enhanced Image with Inpainting

The Generate Enhanced Image with Inpainting action enables the creation or enhancement of images by utilizing an advanced model. It provides options for inpainting, refined styling, and various customizable parameters, including size, prompt strength, and guidance scale.

Input

The input for this action is defined by a structured schema. Below are the key fields:

  • mask (string, required): URI for the input mask used in inpaint mode. Areas colored black will remain unchanged, while white areas will be inpainted.
  • width (integer, default: 1024): Specifies the width of the output image in pixels.
  • height (integer, default: 1024): Specifies the height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): Text input prompt to guide image generation.
  • refine (string, default: "no_refiner"): Select the refinement style.
  • loraScale (number, default: 0.6): LoRA additive scale parameter, applicable only on trained models.
  • inputImage (string): URI of the input image for img2img or inpaint modes.
  • randomSeed (integer): Specifies the random seed for image generation.
  • numberOfOutputs (integer, default: 1): How many images should be generated.

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

{
  "width": 1152,
  "height": 768,
  "prompt": "A TOK photo, extreme macro of an alien eye",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduleType": "K_EULER",
  "guidanceScale": 7.5,
  "inferenceSteps": 30,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "watermarkEnabled": false,
  "highNoiseFraction": 0.8,
  "negativeInputPrompt": ""
}

Output

The output typically consists of a list of generated image URIs. An example output for this action could look like:

[
  "https://assets.cognitiveactions.com/invocations/5a78e56b-9cda-4a82-9f9c-cc8611b4997e/67a85752-bc92-4d02-80b1-0f3034fefe4a.png"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Enhanced Image with Inpainting action using Python. This code demonstrates structuring the input JSON payload correctly:

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 = "0c162f86-785f-490a-8502-ba74fbd316ca"  # Action ID for Generate Enhanced Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1152,
    "height": 768,
    "prompt": "A TOK photo, extreme macro of an alien eye",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduleType": "K_EULER",
    "guidanceScale": 7.5,
    "inferenceSteps": 30,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "watermarkEnabled": False,
    "highNoiseFraction": 0.8,
    "negativeInputPrompt": ""
}

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:

  • The action_id corresponds to the Generate Enhanced Image with Inpainting action.
  • The payload is built according to the input schema provided above, ensuring that all necessary parameters are included.

Conclusion

The Generate Enhanced Image with Inpainting action from the fofr/sdxl-levon specification opens up exciting possibilities for developers looking to enhance their applications with advanced image generation capabilities. Whether you're creating unique artwork, enhancing existing images, or experimenting with new styles, this action provides a robust solution. Consider exploring more use cases and experimenting with different parameters to fully leverage the potential of Cognitive Actions in your projects. Happy coding!