Enhance Your Apps with Image Generation Using the DND Flux Cognitive Actions

The DND Flux Cognitive Actions provide a powerful way to integrate advanced image generation capabilities into your applications. With features like inpainting, customizable dimensions, and aspect ratios, developers can create high-quality images based on descriptive text prompts. This guide will walk you through the available actions, their inputs, outputs, and provide conceptual examples to help you get started.
Prerequisites
Before diving into the Cognitive Actions, ensure you have:
- An API key for the DND Flux Cognitive Actions platform.
- Familiarity with JSON structure for API requests.
- Basic knowledge of making HTTP requests in your preferred programming language.
Authentication generally involves passing your API key in the request headers, allowing you to securely access the actions.
Cognitive Actions Overview
Generate Image With Inpainting
The Generate Image With Inpainting action creates high-quality images using advanced inpainting techniques by interpreting descriptive text prompts. This action can customize image dimensions, aspect ratios, and various output formats, making it versatile for numerous applications.
Input
The required input fields for this action are defined in the schema below. Here’s a breakdown:
- prompt (string, required): Describes the desired image, including specific styles or objects.
- mask (string, optional): An image mask for inpainting.
- seed (integer, optional): Sets a random seed for reproducible results.
- model (string, optional): Choose between "dev" for detailed outputs or "schnell" for faster outputs.
- width (integer, optional): Width of the generated image (256 - 1440).
- height (integer, optional): Height of the generated image (256 - 1440).
- outputCount (integer, optional): Number of images to generate (1 - 4).
- outputQuality (integer, optional): Image quality from 0 (lowest) to 100 (highest).
- imageAspectRatio (string, optional): Sets the aspect ratio for generated images.
Here’s an example input JSON payload:
{
"model": "dev",
"prompt": "A elven mage women with crystal ball and staff with fantasy background in the style of DND",
"outputCount": 1,
"loraIntensity": 1,
"outputQuality": 90,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"inferenceStepCount": 28,
"diffusionGuidanceScale": 3.5,
"additionalLoraIntensity": 1
}
Output
The action typically returns the URL of the generated image. Here’s an example output:
[
"https://assets.cognitiveactions.com/invocations/f141551c-99f8-4331-9bee-d8a7d3e474c5/d0cae6a2-d098-4ed4-b3b1-e3676b8174bd.webp"
]
Conceptual Usage Example (Python)
Here’s how a developer might structure a request to execute this 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 = "34c387a1-9658-42d1-b807-ddefb0a814ee" # Action ID for Generate Image With Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "A elven mage women with crystal ball and staff with fantasy background in the style of DND",
"outputCount": 1,
"loraIntensity": 1,
"outputQuality": 90,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"inferenceStepCount": 28,
"diffusionGuidanceScale": 3.5,
"additionalLoraIntensity": 1
}
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, the action_id corresponds to the Generate Image With Inpainting action. The payload contains all required fields as specified in the input schema.
Conclusion
The DND Flux Cognitive Actions allow developers to incorporate sophisticated image generation capabilities into their applications with ease. By leveraging the Generate Image With Inpainting action, you can create stunning visuals tailored to your specifications. As you explore these features, consider how they can enhance user experiences in your projects. Happy coding!