Enhance Image Generation with ControlNet Multi Cognitive Actions

Integrating advanced image generation capabilities into your applications has never been easier with the ControlNet Multi Cognitive Actions. This powerful API enables developers to harness the potential of multi-input ControlNet models to create stunning images based on various control images. By utilizing adjustable weights, you can precisely guide the composition of your images, making it an ideal solution for customization and creativity in your projects.
Prerequisites
Before diving into the implementation of ControlNet Multi Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Basic knowledge of handling API requests in your preferred programming language.
For authentication, you will typically pass your API key in the request headers, allowing you to access the Cognitive Actions securely.
Cognitive Actions Overview
Execute Multi-Condition ControlNet Composition
Purpose:
This action utilizes a multi-input ControlNet model to generate images based on multiple control images and adjustable weights. It allows for precise image composition by guiding the process with specific input images and set importance weights for each control element.
Category: Image Generation
Input
The input for this action requires several components to function effectively:
- pose (string, required): A URI pointing to the pose input image.
- cannyImage (string, required): A URI for the Canny edges input image.
- depthImage (string, required): A URI for the depth input image.
- mlsdImage (string, required): A URI for the MLSD input image.
- segmentationImage (string, required): A URI for the segmentation input image.
- softEdgeImage (string, required): A URI for the soft edge input image.
- prompt (string, optional): A text prompt for generating the output. Defaults to "a magpie wearing a tophat".
- negativePrompt (string, optional): Text specifying elements to exclude from the output. Defaults to "monochrome, lowres, bad anatomy, worst quality, low quality".
- Weights (number, optional): Adjust importance for each of the inputs (poseWeight, cannyWeight, depthWeight, mlsdWeight, softEdgeWeight, segmentationWeight).
Example Input:
{
"pose": "https://replicate.delivery/pbxt/IrarVkMTOYSZ08KZWAMcA3ed87zelT55XdfoYaq4drAWI4G1/pose_man.png",
"prompt": "a giant standing in a fantasy landscape, best quality",
"mlsdImage": "https://replicate.delivery/pbxt/IrarWDb4d9n1pWwEV3na6aZogpYW0qpwZ4FNIFxq3B21nrPU/empty.png",
"cannyImage": "https://replicate.delivery/pbxt/IrarVflkkV3TsUxP0sggxmthggyLFpUxrfOgY1CINeDbMY2J/canny_man.png",
"depthImage": "https://replicate.delivery/pbxt/IrarW1cJkljr1M6wZgoOqf5H1ERAobcp25R3VVpTe38hukqb/empty.png",
"poseWeight": 0.8,
"cannyWeight": 1,
"softEdgeImage": "https://replicate.delivery/pbxt/IrarVcg0YvuRzjA6G0yelEeGq8IbQFIktkjga3X9zbxEJTYs/empty.png",
"negativePrompt": "monochrome, lowres, bad anatomy, worst quality, low quality",
"segmentationImage": "https://replicate.delivery/pbxt/IrarVUc6AdoRj3e5ypGIPSVHsThTOsAGZoD4xnsSJOzsVXt9/empty.png"
}
Output
The expected output is a URI pointing to the generated image, which may look like this:
https://assets.cognitiveactions.com/invocations/e8340470-f7b6-4642-8d9e-18b1c962bb84/6bdf3d33-1c2a-42d5-a335-927f06856540.png
Conceptual Usage Example (Python)
Here’s a conceptual example of how you might call the Execute Multi-Condition ControlNet Composition action in 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 = "7530828d-5bfd-4f44-bc79-22a0ecb515c7" # Action ID for Execute Multi-Condition ControlNet Composition
# Construct the input payload based on the action's requirements
payload = {
"pose": "https://replicate.delivery/pbxt/IrarVkMTOYSZ08KZWAMcA3ed87zelT55XdfoYaq4drAWI4G1/pose_man.png",
"prompt": "a giant standing in a fantasy landscape, best quality",
"mlsdImage": "https://replicate.delivery/pbxt/IrarWDb4d9n1pWwEV3na6aZogpYW0qpwZ4FNIFxq3B21nrPU/empty.png",
"cannyImage": "https://replicate.delivery/pbxt/IrarVflkkV3TsUxP0sggxmthggyLFpUxrfOgY1CINeDbMY2J/canny_man.png",
"depthImage": "https://replicate.delivery/pbxt/IrarW1cJkljr1M6wZgoOqf5H1ERAobcp25R3VVpTe38hukqb/empty.png",
"poseWeight": 0.8,
"cannyWeight": 1,
"softEdgeImage": "https://replicate.delivery/pbxt/IrarVcg0YvuRzjA6G0yelEeGq8IbQFIktkjga3X9zbxEJTYs/empty.png",
"negativePrompt": "monochrome, lowres, bad anatomy, worst quality, low quality",
"segmentationImage": "https://replicate.delivery/pbxt/IrarVUc6AdoRj3e5ypGIPSVHsThTOsAGZoD4xnsSJOzsVXt9/empty.png"
}
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, the code constructs the input JSON payload according to the requirements of the action. The action ID and payload are supplied to the hypothetical endpoint for execution.
Conclusion
The ControlNet Multi Cognitive Actions empower developers to create intricate and compelling images with ease. By leveraging multiple control images and customizing their significance, you can achieve unparalleled flexibility in your image generation tasks. Explore the potential applications and start integrating these Cognitive Actions into your projects today!