Generate Stunning Images with the georgimarkov22/magma11 Cognitive Action

In this blog post, we'll explore the capabilities of the georgimarkov22/magma11 Cognitive Action, specifically focusing on the powerful Generate Image with Custom Parameters action. This action allows developers to generate customized images using advanced models, offering precise control over various aspects like size, aspect ratio, and output format. By leveraging these pre-built actions, developers can quickly enhance their applications with advanced image generation capabilities.
Prerequisites
Before you get started, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Familiarity with making HTTP requests and handling JSON data in your preferred programming language.
To authenticate, you'll typically pass your API key in the headers of your requests.
Cognitive Actions Overview
Generate Image with Custom Parameters
The Generate Image with Custom Parameters action is designed for generating highly customized images. It leverages the 'dev' or 'schnell' model, which allows users to control various parameters such as image size, aspect ratio, and format. This flexibility enables developers to create images that meet specific requirements efficiently.
Input
The action requires a JSON object as input, where the only mandatory field is the prompt. Below is a detailed schema of the input parameters:
- prompt (required): Text prompt guiding the image generation.
- model: Specify either
devorschnell. Default isdev. - width: Width of the generated image (in pixels).
- height: Height of the generated image (in pixels).
- aspectRatio: Specifies the aspect ratio, with options like
1:1,16:9, orcustom. - outputCount: Total number of images to generate (between 1 and 4).
- outputFormat: Format of the output images (options:
webp,jpg,png). - guidanceScale: Controls the guidance during the generation.
- goFast: Enables faster predictions with a quantized model.
- seed, image, mask, and other parameters for additional customization.
Here’s a practical example of the JSON payload needed to invoke this action:
{
"model": "dev",
"goFast": false,
"height": 1080,
"prompt": "close up of magma11 mgm2011 on foreground facing the camera. he is wearing metal lorica segmentata. he is full of sadness in a heroic pose standing on the shore of a stormy sea. the wind blows his short hair. sun lights him from left side.. at the background heavy storm clouds hang over the sea. a ray of sunlight shines on a old wrecked pirate ship abandoned at sea",
"aspectRatio": "16:9",
"outputCount": 1,
"outputFormat": "webp",
"guidanceScale": 3,
"loraIntensity": 1,
"outputQuality": 80,
"inferenceSteps": 28,
"megapixelCount": "1",
"promptStrength": 0.8,
"additionalLoraIntensity": 1
}
Output
Upon successful execution, you will receive a response containing the generated image(s). The output typically includes a URL pointing to the generated image. Here’s an example of the output:
[
"https://assets.cognitiveactions.com/invocations/0e796149-ffb0-4fe3-90be-920df395d7b7/f9419f8a-9b2d-47f6-9cc5-9821cca103f6.webp"
]
Conceptual Usage Example (Python)
Here’s how you could structure a Python script to call this 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 = "f451c32c-5610-4a24-9d4c-c80f4df6dee4" # Action ID for Generate Image with Custom Parameters
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"height": 1080,
"prompt": "close up of magma11 mgm2011 on foreground facing the camera. he is wearing metal lorica segmentata. he is full of sadness in a heroic pose standing on the shore of a stormy sea. the wind blows his short hair. sun lights him from left side.. at the background heavy storm clouds hang over the sea. a ray of sunlight shines on a old wrecked pirate ship abandoned at sea",
"aspectRatio": "16:9",
"outputCount": 1,
"outputFormat": "webp",
"guidanceScale": 3,
"loraIntensity": 1,
"outputQuality": 80,
"inferenceSteps": 28,
"megapixelCount": "1",
"promptStrength": 0.8,
"additionalLoraIntensity": 1
}
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
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 and input payload are specified according to the requirements of the Generate Image with Custom Parameters action. The endpoint structure and headers are also illustrative, aiming to provide a clear guide for developers.
Conclusion
The Generate Image with Custom Parameters action in the georgimarkov22/magma11 specification opens up exciting possibilities for developers looking to integrate advanced image generation capabilities into their applications. With options for customization, speed, and quality, these Cognitive Actions provide a powerful toolset for creative projects. Explore further use cases and experiment with different prompts and parameters to unlock the full potential of your applications!