Elevate Your App with Image Generation Using animacustoms/ernestamod Cognitive Actions

In the world of digital content creation, generating high-quality images on demand can significantly enhance user experience and engagement. The animacustoms/ernestamod provides a powerful Cognitive Action, Generate Image with Inpainting, which allows developers to create stunning visuals tailored to specific requirements. This action not only generates new images but also performs inpainting based on provided settings, making it versatile for various applications in gaming, marketing, and more.
Prerequisites
Before diving into the integration, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic familiarity with JSON and making API calls.
- A development environment set up for making HTTP requests, such as Python with the
requestslibrary.
Authentication typically involves passing your API key in the request headers to authorize your calls to the Cognitive Actions service.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action is designed to create new images or modify existing ones based on a specified prompt and optional parameters. This makes it suitable for generating high-definition visuals with customized styles, dimensions, and quality optimizations.
Input
The required and optional fields for this action are defined in the input_schema. Here’s a breakdown of the essential input parameters:
- prompt (string, required): A detailed description guiding the image generation.
- width (integer, optional): Specifies the width of the generated image (must be a multiple of 16).
- height (integer, optional): Specifies the height of the generated image (must be a multiple of 16).
- image (string, optional): A URL to an input image for inpainting or image-to-image generation.
- mask (string, optional): A URL to an image mask for inpainting mode.
- modelType (string, optional): Selects the model type for inference (default is "dev").
- outputCount (integer, optional): Defines the number of output images to generate (between 1 to 4).
- imageOutputFormat (string, optional): The format of the output image (options include webp, jpg, png).
Here’s an example of the JSON payload to invoke this action:
{
"width": 1440,
"height": 1440,
"prompt": "(stunning 18 years old woman), confidently sitting in luxurious Bentley Continental GT, dressed in elegant (sleek black dress with thigh-high slit and open back), detailed facial features and expression, moody evening lighting, high-definition, warm and inviting ambiance, showcasing opulence and style, surrounding luxurious interior details, ultra-detailed, capturing confidence and youth in a sophisticated atmosphere.",
"modelType": "dev",
"outputCount": 4,
"imageOutputFormat": "webp"
}
Output
Upon successful execution, this action returns an array of URLs pointing to the generated images. Here’s an example of the expected output:
[
"https://assets.cognitiveactions.com/invocations/104cb461-e4f1-41a3-bd67-fae151b380a5/1f67275b-1adc-4824-a468-5775f0ef5515.webp",
"https://assets.cognitiveactions.com/invocations/104cb461-e4f1-41a3-bd67-fae151b380a5/973e71dc-5e0c-4876-84c2-d814f4f1661a.webp",
"https://assets.cognitiveactions.com/invocations/104cb461-e4f1-41a3-bd67-fae151b380a5/aa17553b-8f60-4c25-8aa6-2885f0614026.webp",
"https://assets.cognitiveactions.com/invocations/104cb461-e4f1-41a3-bd67-fae151b380a5/f3039cc1-ec17-475d-a753-2e51de08eb43.webp"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet illustrating how to call the Generate Image with Inpainting action using the Cognitive Actions API:
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 = "963cbb08-2166-4c8d-873b-28312928aa61" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"width": 1440,
"height": 1440,
"prompt": "(stunning 18 years old woman), confidently sitting in luxurious Bentley Continental GT, dressed in elegant (sleek black dress with thigh-high slit and open back), detailed facial features and expression, moody evening lighting, high-definition, warm and inviting ambiance, showcasing opulence and style, surrounding luxurious interior details, ultra-detailed, capturing confidence and youth in a sophisticated atmosphere.",
"modelType": "dev",
"outputCount": 4,
"imageOutputFormat": "webp"
}
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:
- The API key and endpoint URL are placeholders that need to be replaced with your actual credentials.
- The
payloadvariable contains the structured input for the image generation request. - The response is handled to print out either the result or any errors encountered during the execution.
Conclusion
The Generate Image with Inpainting Cognitive Action from the animacustoms/ernestamod offers a robust solution for developers looking to integrate advanced image generation capabilities into their applications. By utilizing this action, you can create stunning visuals that are tailored to your specifications, enhancing your application's appeal and functionality.
Consider exploring additional use cases, such as dynamic content creation for marketing campaigns or enhancing user-generated content, to leverage the full potential of this Cognitive Action. Happy coding!