Create Stunning Images with Cognitive Actions: A Guide to EOM Phase 1

In the world of digital content creation, the ability to generate custom images can be a game-changer for developers. The EOM Phase 1 spec from Cognitive Actions offers a powerful action called Generate Custom Image with Inpainting. This action utilizes advanced image inpainting techniques, allowing developers to create tailored images through customizable prompts, masks, and various settings for aspect ratio and resolution. In this blog post, we will explore the capabilities of this action and guide you on how to integrate it into your applications.
Prerequisites
To get started with Cognitive Actions, you will need an API key for authentication. This key should be passed in the headers of your requests to ensure secure access to the Cognitive Actions platform. Make sure to set up your environment accordingly.
Cognitive Actions Overview
Generate Custom Image with Inpainting
The Generate Custom Image with Inpainting action allows you to create unique images by specifying a prompt and, optionally, an image mask. This action is particularly useful for developers looking to enhance their applications with tailored image generation capabilities.
Input
The input for this action is structured as follows:
{
"prompt": "string", // Required
"mask": "uri", // Optional
"seed": "integer", // Optional
"image": "uri", // Optional
"model": "string", // Optional
"width": "integer", // Optional
"goFast": "boolean", // Optional
"height": "integer", // Optional
"aspectRatio": "string", // Optional
"imageFormat": "string", // Optional
"outputCount": "integer", // Optional
"imageQuality": "integer", // Optional
"modelWeights": "string", // Optional
"guidanceScale": "number", // Optional
"mainLoraScale": "number", // Optional
"additionalLora": "string", // Optional
"denoisingSteps": "integer", // Optional
"promptStrength": "number", // Optional
"imageMegapixels": "string", // Optional
"disableSafetyCheck": "boolean", // Optional
"additionalLoraScale": "number" // Optional
}
Example Input:
{
"width": 1024,
"height": 1024,
"prompt": "a full-body TOK chibi character, a bearborn mage holding a arcana book, empty background",
"outputCount": 1,
"guidanceScale": 7.5,
"mainLoraScale": 0.6,
"denoisingSteps": 50,
"promptStrength": 0.8
}
Output
The action typically returns a URL to the generated image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/a32f4b32-51c7-4c7b-a831-903b44dbd6b9/589bea03-acd8-40c3-92d0-80dd3b75e633.webp"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet demonstrating how to call the Cognitive Actions execution endpoint for this 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 = "8e4de703-0ee5-4b64-82ac-04ba29709c1e" # Action ID for Generate Custom Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "a full-body TOK chibi character, a bearborn mage holding a arcana book, empty background",
"outputCount": 1,
"guidanceScale": 7.5,
"mainLoraScale": 0.6,
"denoisingSteps": 50,
"promptStrength": 0.8
}
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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable constructs the input based on the action's requirements, allowing you to generate a custom image as specified.
Conclusion
The Generate Custom Image with Inpainting action from the EOM Phase 1 spec opens up exciting possibilities for developers looking to integrate image generation into their applications. By leveraging the capabilities of this action, you can create tailored visual content that enhances user experiences. As you embark on your development journey, consider exploring additional features and use cases that this powerful API can offer. Happy coding!