Generate Stunning Images with Inpainting: A Developer's Guide to ad-ams/ppl01 Actions

In recent years, the ability to create and manipulate images using AI has gained immense popularity across various applications, from art to marketing. The ad-ams/ppl01 spec provides powerful Cognitive Actions that enable developers to generate images through inpainting, leveraging customizable prompts and efficient model settings. This blog post will guide you through integrating the Generate Image with Inpainting action, showcasing its capabilities and providing practical examples for developers looking to enhance their applications.
Prerequisites
To get started with Cognitive Actions, you'll need:
- An API key for the Cognitive Actions platform, which allows you to authenticate your requests.
- Basic familiarity with JSON structures and HTTP requests.
Authentication typically involves passing your API key in the request headers to authorize access to the Cognitive Actions services.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create images by performing inpainting on provided input images. It supports customizable prompts and offers different models to optimize speed and quality. This action is particularly useful for generating unique visual content, enhancing existing images, or creating surreal artwork.
Input:
The input schema requires at least a prompt, with several optional fields to customize the output.
- Required:
prompt: A descriptive text prompt guiding the image generation.
- Optional:
mask: URI of the image mask used for inpainting.seed: Random seed value for reproducible images.image: URI of the input image for transformations.width: Width in pixels for the generated image (256 to 1440).height: Height in pixels for the generated image (256 to 1440).fastMode: Boolean to enable fast prediction speed.imageFormat: Output image format (default: webp).guidanceLevel: Scale of guidance during diffusion (0 to 10).loraIntensity: Intensity of the LoRA application (default: 1).inferenceModel: Model for inference (default: dev).inferenceSteps: Number of denoising steps (1 to 50).numberOfOutputs: Number of images to generate (1 to 4).promptIntensity: Impact of the prompt strength (0 to 1).qualityOfOutput: Quality for output images (0 to 100).imageAspectRatio: Aspect ratio for the generated image.
Example Input:
{
"prompt": "“In style of PPL01, A surreal dreamlike scene where a faceless, blue-hued humanoid figure stands on a cloudscape, gazing into a tear in the sky that reveals a dark, star-filled cosmos. The tear in the sky has a soft glow at the edges, and the figure casts a faint shadow on the clouds beneath. In a second scene, the same blue-hued figure is lying relaxed in a hammock suspended between the clouds, surrounded by a tranquil, sky-blue atmosphere. The entire setting feels serene, blending elements of sky, clouds, and cosmic mystery. The mood is contemplative and peaceful, with a mix of surrealism and space.”",
"imageFormat": "png",
"guidanceLevel": 2,
"loraIntensity": 1,
"inferenceModel": "dev",
"inferenceSteps": 17,
"numberOfOutputs": 4,
"promptIntensity": 0.8,
"qualityOfOutput": 90,
"imageAspectRatio": "9:16",
"additionalLoraIntensity": 1
}
Output: The action typically returns an array of generated image URLs. For example:
[
"https://assets.cognitiveactions.com/invocations/bd0301ca-147d-46fb-9405-bf712e7671d1/e812416b-a617-43a4-a539-7eaf8e5cd73e.png",
"https://assets.cognitiveactions.com/invocations/bd0301ca-147d-46fb-9405-bf712e7671d1/fca87955-04c4-4983-8c35-095e2d3f30c3.png",
"https://assets.cognitiveactions.com/invocations/bd0301ca-147d-46fb-9405-bf712e7671d1/e9b5adb2-f9a8-4254-a8dd-cc0740236f2c.png",
"https://assets.cognitiveactions.com/invocations/bd0301ca-147d-46fb-9405-bf712e7671d1/9f26729f-9e9f-492e-a308-63cdbd9724d7.png"
]
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 = "90d4b189-a1a3-4108-9cb1-30e1864c554a" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "“In style of PPL01, A surreal dreamlike scene where a faceless, blue-hued humanoid figure stands on a cloudscape, gazing into a tear in the sky that reveals a dark, star-filled cosmos. The tear in the sky has a soft glow at the edges, and the figure casts a faint shadow on the clouds beneath. In a second scene, the same blue-hued figure is lying relaxed in a hammock suspended between the clouds, surrounded by a tranquil, sky-blue atmosphere. The entire setting feels serene, blending elements of sky, clouds, and cosmic mystery. The mood is contemplative and peaceful, with a mix of surrealism and space.”",
"imageFormat": "png",
"guidanceLevel": 2,
"loraIntensity": 1,
"inferenceModel": "dev",
"inferenceSteps": 17,
"numberOfOutputs": 4,
"promptIntensity": 0.8,
"qualityOfOutput": 90,
"imageAspectRatio": "9:16",
"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 code snippet, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id variable corresponds to the Generate Image with Inpainting action, and the payload is structured according to the required input schema.
Conclusion
The Generate Image with Inpainting action from the ad-ams/ppl01 spec allows developers to produce stunning and unique images with ease. By leveraging customizable prompts and various model settings, you can enhance your applications with high-quality, AI-generated visuals. Consider integrating this action into your projects to unlock new creative possibilities and engage your users with captivating imagery. Happy coding!