Generate Stunning Images with Cognitive Actions for Image Inpainting

In the world of AI and graphics, the ability to generate and manipulate images can transform applications across various domains. The "aistockbrah/tnymdrn" Cognitive Actions provide developers with powerful tools for image generation, specifically through the action of image inpainting. This action allows for the creation of images based on textual prompts while offering extensive customization options. With features like customizable aspect ratios, various model types, and additional parameters for fine-tuning, these Cognitive Actions can help enhance your applications with visually appealing content seamlessly.
Prerequisites
To start using these Cognitive Actions, you will need an API key from the Cognitive Actions platform. This key will be required for authenticating your requests. Typically, you would pass this API key in the headers of your HTTP requests to ensure secure access to the service.
Cognitive Actions Overview
Generate Images with Image Inpainting
The Generate Images with Image Inpainting action allows you to create images based on a given textual prompt, incorporating various customizable settings. It is categorized under image generation and offers flexibility in image creation through different models and parameters.
Input
The input for this action is structured as follows:
{
"prompt": "string", // Required
"mask": "string", // Optional
"seed": "integer", // Optional
"image": "string", // Optional
"width": "integer", // Optional
"height": "integer", // Optional
"goFast": "boolean", // Optional
"modelType": "string", // Optional
"numOutputs": "integer", // Optional
"imageFormat": "string", // Optional
"guidanceScale": "number", // Optional
"outputQuality": "integer", // Optional
"extraLoraScale": "number", // Optional
"promptStrength": "number", // Optional
"imageResolution": "string", // Optional
"imageAspectRatio": "string", // Optional
"numInferenceSteps": "integer", // Optional
"disableSafetyChecker": "boolean" // Optional
}
Example Input
Here’s an example JSON payload illustrating how to structure the input:
{
"goFast": false,
"prompt": "aerial view of rusty dilapidated steel tiny rectangle bunker research facility with numerous antennas and excessive communication equipment stacked on the roof, overtaken by overgrown thick vines you can barely see the structure. A group of four large rusty robots, in the style of retro sci-fy artist Simon Stålenhag, are fighting in the distance ",
"loraScale": 0.77,
"modelType": "dev",
"numOutputs": 4,
"imageFormat": "png",
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1.77,
"promptStrength": 0.77,
"imageResolution": "1",
"imageAspectRatio": "21:9",
"numInferenceSteps": 34
}
Output
The output of this action typically consists of an array of image URLs, each pointing to the generated images. Below is an example of what you might receive:
[
"https://assets.cognitiveactions.com/invocations/e240ff2f-ba02-4119-99a0-852ab58f294f/23acbfaf-fac8-482d-8632-6b144510a8e5.png",
"https://assets.cognitiveactions.com/invocations/e240ff2f-ba02-4119-99a0-852ab58f294f/9870f7f9-3264-4280-8f46-cc5b78f40b72.png",
"https://assets.cognitiveactions.com/invocations/e240ff2f-ba02-4119-99a0-852ab58f294f/8be9a64d-54f8-4dfd-9933-4c627b40ea7e.png",
"https://assets.cognitiveactions.com/invocations/e240ff2f-ba02-4119-99a0-852ab58f294f/94ded1c0-d067-41ea-9f33-cd5496d5584b.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet to demonstrate how you might call this 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 = "495f5814-1977-4fac-9e20-72e371cfbfee" # Action ID for Generate Images with Image Inpainting
# Construct the input payload based on the action's requirements
payload = {
"goFast": False,
"prompt": "aerial view of rusty dilapidated steel tiny rectangle bunker research facility with numerous antennas and excessive communication equipment stacked on the roof, overtaken by overgrown thick vines you can barely see the structure. A group of four large rusty robots, in the style of retro sci-fy artist Simon Stålenhag, are fighting in the distance ",
"loraScale": 0.77,
"modelType": "dev",
"numOutputs": 4,
"imageFormat": "png",
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1.77,
"promptStrength": 0.77,
"imageResolution": "1",
"imageAspectRatio": "21:9",
"numInferenceSteps": 34
}
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, you'll replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. You can see how the action ID and the input payload are structured to match the requirements of the Cognitive Actions service.
Conclusion
The Cognitive Actions for image generation using inpainting offer a powerful and flexible solution for developers looking to integrate creative image capabilities into their applications. With customizable prompts and various generation parameters, you can create unique images tailored to your specific needs. Start exploring the possibilities today and enhance your applications with stunning visuals!