Unleashing Creativity: Integrating Image Generation with Cooler-Han Cognitive Actions

In the realm of AI-driven creativity, the Cooler-Han Cognitive Actions stand out by providing developers with powerful tools for generating images. These actions simplify the process of image creation, allowing for customization through inpainting, various model selections, and other adjustable parameters. Whether you're looking to create stunning visuals for an app or enhance existing images, these pre-built actions can significantly streamline your workflow.
Prerequisites
Before you dive into using the Cooler-Han Cognitive Actions, ensure you have the following:
- API Key: You will need an API key to authenticate your requests.
- Endpoint Access: Familiarity with making HTTP requests to a generic Cognitive Actions execution endpoint will be beneficial.
Authentication typically requires passing the API key in the request headers.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create images by inpainting with customizable parameters, including model selection, image dimensions, and styles. This action is particularly useful for generating high-quality images or enhancing the speed of image generation.
Input
The action requires the following fields:
- prompt (string, required): The descriptive text that guides the image generation.
- mask (string, optional): URI of the image mask for inpainting.
- seed (integer, optional): For reproducible image generation.
- image (string, optional): URI of the input image for image-to-image conversion.
- width (integer, optional): Desired width of the generated image (between 256 and 1440).
- height (integer, optional): Desired height of the generated image (between 256 and 1440).
- loraScale (number, optional): Determines the strength of the main LoRA application.
- imageAspectRatio (string, optional): Specifies the aspect ratio for the generated image.
- numberOfOutputs (integer, optional): Number of images to generate (1 to 4).
- inferenceModel (string, optional): Selects the model for inference (
devorschnell).
Example input JSON:
{
"prompt": "A dramatic side-view action shot of \"coolerhan,\" a Korean basketball player...",
"loraScale": 1,
"inferenceModel": "dev",
"numberOfOutputs": 3,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"numInferenceSteps": 28,
"imageGuidanceScale": 3.5,
"imageOutputQuality": 90,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8
}
Output
Upon successful execution, the action returns an array of image URLs that have been generated based on the provided inputs.
Example output:
[
"https://assets.cognitiveactions.com/invocations/a14d368d-418b-4cc8-8ac5-7564d417716a/22fdf4aa-9ae1-4e03-90e5-096670159fd6.png",
"https://assets.cognitiveactions.com/invocations/a14d368d-418b-4cc8-8ac5-7564d417716a/fb59a1f0-dc7c-4f83-908b-b4de9cfea1fe.png",
"https://assets.cognitiveactions.com/invocations/a14d368d-418b-4cc8-8ac5-7564d417716a/07dbd9f1-3859-4917-8f1f-16b5cbec5e49.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 = "6303bf04-be0b-4904-a3a5-ee9739f2ce0c" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "A dramatic side-view action shot of \"coolerhan,\" a Korean basketball player...",
"loraScale": 1,
"inferenceModel": "dev",
"numberOfOutputs": 3,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"numInferenceSteps": 28,
"imageGuidanceScale": 3.5,
"imageOutputQuality": 90,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8
}
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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Generate Image with Inpainting action. The structured input payload is sent in the POST request, and the response is handled to display the results or any error messages.
Conclusion
The Cooler-Han Cognitive Actions provide a robust framework for developers seeking to harness the power of AI in image generation. With the ability to customize inputs and optimize outputs, these actions can help create stunning visuals that enhance any application. Consider exploring additional use cases, such as integrating these actions into creative tools, gaming applications, or marketing platforms to fully realize their potential.