Enhance Your Images with the Lightweight AI Model1 Cognitive Actions

24 Apr 2025
Enhance Your Images with the Lightweight AI Model1 Cognitive Actions

In the realm of image processing, the Lightweight AI Model1 offers developers a powerful toolset through its Cognitive Actions. These pre-built actions streamline the process of modifying images, enabling tasks like inpainting to be executed with high quality and efficiency. In this article, we'll delve into the capabilities of the image inpainting action and guide you through integrating it into your applications.

Prerequisites

To get started with the Cognitive Actions from the Lightweight AI Model1, you'll need an API key for authentication. Generally, this involves sending your API key in the headers of your requests. Ensure you have the necessary setup in place before diving into the specifics of the actions.

Cognitive Actions Overview

Perform Image Inpainting Using Flux Schnell Model

The Perform Image Inpainting Using Flux Schnell Model action allows you to modify images using a mask and a textual prompt. This action is particularly useful for tasks that require detailed image manipulation, such as filling in parts of an image based on specific guidance from the user.

Category: Image Processing

Input

The input for this action requires several fields, which allow for customization of the inpainting process. Below is the schema and an example of the JSON payload needed to invoke this action:

  • mask (string, URI): Upload a mask image for inpainting. White areas indicate regions to be inpainted, while black areas preserve the original image.
  • seed (integer, optional): A random seed value for reproducibility.
  • image (string, URI): The base image for inpainting.
  • width (integer, default: 1024): The output image width in pixels.
  • height (integer, default: 1024): The output image height in pixels.
  • prompt (string, default: "A bohemian-style female travel blogger..."): A textual prompt guiding the inpainting process.
  • loraList (array of strings, optional): List of Lora models to apply during generation.
  • loraScales (array of numbers, optional): Scaling factors for the corresponding Lora models.
  • outputFormat (string, default: "png"): The format of the output images (webp, jpg, png).
  • guidanceScale (number, default: 3.5): Controls adherence to the prompt.
  • outputQuality (integer, default: 100): Specifies image quality (0-100).
  • promptStrength (number, default: 0.8): The influence of the prompt in transformation (0-1).
  • numberOfOutputs (integer, default: 1): The number of output images (1-4).
  • numberOfInferenceSteps (integer, default: 28): The number of steps during inference (1-50).

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A fluffy, orange tabby cat curled up asleep in a sunbeam streaming through a window, its soft fur glowing with the warmth of the light; highly detailed 8K UHD photorealistic rendering, natural lighting, warm and inviting atmosphere, focus on softness and texture.",
  "outputFormat": "png",
  "outputQuality": 100,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 4
}

Output

The action typically returns a URL pointing to the generated image file. Here’s an example of what the output might look like:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/060ea98e-ccbe-4f29-bbb7-a8fc62c51ccf/077bec15-4cae-4ce7-acfe-4cf0caf4cf4f.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet that demonstrates how to call this Cognitive 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 = "72013cb0-88d6-479a-b2dd-a036af7b2bbc"  # Action ID for Perform Image Inpainting Using Flux Schnell Model

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A fluffy, orange tabby cat curled up asleep in a sunbeam streaming through a window, its soft fur glowing with the warmth of the light; highly detailed 8K UHD photorealistic rendering, natural lighting, warm and inviting atmosphere, focus on softness and texture.",
    "outputFormat": "png",
    "outputQuality": 100,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 4
}

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, you replace the COGNITIVE_ACTIONS_API_KEY and adjust the COGNITIVE_ACTIONS_EXECUTE_URL to match your endpoint. The action_id corresponds to the inpainting action, and the payload contains the necessary input for execution.

Conclusion

The Lightweight AI Model1’s Cognitive Actions offer an efficient way to enhance your image processing capabilities, particularly through the powerful inpainting action. By leveraging these pre-built functionalities, developers can easily integrate advanced image manipulation features into their applications. Consider exploring various use cases, such as content creation, artistic applications, or even automated photo editing, to fully utilize the potential of Cognitive Actions in your projects.