Unleash Your Creativity: Integrating Image Generation with the leonardoa2/cult6-mask Action

21 Apr 2025
Unleash Your Creativity: Integrating Image Generation with the leonardoa2/cult6-mask Action

The leonardoa2/cult6-mask API offers a powerful set of Cognitive Actions for developers looking to enhance their applications with advanced image generation capabilities. One of the standout features is its ability to generate images using custom input and inpainting techniques, allowing for a high degree of customization and creativity. By leveraging this API, you can produce stunning visuals with various options for model selection, prompt influence, and aspect ratio configuration, making it ideal for a range of projects—from artistic endeavors to practical applications.

Prerequisites

Before you begin integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests in your development environment.
  • Basic understanding of JSON format for structuring your input and output.

Authentication typically involves passing your API key in the request headers, which allows you to securely access the Cognitive Actions features.

Cognitive Actions Overview

Generate Image with Custom Inpainting

This action allows you to generate images by combining custom prompts with inpainting techniques, tailored for both speedy and detailed outputs. It is categorized under image-generation.

Input

The input for this action consists of several fields, with prompt being required. Below is a breakdown of the input schema along with an example:

  • Required:
    • prompt (string): The textual description guiding the image generation.
  • Optional:
    • mask (string): A URI pointing to an image mask for inpainting (overrides width and height).
    • seed (integer): A random seed for reproducibility.
    • image (string): A URI for the input image for image-to-image generation.
    • width (integer): Custom width (applies only if aspect_ratio is 'custom').
    • height (integer): Custom height (applies only if aspect_ratio is 'custom').
    • fastMode (boolean): Enable faster predictions using an optimized model.
    • chosenModel (string): Specify the model for inference, options include "dev" or "schnell".
    • imageMegapixels (string): Choose between 0.25 and 1 megapixels.
    • numberOfOutputs (integer): Number of images to generate (1 to 4).
    • promptInfluence (number): Influence level of the prompt on the generated image.
    • imageAspectRatio (string): Aspect ratio of the output image.
    • imageOutputFormat (string): The format of the output image (webp, jpg, png).
    • imageOutputQuality (integer): Quality level from 0 to 100.
    • Other parameters for fine-tuning model behavior.

Example Input:

{
  "prompt": "A raw, grainy 35mm film photograph, capturing an intense, unfiltered moment under the harsh glare of a direct flash. The extreme overexposure from the flash creates stark, blown-out highlights and deep, crushing shadows, stripping away any sense of depth...",
  "fastMode": false,
  "chosenModel": "dev",
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "promptInfluence": 0.8,
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 100,
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28,
  "loraApplicationScale": 1,
  "diffusionGuidanceScale": 3
}

Output

The action typically returns a list of image URLs pointing to the generated content. Here’s an example of the output you might receive:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/222a655d-8d2c-4e92-85aa-80475aa40a1a/88c013e5-6f02-4780-8941-7a28f7f90fbb.webp"
]

Conceptual Usage Example (Python)

Here’s how you might implement this action using Python to send a request to the Cognitive Actions endpoint.

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 = "94c246a7-b02d-46f4-a817-c1b7cd6b35e7"  # Action ID for Generate Image with Custom Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "A raw, grainy 35mm film photograph, capturing an intense, unfiltered moment under the harsh glare of a direct flash...",
    "fastMode": False,
    "chosenModel": "dev",
    "imageMegapixels": "1",
    "numberOfOutputs": 1,
    "promptInfluence": 0.8,
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "webp",
    "imageOutputQuality": 100,
    "additionalLoraScale": 1,
    "inferenceStepsCount": 28,
    "loraApplicationScale": 1,
    "diffusionGuidanceScale": 3
}

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 payload variable is structured based on the action's input schema, ensuring that you properly configure the parameters required for image generation. The code shows how to handle the response and any potential errors gracefully.

Conclusion

The leonardoa2/cult6-mask Cognitive Action for image generation offers a robust toolset for developers looking to incorporate advanced visual content into their applications. By utilizing the capabilities of custom inpainting and flexible input options, you can create unique images tailored to your needs. Start exploring the creative possibilities today, and consider extending your application with additional features as you grow more familiar with the API!