Unlocking Creativity: Integrate SDXL Lightning Image Generation with Cognitive Actions

Cognitive Actions within the lucataco/sdxl-lightning-multi-controlnet specification provide developers with a powerful toolset for advanced image generation. Leveraging the SDXL lightning model, these actions enable functionalities like image-to-image transformation, inpainting, and the application of concurrent ControlNet configurations. By integrating these pre-built actions into your application, you can effortlessly create stunning visuals tailored to your specific needs.
Prerequisites
To get started with Cognitive Actions, you'll need to obtain an API key from the Cognitive Actions platform. This key will be used to authenticate your requests. Typically, you would pass the API key in the headers of your API calls.
Cognitive Actions Overview
Execute SDXL Lightning Image Generation
The Execute SDXL Lightning Image Generation action is designed to produce high-quality images using the SDXL lightning model. It supports multiple features including img2img, inpainting, and the ability to apply up to three different ControlNet configurations. This action not only allows for detailed customization of image parameters but also gives flexibility in how images are generated and refined.
Category: Image Generation
Input
The input for this action includes a variety of optional and required fields, which allow for extensive customization of the generated images. Here’s a breakdown of the input schema along with an example:
{
"width": 1024,
"height": 1024,
"prompt": "extreme macro photo of a golden astronaut riding a unicorn statue, in a museum, bokeh, 50mm",
"numOutputs": 1,
"refineStyle": "no_refiner",
"controlnetOne": "soft_edge_hed",
"controlnetTwo": "none",
"guidanceScale": 0,
"applyWatermark": true,
"negativePrompt": "worst quality, low quality",
"promptStrength": 0.8,
"resizeStrategy": "width_height",
"controlnetThree": "none",
"controlnetOneEnd": 1,
"controlnetTwoEnd": 1,
"numInferenceSteps": 4,
"controlnetOneImage": "https://replicate.delivery/pbxt/KTWobEZiPRKJanaeqp2FqDfppvecWkJIZARLqRU3F0U54dtl/astro-on-horse.png",
"controlnetOneStart": 0,
"controlnetThreeEnd": 1,
"controlnetTwoStart": 0,
"schedulingStrategy": "K_EULER",
"controlnetThreeStart": 0,
"controlnetOneConditioningScale": 0.75,
"controlnetTwoConditioningScale": 0.75,
"controlnetThreeConditioningScale": 0.75
}
Output
The action returns an array of generated image URLs. Here’s an example of the output you can expect:
[
"https://assets.cognitiveactions.com/invocations/e073cf3e-31a7-4e01-b976-553ff1323836/103c2f69-e880-4f81-9dc2-0fc27d9fe559.png",
"https://assets.cognitiveactions.com/invocations/e073cf3e-31a7-4e01-b976-553ff1323836/439f8331-8857-4d30-9d22-914dd2adbe0d.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the Execute SDXL Lightning Image Generation action using a hypothetical Cognitive Actions execution endpoint in 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 = "5b6ab575-1a80-409d-ba97-00e33ea5865f" # Action ID for Execute SDXL Lightning Image Generation
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "extreme macro photo of a golden astronaut riding a unicorn statue, in a museum, bokeh, 50mm",
"numOutputs": 1,
"refineStyle": "no_refiner",
"controlnetOne": "soft_edge_hed",
"controlnetTwo": "none",
"guidanceScale": 0,
"applyWatermark": True,
"negativePrompt": "worst quality, low quality",
"promptStrength": 0.8,
"resizeStrategy": "width_height",
"controlnetThree": "none",
"controlnetOneEnd": 1,
"controlnetTwoEnd": 1,
"numInferenceSteps": 4,
"controlnetOneImage": "https://replicate.delivery/pbxt/KTWobEZiPRKJanaeqp2FqDfppvecWkJIZARLqRU3F0U54dtl/astro-on-horse.png",
"controlnetOneStart": 0,
"controlnetThreeEnd": 1,
"controlnetTwoStart": 0,
"schedulingStrategy": "K_EULER",
"controlnetThreeStart": 0,
"controlnetOneConditioningScale": 0.75,
"controlnetTwoConditioningScale": 0.75,
"controlnetThreeConditioningScale": 0.75
}
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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured based on the input schema defined for the action. The action_id corresponds to the specific action you are invoking. The endpoint URL and request structure are illustrative and may vary based on the actual implementation.
Conclusion
Integrating the SDXL Lightning Image Generation Cognitive Action into your application opens up a world of creative possibilities. With its powerful image generation capabilities and extensive customization options, you can create unique visuals tailored to your projects. Consider experimenting with different parameters and ControlNet configurations to see how they influence the output. Happy coding!