Enhance Your Images with Sepal SDXL Inpainting Cognitive Actions

21 Apr 2025
Enhance Your Images with Sepal SDXL Inpainting Cognitive Actions

In the realm of image processing, the sepal/sdxl-inpainting specification empowers developers to leverage advanced AI capabilities for image modification. Specifically, the Perform Image Inpainting action utilizes the Stable Diffusion XL model from Huggingface, enabling users to seamlessly alter specified areas of an image based on a mask and a textual prompt. This opens up exciting possibilities for creative image manipulation, restoration, and enhancement.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which you will use to authenticate your requests.
  • A basic understanding of how to make HTTP requests and handle JSON payloads.

To authenticate, you will typically pass your API key in the request headers, ensuring that your calls to the Cognitive Actions API are secure.

Cognitive Actions Overview

Perform Image Inpainting

The Perform Image Inpainting action allows you to modify specific areas of an image, providing fine control over the changes through parameters such as prompts and guidance scales.

  • Category: Image Processing
  • Purpose: This action enables the modification of designated areas in an image based on a provided mask, allowing for creative alterations guided by a textual prompt.

Input

The input for this action must follow the defined schema, which includes the following fields:

{
  "mask": "https://replicate.delivery/pbxt/JTrIcNokOgIDb3Y5ouSvWmXf6iQAheTJG7UaTZGje2VBnbeh/overture-creations-5sI6fQgYIuo_mask.png",
  "image": "https://replicate.delivery/pbxt/JTrIcA5OpankV1HZfwXyEmmZLZKparZrmGjCMIKwYLiEUyTj/overture-creations-5sI6fQgYIuo.png",
  "prompt": "a tiger sitting on a park bench",
  "guidanceScale": 7.5,
  "promptStrength": 0.8,
  "numberOfInferenceSteps": 50
}
  • mask (string, required): URI of the mask image where areas in black will be preserved and areas in white will be altered.
  • image (string, required): URI for the input image used for inpainting.
  • prompt (string, optional): Textual prompt guiding the generation of the inpainted image. Default is "An astronaut riding a rainbow unicorn".
  • guidanceScale (number, optional): Influences the alteration degree; should be between 1 and 50. Default is 7.5.
  • negativePrompt (string, optional): Prompt to avoid during generation.
  • promptStrength (number, optional): Strength of the prompt when inpainting, ranging from 0 to 1, with a default of 0.8.
  • numberOfInferenceSteps (integer, optional): Number of denoising steps; must be between 1 and 500. Default is 50.

Output

Upon successful execution, this action returns a URI to the modified image:

"https://assets.cognitiveactions.com/invocations/4ca08c63-c6ae-4446-83c4-499255194c94/36fedd7b-1744-43b3-b6fb-3b319010189a.png"

This output links to the newly generated image, showcasing the alterations as specified by the mask and prompt.

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet illustrating how to call the Perform Image Inpainting action:

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 = "456abd0a-adee-433a-9e86-6b6a3321ac15"  # Action ID for Perform Image Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "mask": "https://replicate.delivery/pbxt/JTrIcNokOgIDb3Y5ouSvWmXf6iQAheTJG7UaTZGje2VBnbeh/overture-creations-5sI6fQgYIuo_mask.png",
    "image": "https://replicate.delivery/pbxt/JTrIcA5OpankV1HZfwXyEmmZLZKparZrmGjCMIKwYLiEUyTj/overture-creations-5sI6fQgYIuo.png",
    "prompt": "a tiger sitting on a park bench",
    "guidanceScale": 7.5,
    "promptStrength": 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, you'll notice that the action_id is set to the ID of the Perform Image Inpainting action, and the payload is constructed using the required input fields. The request is sent to a hypothetical endpoint, illustrating how to pass the input correctly.

Conclusion

The Perform Image Inpainting action within the sepal/sdxl-inpainting specification provides a powerful tool for developers looking to enhance images creatively. By leveraging this API, you can easily manipulate images based on user-defined prompts and masks, unlocking new possibilities in your applications. Explore further by integrating this action into your projects or experimenting with different prompts and parameters to see the potential of AI-driven image enhancements!