Generate Custom Images Effortlessly with the Hadasadler/Lironai Cognitive Actions

23 Apr 2025
Generate Custom Images Effortlessly with the Hadasadler/Lironai Cognitive Actions

In the world of digital creativity, generating custom images can be a game changer for developers looking to enhance their applications with unique visuals. The Hadasadler/Lironai Cognitive Actions provide a powerful API for generating images using advanced techniques like inpainting and image-to-image transformations. With features that allow for detailed customization including aspect ratio, resolution, and output quality, developers can create stunning images tailored to their needs.

Prerequisites

Before diving into the integration of the Cognitive Actions, ensure you have the following:

  • API Key: You’ll need an API key to authenticate your requests to the Cognitive Actions platform.
  • Environment Setup: Set up your development environment to make HTTP requests, such as using Python with the requests library.

Authentication is typically handled by including your API key in the request headers, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Custom Image

The Generate Custom Image action allows you to create custom images based on textual prompts and optional parameters for detailed customization. This action falls under the image-generation category.

Input

The input for this action is structured as follows:

  • prompt (required): A text prompt to guide the image generation. For best results, include specific keywords used during training.
  • model: Choose between "dev" for detailed outputs or "schnell" for faster generation.
  • aspectRatio: Define the aspect ratio of the generated image, with options like "16:9" or "custom".
  • width / height: Specify dimensions when custom aspect ratio is selected.
  • numberOfOutputs: Indicate how many images to generate (1 to 4).
  • Additional parameters like loraScale, guidanceIntensity, and imageOutputQuality allow for further customization.

Here is an example of the JSON payload needed to invoke this action:

{
  "model": "dev",
  "prompt": "lironai  A man looking to the camera",
  "loraScale": 1,
  "megapixels": "1",
  "aspectRatio": "16:9",
  "outputFormat": "jpg",
  "enableFastMode": false,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "guidanceIntensity": 3,
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 28
}

Output

The output of the action will typically be a URL to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/88d8ad6e-56d2-48a2-99f1-eb55996de0b9/efb18327-3aee-4306-a501-c41958211efc.jpg"
]

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 = "11b7c6d7-a994-4ead-a7f5-b822eb824137"  # Action ID for Generate Custom Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "lironai  A man looking to the camera",
    "loraScale": 1,
    "megapixels": "1",
    "aspectRatio": "16:9",
    "outputFormat": "jpg",
    "enableFastMode": False,
    "numberOfOutputs": 1,
    "promptIntensity": 0.8,
    "guidanceIntensity": 3,
    "imageOutputQuality": 80,
    "additionalLoraScale": 1,
    "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()

    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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable holds the structured input based on the action's requirements. The API call is made to a hypothetical endpoint, and the result is printed in a readable format.

Conclusion

The Hadasadler/Lironai Cognitive Actions provide developers with a powerful way to generate custom images tailored to their applications. With a variety of parameters and options for customization, the potential use cases are vast, from creating unique artwork to enhancing user interfaces. To get started, set up your environment, follow the examples provided, and unlock your creativity with these cognitive actions!