Generate Stunning Images with the Cyborg Cognitive Actions
The Cyborg Cognitive Actions offers a powerful toolset for developers looking to integrate image generation capabilities into their applications. This API enables the creation of stunning visuals using advanced image inpainting techniques. With customizable parameters such as image prompts, dimensions, and output formats, developers can leverage these pre-built actions to automate and enhance their creative workflows.
Prerequisites
To start using the Cyborg Cognitive Actions, you will need:
- An API key for the Cognitive Actions platform.
- Basic understanding of how to make HTTP requests and handle JSON responses.
Authentication typically involves passing your API key in the headers of your requests, ensuring secure access to the action endpoints.
Cognitive Actions Overview
Generate Inpainted Image
The Generate Inpainted Image action is designed for creating images based on a text prompt and optional parameters like image masks, dimensions, and output formats. This action utilizes two models, 'dev' and 'schnell', optimizing for either quality or speed depending on your needs.
Input
The input for this action requires the following fields:
- imagePrompt: (required) A textual prompt for generating images (e.g., "A bald BORG cybernetic man with black spectacles.").
- image: (optional) URI to the input image for inpainting. Overrides width and height if provided.
- mask: (optional) URI to an image mask used for inpainting mode.
- width: (optional) Specifies the width of the generated image in pixels (256 to 1440).
- height: (optional) Specifies the height of the generated image in pixels (256 to 1440).
- goFast: (optional) Enables speed-optimized predictions.
- numOutputs: (optional) Defines the number of output images (1 to 4).
- guidanceScale: (optional) Sets the guidance scale for the diffusion model (0 to 10).
- numInferenceSteps: (optional) Specifies the number of denoising steps (1 to 50).
- imageOutputFormat: (optional) Determines the output image format (webp, jpg, png).
- imageOutputQuality: (optional) Quality of the output images (0 to 100).
Here’s an example of the input JSON payload:
{
"image": "https://replicate.delivery/pbxt/MmLxXGafItuVsxf11ixN2gtj5J0nx6PQIUKURdHhNidYW4VJ/New-Glasses-20.jpg",
"goFast": false,
"numOutputs": 1,
"imagePrompt": "A bald BORG cybernetic man with black spectacles.",
"guidanceScale": 4.06,
"mainLoraScale": 1,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 80
}
Output
The output will typically return a list containing the URI of the generated image. Here’s an example of what you might receive:
[
"https://assets.cognitiveactions.com/invocations/7b8b6b08-3006-4b46-9d72-d32b4b239484/9bdb3560-dd21-41d8-a2c1-59cf221effc3.webp"
]
Conceptual Usage Example (Python)
Here’s how a developer might call the Generate Inpainted Image 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 = "f3240239-da63-4844-aa54-475a75e5e958" # Action ID for Generate Inpainted Image
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/MmLxXGafItuVsxf11ixN2gtj5J0nx6PQIUKURdHhNidYW4VJ/New-Glasses-20.jpg",
"goFast": false,
"numOutputs": 1,
"imagePrompt": "A bald BORG cybernetic man with black spectacles.",
"guidanceScale": 4.06,
"mainLoraScale": 1,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 80
}
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 snippet, you replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and use the action ID for the Generate Inpainted Image action. The input payload is structured according to the requirements, and the results are printed out upon successful execution.
Conclusion
The Cyborg Cognitive Actions provide an innovative way to generate and manipulate images programmatically. By leveraging the capabilities of the Generate Inpainted Image action, developers can create rich visual content tailored to their needs. Whether you're building an application that requires intricate graphics or simply looking to enhance your creative projects, these actions offer a robust solution. Consider exploring further use cases or integrating additional Cognitive Actions to expand your application's capabilities!