Generate Customized Images Fast and Easy with mktbangbang/luina Cognitive Actions

22 Apr 2025
Generate Customized Images Fast and Easy with mktbangbang/luina Cognitive Actions

Creating stunning images tailored to your specifications can significantly enhance user experiences in applications. The mktbangbang/luina Cognitive Actions offer a powerful way to generate customized images using advanced inpainting techniques. This set of actions enables developers to leverage capabilities such as adjustable dimensions, output quality, and optimized processing—all with just a few lines of code.

Prerequisites

To get started with the mktbangbang/luina Cognitive Actions, you'll need an API key from the Cognitive Actions platform. This key will allow you to authenticate your requests. Typically, you would pass this API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Customized Image with Inpainting

The Generate Customized Image with Inpainting action generates customized images using inpainting techniques. This action allows you to specify various parameters such as dimensions, output quality, and model inference settings. You can fine-tune aspects of the image generation process, including prompt strength and guidance scale, to achieve the desired results.

Input

The action requires a prompt and supports several optional fields. Here’s a brief overview of the schema:

  • prompt (required): Descriptive text that guides the image generation.
  • mask (optional): URI of the image mask for inpainting mode.
  • seed (optional): Random seed for consistent image generation.
  • image (optional): URI of the input image for image-to-image or inpainting mode.
  • model (optional): Select the model for inference (default: "dev").
  • width and height (optional): Dimensions of the generated image when aspect ratio is 'custom'.
  • goFast (optional): Enable for speed optimization.
  • aspectRatio (optional): Defines the aspect ratio of the generated image.
  • imageFormat (optional): Format of the output images (default: "webp").
  • imageQuality (optional): Quality of saved output images (default: 80).
  • guidanceScale (optional): Influences the guidance of the diffusion process (default: 3).
  • numOutputs (optional): Number of image outputs to generate (default: 1).

Here’s a practical example of the JSON payload needed to invoke the action:

{
  "model": "dev",
  "goFast": false,
  "prompt": "A flatlay image of several TOK perfume bottles on a white background. The bottles should have different shades of liquid, showcasing the variety of the TOK fragrance line. Include a few TOK bottles with different capacity. The composition should be balanced and aesthetically pleasing, with the bottles arranged in a seemingly random yet harmonious manner. The lighting should be bright and even, highlighting the details of each bottle. The overall image should evoke a sense of luxury, sophistication, and variety.",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "imageFormat": "webp",
  "imageQuality": 80,
  "guidanceScale": 3,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "outputMegapixels": "1",
  "numInferenceSteps": 28
}

Output

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

[
  "https://assets.cognitiveactions.com/invocations/c1b14d15-f5d5-46ca-b857-0d7e47b36dcd/6ecf969c-6e07-4f45-9970-0696ea0d3271.webp"
]

Conceptual Usage Example (Python)

Here’s how you might structure a Python request 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 = "d8e303e6-6a3c-4b2f-add5-e8da1fe5e7dc"  # Action ID for Generate Customized Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": false,
    "prompt": "A flatlay image of several TOK perfume bottles on a white background. The bottles should have different shades of liquid, showcasing the variety of the TOK fragrance line. Include a few TOK bottles with different capacity. The composition should be balanced and aesthetically pleasing, with the bottles arranged in a seemingly random yet harmonious manner. The lighting should be bright and even, highlighting the details of each bottle. The overall image should evoke a sense of luxury, sophistication, and variety.",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "imageFormat": "webp",
    "imageQuality": 80,
    "guidanceScale": 3,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "outputMegapixels": "1",
    "numInferenceSteps": 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 code snippet, replace the placeholders with your actual API key and adjust the action ID accordingly. The payload structure follows the schema requirements, ensuring that all necessary inputs are supplied.

Conclusion

The mktbangbang/luina Cognitive Actions, particularly the Generate Customized Image with Inpainting, offer developers a robust toolset for creating tailored images quickly and efficiently. With adjustable parameters and a user-friendly API structure, integrating these capabilities into your applications can significantly enhance visual content and user engagement. Explore further use cases such as image customization for marketing materials or personalized user experiences to leverage the full potential of these actions!