Create Stunning Images with the Sandra Cognitive Actions

Creating visually appealing images has never been easier with the Sandra Cognitive Actions. By utilizing these pre-built actions, developers can integrate sophisticated image generation capabilities directly into their applications. The Generate Customized Images action allows for a high degree of customization, ensuring that the output meets specific aesthetic and technical requirements.
Prerequisites
Before you start using the Sandra Cognitive Actions, ensure you have the following:
- An API key for the Sandra Cognitive Actions platform.
- Familiarity with JSON and basic HTTP requests, as the integration will involve sending JSON payloads.
- Basic knowledge of Python for executing the example code provided.
Authentication typically involves passing your API key in the request headers, which will authorize your application to use the Cognitive Actions.
Cognitive Actions Overview
Generate Customized Images
The Generate Customized Images action is designed for creating detailed or rapidly generated images based on specified parameters. It supports various features, including inpainting, image-to-image transformations, and customizable output. Developers can control aspects such as resolution, aspect ratio, and quality, making it a versatile tool for a variety of applications.
Input:
The action requires a JSON object with the following fields:
- prompt (required): The text prompt guiding the image generation. Example:
"a TOK wearing cyberpunk glasses in neon bold vibrant colors". - model (optional): Specify the model for inference (
"dev"or"schnell"). Default is"dev". - goFast (optional): A boolean to enable faster predictions. Default is
false. - megapixels (optional): Approximate number of megapixels for the generated image. Default is
"1". - aspectRatio (optional): Specifies the aspect ratio. Default is
"1:1". - outputFormat (optional): The file format for the output images. Default is
"webp". - guidanceScale (optional): A scale for the diffusion process. Default is
3. - numberOfOutputs (optional): Number of images to generate (max 4). Default is
1. - ... (other optional fields available for fine-tuning)
Example Input:
{
"model": "dev",
"goFast": false,
"prompt": "a TOK wearing cyberpunk glasses in neon bold vibrant colors",
"megapixels": "1",
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3,
"mainLoraScale": 1,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"numberOfInferenceSteps": 28
}
Output:
Upon successful execution, the action returns a JSON array with the URL(s) of the generated image(s). For example:
[
"https://assets.cognitiveactions.com/invocations/9b291034-00b4-4aa8-a774-41ea5bb73da6/c8ffd566-9903-45c5-8b38-0eff7876f353.webp"
]
Conceptual Usage Example (Python):
Here's a Python snippet that demonstrates how to invoke the Generate Customized Images 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 = "c9b49e06-9120-4312-bc7f-56dac97d8c81" # Action ID for Generate Customized Images
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"prompt": "a TOK wearing cyberpunk glasses in neon bold vibrant colors",
"megapixels": "1",
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3,
"mainLoraScale": 1,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"numberOfInferenceSteps": 28
}
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 action ID and the structured input payload are defined based on the requirements of the Generate Customized Images action.
Conclusion
The Generate Customized Images action from the Sandra Cognitive Actions provides an easy-to-integrate solution for developers looking to enhance their applications with advanced image generation capabilities. By leveraging customizable parameters, developers can create unique and stunning images tailored to their needs. Explore this action further and consider how it can elevate your projects!