Create Stunning Images with nn22a/ainem Cognitive Actions

Integrating advanced image generation capabilities into your applications has never been easier with the nn22a/ainem Cognitive Actions. These pre-built actions harness the power of sophisticated inpainting techniques and customizable parameters to generate compelling images tailored to your specifications. This guide will walk you through the primary action available in the nn22a/ainem suite, helping you unlock its potential for your projects.
Prerequisites
Before diving into the integration, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with JSON structure and HTTP requests.
- Basic understanding of Python programming is beneficial for the provided code examples.
To authenticate your requests, you will typically pass your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate Image with Inpainting and Customization
The Generate Image with Inpainting and Customization action allows developers to create images using advanced inpainting techniques. This action provides various customizable parameters such as aspect ratio, dimensions, and the option to apply additional LoRA weights for enhanced creativity. It caters to both artistic and realistic outcomes, offering models optimized for speed or quality.
Input
The following is the required and optional fields for the input, based on the provided schema:
- prompt (required): A descriptive text prompt guiding the image generation.
- mask (optional): URI of the image mask for inpainting mode.
- image (optional): URI of the input image for img2img or inpainting mode.
- width (optional): Width of the generated image (in pixels) when aspect ratio is set to custom.
- height (optional): Height of the generated image (in pixels) when aspect ratio is set to custom.
- goFast (optional): Enable faster predictions using an fp8 quantized model.
- seed (optional): Random seed for reproducibility.
- extraLora (optional): Load additional LoRA weights from various sources.
- loraScale (optional): Adjust the intensity of the primary LoRA application.
- numOutputs (optional): Number of image outputs desired (max 4).
- guidanceScale (optional): Influences the diffusion guidance.
- outputQuality (optional): Quality of saved output images (0-100).
- denoisingSteps (optional): Number of steps used in the denoising process.
- imageAspectRatio (optional): Aspect ratio for the generated image.
- imageOutputFormat (optional): File format for the output images.
Example Input:
{
"goFast": false,
"prompt": "AINEM with platinum blonde hair with thick roots, in a luxury white bedroom with large crystal hanging diamond chandalier, sitting on the bed with a toy sized white poodle, wearing cute pajama dress, cartoon",
"loraScale": 1,
"numOutputs": 1,
"guidanceScale": 3,
"outputQuality": 100,
"denoisingSteps": 36,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "4:5",
"imageOutputFormat": "png"
}
Output
The action typically returns a URL pointing to the generated image. Here’s an example of a successful output:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/b5841d1c-48a4-455e-8cd9-2215a39e21e2/a98d91e9-1ffe-4e75-a3e1-9f8798c86bd1.png"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet demonstrating how to invoke the Generate Image with Inpainting and Customization 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 = "84e85840-8d8f-4d49-ac0a-9da31a2e4b60" # Action ID for Generate Image with Inpainting and Customization
# Construct the input payload based on the action's requirements
payload = {
"goFast": False,
"prompt": "AINEM with platinum blonde hair with thick roots, in a luxury white bedroom with large crystal hanging diamond chandalier, sitting on the bed with a toy sized white poodle, wearing cute pajama dress, cartoon",
"loraScale": 1,
"numOutputs": 1,
"guidanceScale": 3,
"outputQuality": 100,
"denoisingSteps": 36,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "4:5",
"imageOutputFormat": "png"
}
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 snippet:
- Replace the placeholder for
COGNITIVE_ACTIONS_API_KEYwith your actual API key. - The
action_idcorresponds to the action you want to execute. - The
payloadis constructed based on the required fields for the action. - The response is handled to print out the generated image URL or error messages appropriately.
Conclusion
The Generate Image with Inpainting and Customization action from the nn22a/ainem suite provides powerful capabilities for developers looking to integrate advanced image generation into their applications. By leveraging customizable parameters, you can create unique and high-quality images tailored to your needs. Explore the possibilities and enhance your projects with this innovative cognitive action!