Generate Stunning Images with the Lightweight AI Model 3.4 Cognitive Actions

21 Apr 2025
Generate Stunning Images with the Lightweight AI Model 3.4 Cognitive Actions

In the world of image generation, the Lightweight AI Model 3.4 provides developers with powerful tools to create unique and engaging visuals through its Cognitive Actions. These pre-built actions simplify the process of generating and modifying images, enabling developers to enhance their applications with advanced image manipulation capabilities. With features like customizable prompts, inpainting, and various output formats, you can effortlessly integrate sophisticated image generation into your projects.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which will authenticate your requests.
  • Basic knowledge of JSON structures and HTTP requests.

To authenticate, you typically pass your API key in the request headers.

Cognitive Actions Overview

Generate and Inpaint Image

The Generate and Inpaint Image action allows you to create and modify images using a composite approach. By uploading a base image and a mask, you can specify which areas should be altered and which should remain unchanged. This action is particularly useful for applications requiring creative image modifications based on user input.

Input

The input for this action is structured as follows:

{
  "mask": "https://example.com/mask.png",
  "seed": 42,
  "image": "https://example.com/base_image.png",
  "width": 1024,
  "height": 1024,
  "prompt": "A bohemian-style female travel blogger with sun-kissed skin and messy beach waves",
  "inpaint": false,
  "loraList": [],
  "imageCount": 1,
  "loraScales": [],
  "outputFormat": "png",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "taskScheduler": "K_EULER",
  "inferenceSteps": 28,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "controlStrength": 0.2,
  "controlNetEnabled": false
}

Key Fields:

  • mask: A URI for the mask image used in inpainting.
  • image: A URI for the base image.
  • width and height: Dimensions of the output image.
  • prompt: Text prompt guiding the image generation.
  • inpaint: Boolean indicating whether inpainting should occur.

Output

The output of this action typically returns a URL to the generated image. An example output is as follows:

[
  "https://assets.cognitiveactions.com/invocations/94b420b3-bc02-4a5e-a823-2029b77916f2/e8b87168-66ff-4251-bfa9-a92f6a1a4245.png"
]

This URL points to the newly generated image, which reflects the specified parameters and modifications.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet that illustrates how to call the Generate and Inpaint Image 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 = "beab4e69-6240-45d3-9d33-adb2b7ca2f4d"  # Action ID for Generate and Inpaint Image

# Construct the input payload based on the action's requirements
payload = {
    "mask": "https://example.com/mask.png",
    "seed": 42,
    "image": "https://example.com/base_image.png",
    "width": 1024,
    "height": 1024,
    "prompt": "A bohemian-style female travel blogger with sun-kissed skin and messy beach waves",
    "inpaint": False,
    "loraList": [],
    "imageCount": 1,
    "loraScales": [],
    "outputFormat": "png",
    "guidanceScale": 3.5,
    "outputQuality": 100,
    "taskScheduler": "K_EULER",
    "inferenceSteps": 28,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "controlStrength": 0.2,
    "controlNetEnabled": False
}

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 snippet, you replace the placeholder values with your actual API key and input parameters. The action ID and payload structure are essential for a successful request.

Conclusion

The Lightweight AI Model 3.4 Cognitive Actions open up exciting possibilities for image generation and modification. By leveraging the Generate and Inpaint Image action, developers can create stunning visuals tailored to their needs with ease. Consider exploring this action further and integrating it into your applications to enhance user experiences with personalized image content. Happy coding!