Generating Stunning Images with the ASTRA Cognitive Actions

The ASTRA Cognitive Actions offer developers a powerful way to create high-quality images using advanced text-to-image generation capabilities. Leveraging a decentralized model that rivals popular tools like Midjourney v6 and DALL-E 3, ASTRA supports multilingual prompts, fostering innovation and accessibility for all users. In this article, we'll explore how to effectively integrate the "Generate Decentralized High-Quality Images" action into your applications, allowing you to harness the creative potential of AI.
Prerequisites
To get started with ASTRA Cognitive Actions, you'll need the following:
- An API key from the Cognitive Actions platform. This key is essential for authenticating your requests.
- Basic knowledge of making HTTP requests, as you'll need to send JSON payloads to the API.
Conceptually, authentication typically involves passing the API key in the headers of your requests.
Cognitive Actions Overview
Generate Decentralized High-Quality Images
This action utilizes the ASTRA model to generate high-quality images from text descriptions. It serves as a versatile tool for developers looking to incorporate image generation into their applications, whether for creative projects, marketing materials, or interactive experiences.
Input
The action accepts a variety of parameters structured as follows:
{
"mask": "string (uri)",
"seed": "integer",
"image": "string (uri)",
"width": "integer",
"height": "integer",
"prompt": "string",
"refine": "string",
"loraScale": "number",
"scheduler": "string",
"guidanceScale": "number",
"denoisingSteps": "integer",
"negativePrompt": "string",
"numberOfImages": "integer",
"promptStrength": "number",
"refinementSteps": "integer",
"alternateWeights": "string",
"includeWatermark": "boolean",
"highNoiseFraction": "number",
"bypassSafetyChecker": "boolean"
}
Here’s an example input:
{
"width": 1024,
"height": 1024,
"prompt": "mining space cargo \"FCM-B2\" crossing an deep space, rich in detail, close-up, ultra detailed, real photography, space opera",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"denoisingSteps": 50,
"negativePrompt": "deformed iris, deformed pupils, semi-realistic, text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, blurry, low quality , bad quality , Not detailed, watermark, deformed figures, lack of details, bad anatomy, blurry, extra arms, extra fingers, poorly drawn hands, disfigured, tiling, deformed, mutated ,ugly, disfigured, low quality, blurry ,distorted, blur, smooth, low-quality, warm, haze, over-saturated, high-contrast, out of focus, dark, worst quality, low quality",
"numberOfImages": 1,
"promptStrength": 0.8,
"includeWatermark": true,
"highNoiseFraction": 0.8
}
Output
The action typically returns an array of image URLs based on the input parameters provided. Here’s an example of the response:
[
"https://assets.cognitiveactions.com/invocations/d7579584-93be-4579-a62f-8750ffd40260/acb0e30e-4d46-4710-86fb-72e1d4a04e5d.png"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet demonstrating how to invoke the "Generate Decentralized High-Quality Images" 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 = "9a80722e-f239-4627-bdf3-278a344379ba" # Action ID for Generate Decentralized High-Quality Images
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "mining space cargo \"FCM-B2\" crossing an deep space, rich in detail, close-up, ultra detailed, real photography, space opera",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"denoisingSteps": 50,
"negativePrompt": "deformed iris, deformed pupils, semi-realistic, text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, blurry, low quality , bad quality , Not detailed, watermark, deformed figures, lack of details, bad anatomy, blurry, extra arms, extra fingers, poorly drawn hands, disfigured, tiling, deformed, mutated ,ugly, disfigured, low quality, blurry ,distorted, blur, smooth, low-quality, warm, haze, over-saturated, high-contrast, out of focus, dark, worst quality, low quality",
"numberOfImages": 1,
"promptStrength": 0.8,
"includeWatermark": True,
"highNoiseFraction": 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, and note that the endpoint URL and request structure are illustrative. The action_id corresponds to the "Generate Decentralized High-Quality Images" action.
Conclusion
The ASTRA Cognitive Actions empower developers to create stunning images effortlessly through advanced AI capabilities. By integrating the "Generate Decentralized High-Quality Images" action into your applications, you can explore a multitude of creative possibilities. Consider experimenting with different prompts and parameters to unlock the full potential of this powerful tool. Happy coding!