Generate Stunning Images with pnyompen/sdxl-controlnet-lora-small Cognitive Actions

23 Apr 2025
Generate Stunning Images with pnyompen/sdxl-controlnet-lora-small Cognitive Actions

In the world of AI-driven creativity, the pnyompen/sdxl-controlnet-lora-small API offers powerful Cognitive Actions that allow developers to generate images with remarkable detail and control. By leveraging SDXL Canny ControlNet with LoRA support, these actions enable intricate image creation through adjustable parameters, making it easier than ever to transform ideas into visuals. Whether you are looking to create entirely new images or modify existing ones, this guide will walk you through how to effectively integrate these Cognitive Actions into your applications.

Prerequisites

Before you dive into the integration, ensure you have the following set up:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON and RESTful API calls.

Authentication typically involves passing your API key in the request headers, allowing secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Image with SDXL Canny ControlNet

Description: This action allows you to generate images using the SDXL Canny ControlNet with LoRA support. It provides detailed control over the image generation process through various adjustable parameters, including denoising strength, guidance scale, and the number of outputs. The action also supports image-to-image (img2img) transformations and background removal.

Category: image-generation

Input

The following JSON schema outlines the required and optional fields for the action:

{
  "image": "https://replicate.delivery/pbxt/JiOTMCHj4oGrTTf8Pg2r7vyI8YdXc5jL2IDyC2SfhuggjYe6/out-0%20%281%29.png",
  "prompt": "shot in the style of sksfer, a woman in alaska",
  "img2img": false,
  "strength": 0.8,
  "scheduler": "K_EULER",
  "loraWeights": "https://pbxt.replicate.delivery/mwN3AFyYZyouOB03Uhw8ubKW9rpqMgdtL9zYV9GF2WGDiwbE/trained_model.tar",
  "guidanceScale": 7.5,
  "conditionScale": 0.5,
  "negativePrompt": "",
  "numberOfOutputs": 1,
  "loraAdditiveScale": 0.95,
  "numInferenceSteps": 40,
  "autoGenerateCaption": false
}
  • Required Fields:
    • image: URL of the input image for img2img or inpainting mode.
    • prompt: Text description to guide the image generation.
    • numberOfOutputs: Number of images to be generated (1 to 4).
  • Optional Fields:
    • seed: Random seed for reproducibility.
    • img2img: Boolean to indicate whether to use img2img mode.
    • strength: Denoising strength for img2img mode (0 to 1).
    • scheduler: The scheduling algorithm for denoising.
    • loraWeights: URL for LoRA weights.
    • guidanceScale: Scale for classifier-free guidance (1 to 50).
    • conditionScale: ControlNet influence scale (0 to 2).
    • negativePrompt: Elements to avoid in the generated image.
    • loraAdditiveScale: Additive scale for LoRA (-2 to 2).
    • numInferenceSteps: Total steps for the denoising process (1 to 500).
    • autoGenerateCaption: Use BLIP for automatic captioning.

Output

Upon successful execution, the action returns a list of URLs pointing to the generated images. Here's an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/4c1f9467-6364-42be-829f-7909703b19d8/3bc051ef-53bf-4311-9684-0668837aceb4.webp"
]

Conceptual Usage Example (Python)

Here's how you could call the Generate Image 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 = "cd90d457-2ad9-4fda-86f3-6a48d41485a6" # Action ID for Generate Image with SDXL Canny ControlNet

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/JiOTMCHj4oGrTTf8Pg2r7vyI8YdXc5jL2IDyC2SfhuggjYe6/out-0%20%281%29.png",
    "prompt": "shot in the style of sksfer, a woman in alaska",
    "img2img": False,
    "strength": 0.8,
    "scheduler": "K_EULER",
    "loraWeights": "https://pbxt.replicate.delivery/mwN3AFyYZyouOB03Uhw8ubKW9rpqMgdtL9zYV9GF2WGDiwbE/trained_model.tar",
    "guidanceScale": 7.5,
    "conditionScale": 0.5,
    "negativePrompt": "",
    "numberOfOutputs": 1,
    "loraAdditiveScale": 0.95,
    "numInferenceSteps": 40,
    "autoGenerateCaption": False
}

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}
    )
    response.raise_for_status()  # Raise an exception for bad status codes

    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 the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id is set to the ID of the Generate Image action.
  • The payload object is structured according to the input schema, ensuring you provide the necessary parameters for the image generation.

Conclusion

The pnyompen/sdxl-controlnet-lora-small Cognitive Actions empower developers to create stunning visuals with ease and precision. By integrating these actions into your applications, you can unlock a new level of creativity, whether for content generation, design, or enhancing existing images. Explore the potential of image generation and take your projects to the next level!