Generate Stunning Images with the sudheertd/msudheer Cognitive Actions

In the realm of artificial intelligence, image generation has gained immense popularity, enabling developers to create visually stunning graphics with ease. The sudheertd/msudheer Cognitive Actions offer a powerful solution for generating high-quality images based on customizable parameters. This article will guide you through the capabilities of the provided actions, focusing on how to integrate them into your applications effectively.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Basic knowledge of JSON and RESTful API concepts.
- Familiarity with making HTTP requests in your programming language of choice (we'll use Python for examples).
To authenticate your requests, you'll typically pass your API key in the headers of your requests.
Cognitive Actions Overview
Generate Image Using Prediction
The Generate Image Using Prediction action allows you to create high-quality images using a variety of parameters. This action supports inpainting and image-to-image modes and grants you the flexibility to customize output formats and quality.
Input
The input schema for this action is quite comprehensive. Here are the required and optional fields:
- Required:
prompt: A string containing a description for the image generation.
- Optional:
mask: URL of the image mask for inpainting.seed: An integer for a random seed to generate reproducible images.image: URI of the input image for image-to-image or inpainting mode.width: Image width (256 to 1440).height: Image height (256 to 1440).loraScale: Number indicating the strength of the main LoRA application.inferenceModel: Model selection, either "dev" or "schnell".promptStrength: Strength of the prompt when using img2img (0 to 1).numberOfOutputs: The number of images to generate (1 to 4).imageAspectRatio: Aspect ratio for the image.imageOutputFormat: Format of the output images (webp, jpg, png).imageOutputQuality: Quality level for the output images (0 to 100).- Other LoRA related parameters and settings.
Example Input:
{
"prompt": "Photo of MSUDHEER displaying a subtle, struggling against a vivid black background. His hair is neatly styled, and his eyes gaze directly into the camera with a evilness and cruelty with smile. MSUDHEER wears a casual grey jacket over a light pink shirt, adding to his approachable and relaxed demeanor. . The overall atmosphere of the photo is light and engaging, capturing MSUDHEER’s personality in a evil expressions",
"loraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"numberOfOutputs": 4,
"imageAspectRatio": "1:1",
"imageOutputFormat": "jpg",
"imageOutputQuality": 90,
"additionalLoraScale": 1,
"inferenceStepsCount": 28,
"diffusionGuidanceScale": 3.5
}
Output
The output of this action is typically a list of URLs pointing to the generated images.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/d2aa5901-a411-48ac-9bc4-1ee2510f9694/f1325a8e-fa89-4b22-b023-a3814724bdb0.jpg",
"https://assets.cognitiveactions.com/invocations/d2aa5901-a411-48ac-9bc4-1ee2510f9694/ae0309ac-17d6-4a8f-a8c3-295b33bd9dfd.jpg",
"https://assets.cognitiveactions.com/invocations/d2aa5901-a411-48ac-9bc4-1ee2510f9694/70e77d40-f3d2-4d15-90d4-233952bfd2d4.jpg",
"https://assets.cognitiveactions.com/invocations/d2aa5901-a411-48ac-9bc4-1ee2510f9694/9f70b830-5f7c-4506-a89d-aff9354b63de.jpg"
]
Conceptual Usage Example (Python)
Here’s how you might invoke the Generate Image Using Prediction action in 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 = "c94d1073-2035-4ddf-a167-216f6aaae4be" # Action ID for Generate Image Using Prediction
# Construct the input payload based on the action's requirements
payload = {
"prompt": "Photo of MSUDHEER displaying a subtle, struggling against a vivid black background. His hair is neatly styled, and his eyes gaze directly into the camera with a evilness and cruelty with smile. MSUDHEER wears a casual grey jacket over a light pink shirt, adding to his approachable and relaxed demeanor. . The overall atmosphere of the photo is light and engaging, capturing MSUDHEER’s personality in a evil expressions",
"loraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"numberOfOutputs": 4,
"imageAspectRatio": "1:1",
"imageOutputFormat": "jpg",
"imageOutputQuality": 90,
"additionalLoraScale": 1,
"inferenceStepsCount": 28,
"diffusionGuidanceScale": 3.5
}
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}
)
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 Using Prediction is used to specify which action to execute.
- The input payload is structured according to the action's requirements.
Conclusion
The sudheertd/msudheer Cognitive Actions empower developers to seamlessly integrate image generation capabilities into their applications. By utilizing the Generate Image Using Prediction action, you can create stunning visuals tailored to your specific needs. Explore the possibilities, experiment with different parameters, and elevate your applications with these powerful tools!