Create Stunning Images with the louteranas/better-pdp Cognitive Actions

In the ever-evolving world of image generation, the louteranas/better-pdp spec offers powerful Cognitive Actions designed to simplify and enhance the process of creating customized images. With the Generate Inpainted Image action, developers can leverage advanced inpainting techniques to create visually appealing images based on specified prompts and adjustable parameters. This blog post will guide you through integrating these Cognitive Actions into your applications, showcasing their capabilities and benefits.
Prerequisites
Before diving into the integration, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic understanding of making API requests and handling JSON data.
Authentication typically involves passing your API key in the request headers. This allows you to securely interact with the Cognitive Actions API.
Cognitive Actions Overview
Generate Inpainted Image
The Generate Inpainted Image action enables developers to create customized images by employing inpainting techniques. This action allows for a range of adjustable parameters such as image mask, prompt strength, and output quality, making it versatile for various use cases.
Input
The following fields are required and optional for the action's input:
- Required:
prompt: A detailed description of the desired image (e.g., "A high-quality studio portrait of DIGOUZ...").
- Optional:
mask: (string) Image mask for inpainting mode (URI).seed: (integer) Random seed for reproducible generation.image: (string) Input image for image-to-image or inpainting mode (URI).model: (string) Selects the inference model, with options "dev" (default) and "schnell".width: (integer) Width of the generated image (if aspect ratio is custom).height: (integer) Height of the generated image (if aspect ratio is custom).imageFormat: (string) Format of the output image (default is "webp").imageQuality: (integer) Quality rating for output images (0-100).loraStrength: (number) Strength of the main LoRA applied (default is 1).enableFastMode: (boolean) Enables faster predictions if set to true.- Additional fields control aspects like prompt intensity, number of outputs, and more.
Example Input
{
"model": "dev",
"prompt": "A high-quality studio portrait of DIGOUZ, completely bald and on the slimmer side. make the face look realistic and not too smooth. Facing the camera with a confident yet relaxed expression. DIGOUZ should look like a startup ceo. This should look like a linkedin professional profile picture.",
"imageFormat": "webp",
"imageQuality": 80,
"loraStrength": 1,
"enableFastMode": false,
"imageMegapixels": "1",
"numberOfOutputs": 1,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"guidanceIntensity": 3,
"inferenceStepCount": 28,
"additionalLoraStrength": 1
}
Output
Upon successful execution, the action returns an array of URLs pointing to the generated images. Each URL corresponds to an output image based on the provided prompt and settings.
Example Output
[
"https://assets.cognitiveactions.com/invocations/56bee2f0-8f3f-4e76-972c-4ab6a866431b/376ca286-fbc8-4450-b8d3-f4e308e85af7.webp"
]
Conceptual Usage Example (Python)
Here’s how you might structure a Python script to call the Generate Inpainted Image 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 = "47ecbe21-929f-437c-94dd-193eb86173de" # Action ID for Generate Inpainted Image
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "A high-quality studio portrait of DIGOUZ, completely bald and on the slimmer side. make the face look realistic and not too smooth. Facing the camera with a confident yet relaxed expression. DIGOUZ should look like a startup ceo. This should look like a linkedin professional profile picture.",
"imageFormat": "webp",
"imageQuality": 80,
"loraStrength": 1,
"enableFastMode": False,
"imageMegapixels": "1",
"numberOfOutputs": 1,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"guidanceIntensity": 3,
"inferenceStepCount": 28,
"additionalLoraStrength": 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, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action_id is set to the identifier for the Generate Inpainted Image action. The payload is constructed based on the required input schema, ensuring all necessary fields are included.
Conclusion
The louteranas/better-pdp Cognitive Actions provide robust tools for image generation, allowing developers to create stunning visuals with ease. By leveraging the Generate Inpainted Image action, you can tap into advanced inpainting techniques that enhance the creative potential of your applications. Explore these capabilities further, experiment with different parameters, and unlock new possibilities in image creation!