Create Stunning Images with the advoworks/lokidog Cognitive Actions

In the realm of image generation, the advoworks/lokidog Cognitive Actions stand out by providing advanced functionalities such as inpainting and customizable options for generating high-quality images. These pre-built actions simplify the integration of sophisticated image generation capabilities into your applications, allowing developers to focus on creativity rather than technical complexities.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- An API key for accessing the Cognitive Actions platform.
- Familiarity with JSON structures for sending requests and handling responses.
Authentication typically involves passing your API key in the request headers, allowing you to securely interact with the Cognitive Actions endpoints.
Cognitive Actions Overview
Generate Image with Inpainting
Description:
This action generates images using inpainting techniques. By specifying an image mask along with options like aspect ratio and dimensions, users can create high-quality images with limited steps. Advanced features include adjusting LoRA weights, enabling fast mode, and fine-tuning guidance scales for enhanced realism.
Category: Image Generation
Input
The input for this action requires a JSON object with the following schema:
- prompt: (required) The description for the image you want to generate.
- mask: (optional) URI of the image mask used for inpainting mode.
- image: (optional) URI of an input image for modifying or inpainting.
- model: (optional) Choose between "dev" or "schnell" for inference models.
- width: (optional) Width of the generated image (effective for custom aspect ratios).
- height: (optional) Height of the generated image (effective for custom aspect ratios).
- goFast: (optional) Toggle for fast mode predictions.
- aspectRatio: (optional) Choose from predefined aspect ratios or set a custom one.
- numOutputs: (optional) Number of images to generate (1 to 4).
- guidanceScale: (optional) Scale for guiding image realism.
- outputQuality: (optional) Quality of the output image (0 to 100).
- promptStrength: (optional) Strength of the prompt in img2img mode.
Example Input:
{
"model": "dev",
"prompt": "A photo of LOKITOK dog, standing on a precarious rock looking at the sunrise",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3.5,
"outputQuality": 80,
"extraLoraScale": 0.8,
"promptStrength": 0.8,
"numInferenceSteps": 28
}
Output
The output of this action typically returns a URL pointing to the generated image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/813e8350-50cd-469a-b279-7ec215c6f470/3aaf196c-93be-4473-8d5c-d905439dbdfa.webp"
]
Conceptual Usage Example (Python)
Here’s how you might call the Generate Image with Inpainting action using 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 = "02097c92-1bdb-4a91-84ac-fe33e8de8078" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "A photo of LOKITOK dog, standing on a precarious rock looking at the sunrise",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3.5,
"outputQuality": 80,
"extraLoraScale": 0.8,
"promptStrength": 0.8,
"numInferenceSteps": 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 the above code snippet, replace the API key and endpoint with your actual values. The action ID corresponds to the Generate Image with Inpainting action, and the input payload is structured according to the action's requirements.
Conclusion
The advoworks/lokidog Cognitive Actions provide a powerful way to generate stunning images through inpainting and customized options. Whether you're looking to create unique visuals or enhance existing ones, these actions can significantly streamline your development process. Explore integrating these capabilities into your applications, and unleash your creativity with advanced image generation!