Generate Stunning Images with the Hyper-SD Cognitive Actions

In the rapidly evolving world of artificial intelligence, image synthesis has become a pivotal technology, enabling developers to create visually stunning content with ease. The Hyper-SD Cognitive Actions provide a powerful interface for generating images using the Hyper-SD Trajectory Segmented Consistency Model. By leveraging these pre-built actions, developers can enhance their applications with high-quality image generation capabilities while customizing parameters such as dimensions and output formats.
Prerequisites
Before you dive into using the Hyper-SD Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic understanding of JSON and RESTful API concepts.
Authentication typically involves passing your API key in the request headers, allowing you to securely access the Cognitive Actions functionalities.
Cognitive Actions Overview
Generate Image with Hyper-SD
The Generate Image with Hyper-SD action enables users to synthesize images efficiently, enhancing both speed and quality. By controlling parameters such as width, height, and output format, developers can tailor the image generation process to meet their specific needs.
Input
The input for this action consists of several parameters, which can be structured as follows:
{
"seed": 12345,
"width": 1024,
"height": 1024,
"prompt": "a photo of a cat",
"outputFormat": "webp",
"outputQuality": 80,
"numberOfOutputs": 1
}
- seed (optional): An integer representing the random seed for generating outputs. If left blank, a randomized seed will be used.
- width (optional): The width of the output image in pixels. Default is 1024.
- height (optional): The height of the output image in pixels. Default is 1024.
- prompt (required): A string describing the content of the desired image.
- outputFormat (optional): The file format for the output image, with options being 'webp', 'jpg', or 'png'. Default is 'webp'.
- outputQuality (optional): An integer representing the quality of the output image, ranging from 0 (lowest) to 100 (highest). Default is 80.
- negativePrompt (optional): A string to specify elements to exclude from the image.
- numberOfOutputs (optional): An integer indicating the number of images to generate, with a maximum of 4 and a minimum of 1. Default is 1.
Output
Upon successful execution, the action returns an array containing URLs to the generated images. Here’s an example of the output:
[
"https://assets.cognitiveactions.com/invocations/95cf04bf-c25c-4ec1-8b19-9f713877e400/3272f8d0-fb1a-4004-ad04-4b44755558ff.webp"
]
This URL points to the synthesized image based on the provided input parameters.
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet to illustrate how you might invoke the Generate Image with Hyper-SD 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 = "6e6a8fe3-f65f-4362-8f7d-1e23730f3672" # Action ID for Generate Image with Hyper-SD
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "a photo of a cat",
"outputFormat": "webp",
"outputQuality": 80,
"numberOfOutputs": 1
}
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, you need to replace the placeholder for the API key and endpoint with your actual credentials. The input payload is structured according to the action's requirements, and the response is handled gracefully to accommodate potential errors.
Conclusion
The Hyper-SD Cognitive Actions provide a robust solution for developers looking to integrate high-quality image generation into their applications. By utilizing parameters like dimensions, output format, and quality, you can create images that meet your specific requirements. Explore the possibilities of image synthesis with Hyper-SD and consider how it can enhance your projects today!