Create Stunning Images from Text Prompts with teaglis-kury/sana Cognitive Actions

In the world of AI and digital creativity, generating images from textual descriptions has become increasingly popular. The teaglis-kury/sana API provides a powerful Cognitive Action called Generate Image From Prompt that allows developers to create images based on customizable text prompts. This action not only supports a variety of settings but also offers enhanced control over the output, enabling developers to bring their creative visions to life seamlessly.
Prerequisites
Before you can start using the Cognitive Actions provided by the teaglis-kury/sana API, ensure you have the following:
- An API key for the Cognitive Actions platform. This will be used for authentication when making requests.
- Familiarity with JSON and HTTP requests, as you’ll need to format your input correctly.
Authentication typically involves passing your API key in the request headers to securely access the Cognitive Actions.
Cognitive Actions Overview
Generate Image From Prompt
The Generate Image From Prompt action generates an image based on a text prompt, allowing for customization with various settings such as image dimensions, guidance scales, and inference steps. This action falls under the image-generation category and is perfect for applications that require dynamic image creation based on user input or predefined prompts.
Input
The input for this action is a JSON object that includes the following fields:
- seed (integer, optional): Random seed for reproducibility. Leave blank to use a randomized seed.
Example:42 - width (integer, optional): Width of the output image in pixels. Default is
1024.
Example:512 - height (integer, optional): Height of the output image in pixels. Default is
1024.
Example:512 - prompt (string, required): Text prompt used to generate the output image. Default is a specific example.
Example:"frog" - guidanceScale (number, optional): Determines the strength of the classifier-free guidance. Range is
1 to 20, default is5.
Example:5 - negativePrompt (string, optional): Text prompt specifying elements to be excluded from the output.
Example:""(empty string) - pagGuidanceScale (number, optional): Scale for PAG guidance. Adjusts the influence of PAG for image generation. Range is
1 to 20, default is2.
Example:2 - numInferenceSteps (integer, optional): Total number of denoising steps during image generation. Minimum is
1, default is18.
Example:18
Here’s a practical example of the JSON input payload:
{
"seed": 42,
"width": 512,
"height": 512,
"prompt": "frog",
"guidanceScale": 5,
"negativePrompt": "",
"pagGuidanceScale": 2,
"numInferenceSteps": 18
}
Output
Upon successfully executing this action, the API returns a URL pointing to the generated image. For example:
https://assets.cognitiveactions.com/invocations/36f8f397-e87e-4442-af33-a309625b4f2a/db386194-0094-45c7-a217-f5393438e950.png
This URL can then be used to display the created image in your application.
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet demonstrating how to call the Generate Image From Prompt 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 = "c7ab5784-90a4-477c-9999-b06842fcfe75" # Action ID for Generate Image From Prompt
# Construct the input payload based on the action's requirements
payload = {
"seed": 42,
"width": 512,
"height": 512,
"prompt": "frog",
"guidanceScale": 5,
"negativePrompt": "",
"pagGuidanceScale": 2,
"numInferenceSteps": 18
}
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_KEYwith your actual API key. - The action ID for Generate Image From Prompt is included in the request.
- The input payload is structured according to the action's requirements.
Conclusion
The Generate Image From Prompt action from the teaglis-kury/sana API provides developers with a robust tool to create images directly from text prompts. By utilizing customizable parameters, developers can efficiently generate a wide range of images tailored to their specific needs. Whether you're building an art application, enhancing a game, or creating unique visuals for marketing, this action can significantly streamline your creative process. Explore the capabilities of this Cognitive Action and integrate it into your applications today!