Create Stunning LEGO Images with the SDXL LEGO Cognitive Actions

In the world of AI-generated imagery, the martintmv-git/sdxl-lego spec brings exciting capabilities specifically tailored for creating vibrant, LEGO-themed images. Utilizing the SDXL model fine-tuned for LEGO, these Cognitive Actions enable developers to generate images with customizable features such as prompt strength, inpainting, and image modifications, all while ensuring safe distribution through watermarking and safety checks.
With these pre-built actions, you can effortlessly integrate LEGO image generation into your applications, enhancing user experience with creative visuals. Let’s dive into how to leverage these actions effectively!
Prerequisites
To get started with the Cognitive Actions, you will need an API key from the Cognitive Actions platform. This key should be included in the header of your requests for authentication purposes. The typical structure for authenticating is by passing the API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate LEGO Themed Image
Description: This action creates LEGO-themed images using the SDXL model. It supports various features like inpainting, image-to-image modifications, and customizable generation settings, such as guidance scale and image dimensions.
Category: Image Generation
Input
The input to this action is structured as follows:
{
"mask": "string (uri)",
"seed": "integer",
"image": "string (uri)",
"width": 1024,
"height": 1024,
"prompt": "string",
"loraScale": 0.6,
"refineSteps": "integer",
"scheduleType": "string",
"guidanceScale": 7.5,
"applyWatermark": true,
"negativePrompt": "string",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"refinementStyle": "string",
"highNoiseFraction": 0.8,
"alternativeWeights": "string",
"disableSafetyChecker": false,
"numberOfInferenceSteps": 50
}
Example Input:
{
"width": 1024,
"height": 1024,
"prompt": "Breaking Bad lego in the style of TOK",
"loraScale": 0.6,
"scheduleType": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": true,
"negativePrompt": "",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"refinementStyle": "no_refiner",
"highNoiseFraction": 0.8,
"numberOfInferenceSteps": 50
}
Output
Upon successful execution, the action typically returns a URL pointing to the generated image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/f162db96-f1b2-4e40-a561-97e2f5170997/44a68003-a2b5-45d7-85ce-b25cf8241ad5.png"
]
Conceptual Usage Example (Python)
Here is a conceptual Python code snippet demonstrating how to invoke the "Generate LEGO Themed Image" 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 = "f21faa08-4b85-4075-b66c-3458f05a519e" # Action ID for Generate LEGO Themed Image
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "Breaking Bad lego in the style of TOK",
"loraScale": 0.6,
"scheduleType": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": True,
"negativePrompt": "",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"refinementStyle": "no_refiner",
"highNoiseFraction": 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 example, replace the placeholder API key and endpoint with your actual credentials. The action_id is set to the ID of the "Generate LEGO Themed Image" action, and the input payload is structured according to the action's requirements.
Conclusion
The SDXL LEGO Cognitive Actions provide developers with powerful tools to create engaging LEGO-themed images with ease. By leveraging customizable settings for image generation, you can enhance your applications with unique visuals that captivate users.
Consider exploring various prompts and configurations to fully utilize the potential of this action in your projects. Happy coding!