Generate Stunning Images with the LibreIntense Cognitive Actions

24 Apr 2025
Generate Stunning Images with the LibreIntense Cognitive Actions

In today's digital landscape, generating high-quality images programmatically can elevate your applications to new heights. The LibreIntense Cognitive Actions provide developers with powerful tools for image generation, leveraging advanced techniques like image inpainting and customizable parameters. By integrating these pre-built actions, you can create visually appealing content tailored to your needs quickly and efficiently.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • A basic understanding of JSON for constructing input payloads.
  • Familiarity with making HTTP requests in your development environment.

Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Image Inpainting

This action generates images using either image-to-image or inpainting modes, optimized for both quality and speed. It allows for custom aspect ratios and supports various output formats. The operation provides control over guidance scales, inference steps, and other parameters to produce realistic and detailed images.

Input

The input schema for this action requires the following fields:

  • prompt (required): A description of the image you want to generate.
  • mask (optional): An image mask for inpainting mode. If provided, width, height, and aspect_ratio inputs are ignored.
  • seed (optional): An integer to specify a random seed for reproducible results.
  • image (optional): An input image for image-to-image or inpainting mode. If included, dimensions will be ignored.
  • width (optional): Image width in pixels (256-1440) when aspect_ratio is set to 'custom'.
  • height (optional): Image height in pixels (256-1440) when aspect_ratio is set to 'custom'.
  • aspectRatio (optional): Desired aspect ratio for the generated image (default: "1:1").
  • outputFormat (optional): The format for the output image (default: "webp").
  • guidanceScale (optional): A scale guiding the realism of generated images (default: 3).
  • numOutputs (optional): Number of images to generate (default: 1).
  • Additional parameters such as goFast, inferenceModel, numInferenceSteps, and others can further customize the output.

Example Input:

{
  "prompt": "Position the LIBREINTENSE bottle against an urban cityscape at night with city lights in the background, evoking a modern, urban lifestyle.",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 80,
  "extraLoraScale": 0.8,
  "inferenceModel": "dev",
  "numInferenceSteps": 28
}

Output

Upon successful execution, this action typically returns a URL pointing to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/6b88d7d3-ac9f-4565-9528-c9ca80b2f72f/c86ee178-7da5-40fa-877f-2fae0cb94fca.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Image Inpainting action using a hypothetical Cognitive Actions execution 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 = "96679f39-3d69-4ead-bb36-987944203c63"  # Action ID for Generate Image with Image Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Position the LIBREINTENSE bottle against an urban cityscape at night with city lights in the background, evoking a modern, urban lifestyle.",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 80,
    "extraLoraScale": 0.8,
    "inferenceModel": "dev",
    "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, you'll see how to structure the input JSON payload according to the action's requirements. The endpoint URL and request structure are illustrative, so be sure to adapt them based on your actual implementation.

Conclusion

The LibreIntense Cognitive Actions provide a powerful way to generate stunning images with ease. By leveraging the capabilities of image inpainting and customizable parameters, you can create personalized content that resonates with your audience. Whether you're building a marketing platform, a creative tool, or enhancing existing applications, these actions will enable you to enhance the visual quality of your projects. Start exploring the possibilities today!