Transform Your Creativity: Integrate Image Generation with mayoita/max-mayoita Cognitive Actions

In today's digital landscape, the ability to generate high-quality images programmatically can significantly enhance applications, from creative design tools to automated content generation. The mayoita/max-mayoita API offers powerful Cognitive Actions that enable developers to create stunning images using advanced techniques like inpainting and image-to-image transformations. This blog post will take you through how to leverage these capabilities effectively, showcasing the "Generate Image with Custom Settings" action.
Prerequisites
Before you begin using the Cognitive Actions provided by the mayoita/max-mayoita API, ensure you have:
- An API key for the Cognitive Actions platform.
- Basic knowledge of JSON and Python for making API calls.
Authentication typically involves passing your API key in the request headers, allowing you to securely access the API's functionalities.
Cognitive Actions Overview
Generate Image with Custom Settings
The Generate Image with Custom Settings action allows you to create high-quality images by specifying various parameters, including prompt intensity, model selection, and output quality. This action falls under the category of image-generation.
Input Schema: The input for this action requires a structured JSON object. Here’s a breakdown of the key fields:
- prompt (required): A descriptive text prompt for image generation.
- model: Choose between
"dev"or"schnell"for different inference performance. - width and height: Define the image dimensions (if applicable).
- image: A URI for the input image when using image-to-image functionality.
- numberOfOutputs: Specify how many images to generate (1-4).
- imageOutputFormat: Select the format of the output image (e.g., "webp", "jpg", "png").
- inferenceStepCount: Number of steps for denoising the image.
Example Input:
{
"model": "dev",
"prompt": "Cinematic portrait of mayoita as human male, bald-headed, while struggling with the helm of a sailing ship navigating under a stormy sky and rough seas.",
"mainLoraScale": 1,
"numberOfOutputs": 1,
"imageAspectRatio": "16:9",
"imageOutputFormat": "webp",
"imageOutputQuality": 90,
"inferenceStepCount": 49,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8,
"diffusionGuidanceScale": 2.38
}
Output: When the action is executed successfully, it returns a URL link to the generated image. Here’s an example of a potential output:
[
"https://assets.cognitiveactions.com/invocations/8b5bdab0-6cfe-4abd-b102-87418a76ac27/b96ca69d-0a5e-4872-971a-79540e0a62da.webp"
]
Conceptual Usage Example (Python): Here's how you might invoke this 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 = "7cedbb6f-39c9-4127-a4e2-e880de7ac78e" # Action ID for Generate Image with Custom Settings
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "Cinematic portrait of mayoita as human male, bald-headed, while struggling with the helm of a sailing ship navigating under a stormy sky and rough seas.",
"mainLoraScale": 1,
"numberOfOutputs": 1,
"imageAspectRatio": "16:9",
"imageOutputFormat": "webp",
"imageOutputQuality": 90,
"inferenceStepCount": 49,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8,
"diffusionGuidanceScale": 2.38
}
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 the placeholder for your API key.
- Construct the input payload based on the action’s requirements.
- The endpoint URL and request structure are illustrative; make sure to adjust based on the actual API specifications.
Conclusion
The mayoita/max-mayoita Cognitive Actions offer a robust set of tools for developers looking to incorporate advanced image generation capabilities into their applications. By leveraging the "Generate Image with Custom Settings" action, you can create stunning visual content tailored to your specific requirements.
Explore these actions further to enhance your applications, and consider experimenting with the various parameters to achieve the best results. Happy coding!