Generate Stunning Images with the chmirandaalos/chma Cognitive Actions

In the realm of digital creativity, the ability to generate images from textual prompts opens up exciting possibilities for developers. The chmirandaalos/chma API provides a powerful Cognitive Action that allows you to create high-quality images based on detailed descriptions. This article delves into the features of the Generate Image with Custom Prompt action, guiding you through its capabilities and how to integrate it into your applications.
Prerequisites
To leverage the Cognitive Actions provided by the chmirandaalos/chma API, you will need:
- An API key for the Cognitive Actions platform to authenticate your requests.
- A basic understanding of JSON and how to structure API calls.
Authentication is typically handled by including your API key in the request headers, ensuring secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate Image with Custom Prompt
The Generate Image with Custom Prompt action allows you to create images from a text prompt while offering various customization options, including inpainting, aspect ratio, and output quality. You can choose between two inference models: 'dev' for high-quality results or 'schnell' for faster generation.
Input
The input for this action is structured as a JSON object, which includes several fields, some of which are required while others are optional. Here's a breakdown of the input schema:
- textPrompt (required): A detailed textual description guiding the image generation.
- aspectRatio (optional): Specifies the aspect ratio of the image. Options include "1:1", "16:9", "custom", etc.
- imageWidth (optional): Specifies the width of the image (only applicable if aspect ratio is 'custom').
- imageHeight (optional): Specifies the height of the image (only applicable if aspect ratio is 'custom').
- inferenceModel (optional): Choose between 'dev' for quality or 'schnell' for speed.
- numberOfOutputs (optional): Defines how many images to generate (1-4).
- imageOutputFormat (optional): Specifies the image format (e.g., "webp", "jpg", "png").
- imageOutputQuality (optional): Sets the quality level for the output image.
Example Input:
{
"textPrompt": "\"cH._.MA\" minimalist logo illustration Cover...",
"aspectRatio": "4:5",
"mainLoraScale": 1,
"inferenceModel": "dev",
"numberOfOutputs": 1,
"imageOutputFormat": "png",
"imageOutputQuality": 90,
"textPromptStrength": 0.8,
"additionalLoraScale": 1,
"diffusionGuidanceScale": 3.5,
"numberOfInferenceSteps": 28
}
Output
The action typically returns a URL pointing to the generated image. The output format is a simple array containing the image link, which can be used to display or download the image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/f771ffeb-3684-43ea-a54a-e2e1c6846173/19a36c47-0cc0-477b-8a0b-fdede3e95966.png"
]
Conceptual Usage Example (Python)
Here’s how you might implement a call to the Generate Image with Custom Prompt 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 = "61732899-e0e8-4c2e-b254-a459522a07c5" # Action ID for Generate Image with Custom Prompt
# Construct the input payload based on the action's requirements
payload = {
"textPrompt": "\"cH._.MA\" minimalist logo illustration Cover...",
"aspectRatio": "4:5",
"mainLoraScale": 1,
"inferenceModel": "dev",
"numberOfOutputs": 1,
"imageOutputFormat": "png",
"imageOutputQuality": 90,
"textPromptStrength": 0.8,
"additionalLoraScale": 1,
"diffusionGuidanceScale": 3.5,
"numberOfInferenceSteps": 28
}
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 see how to set up the input payload and handle the response from the Cognitive Actions API. Make sure to replace the placeholder values with your actual API key and endpoint URL.
Conclusion
The Generate Image with Custom Prompt action from the chmirandaalos/chma API is a powerful tool for developers looking to create dynamic, customized images from textual descriptions. By leveraging its capabilities, you can enhance your applications with unique visual content. Consider exploring additional use cases, such as integrating this action into creative apps, marketing tools, or content generation platforms. Happy coding!