Enhance Your Applications with Image Variations from the egsakash/akashi-v2 Cognitive Actions

In today's digital landscape, image generation and manipulation have become essential tools for developers looking to enrich their applications. The egsakash/akashi-v2 API offers a powerful set of Cognitive Actions that allow developers to generate image variations based on input images and text prompts. This blog post will guide you through using the Generate Image Variations action, exploring its capabilities, input requirements, and how to integrate it seamlessly into your applications.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following prerequisites:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Basic understanding of JSON and RESTful APIs.
Authentication typically involves passing your API key in the request headers, allowing secure access to the action functionalities.
Cognitive Actions Overview
Generate Image Variations
The Generate Image Variations action allows you to create variations of a specified image based on textual input. This action is highly configurable, enabling you to set parameters like the random seed, image dimensions, prompt strength, and more.
Input
The input for this action follows the CompositeRequest schema, which includes the following fields:
- seed (integer): Random seed for variation generation. Leave blank for a random seed.
- image (string): A URI of the starting image for variations. If provided, width and height settings are ignored.
- width (integer): Width of the output image in pixels. Supported values are limited to specific dimensions (e.g., 128, 256, 512, etc.).
- height (integer): Height of the output image in pixels. Similar constraints as width.
- prompt (string): Textual input guiding the generation process.
- scheduler (string): Scheduling algorithm for the generation process (e.g., DDIM, K_EULER).
- guidanceScale (number): Strength of guidance for the generation, ranging from 1 to 20.
- negativePrompt (string): Traits to exclude from the generated image.
- promptStrength (number): Influence of the prompt on the initial image, ranging from 0.0 to 1.0.
- numberOfOutputs (integer): Count of generated images (between 1 and 4).
- disableSafetyCheck (boolean): Option to disable safety checks at your own risk.
- numberOfInferenceSteps (integer): Steps for the denoising process (1 to 500).
Example Input:
{
"width": 512,
"height": 512,
"prompt": "a photo of cjw ,icon of a cjw person , icon , vector art , trending on artstation , colored , asthetic color",
"scheduler": "K_EULER_ANCESTRAL",
"guidanceScale": 7.5,
"negativePrompt": "bad , ugly , distorted , no face , hands , ugly creature , disfigured , worst ",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"disableSafetyCheck": false,
"numberOfInferenceSteps": 50
}
Output
The output consists of a list of URIs pointing to the generated images.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/8d5edd98-53cf-47d6-935d-cf99b1ef4eb6/4dcf227d-a8a9-4c7b-b40a-c28066c02570.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how you can call the Generate Image Variations 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 = "dd183376-6dd8-44d4-92f5-a8ddce3283f4" # Action ID for Generate Image Variations
# Construct the input payload based on the action's requirements
payload = {
"width": 512,
"height": 512,
"prompt": "a photo of cjw ,icon of a cjw person , icon , vector art , trending on artstation , colored , asthetic color",
"scheduler": "K_EULER_ANCESTRAL",
"guidanceScale": 7.5,
"negativePrompt": "bad , ugly , distorted , no face , hands , ugly creature , disfigured , worst ",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"disableSafetyCheck": False,
"numberOfInferenceSteps": 50
}
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. The action_id is set to the ID of the Generate Image Variations action. The input payload is constructed according to the schema, allowing you to customize various parameters for image generation.
Conclusion
The egsakash/akashi-v2 Cognitive Actions empower developers to create engaging and dynamic visual content with ease. By leveraging the Generate Image Variations action, you can enhance your applications, offering unique images tailored to user specifications. Whether for artistic purposes or improving user experience, these actions provide a robust solution for image generation.
Explore the potential of these Cognitive Actions to take your application to the next level!