Generate Stunning Images with Cognitive Actions from hartmamt/randall

24 Apr 2025
Generate Stunning Images with Cognitive Actions from hartmamt/randall

In today’s digital landscape, the ability to generate detailed images through AI has become a game-changer for developers. The hartmamt/randall API brings forth a powerful set of Cognitive Actions that allow you to create images using advanced inpainting techniques. Whether you're looking to enhance existing images or generate new ones from textual descriptions, these actions are designed to make the process seamless and efficient.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic familiarity with making HTTP requests and handling JSON responses.

Authentication is typically handled by including your API key in the request headers, ensuring secure access to the action endpoints.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows developers to create detailed images using customizable parameters. This action supports fast predictions via an fp8 quantization setting and utilizes LoRA weights for enhanced generation, offering both speed and performance with model options like 'dev' or 'schnell'.

Input

The input for this action is structured as follows:

  • prompt (required): A textual description that serves as the basis for the image generation.
  • mask (optional): A URI for the image mask, relevant in inpainting mode.
  • seed (optional): An integer to ensure reproducible outcomes.
  • image (optional): A URI for an input image in image-to-image or inpainting mode.
  • model (optional): Select either 'dev' for quality or 'schnell' for speed, defaulting to 'dev'.
  • width (optional): Specifies the width of the output image (only for custom aspect ratio).
  • height (optional): Specifies the height of the output image (only for custom aspect ratio).
  • megapixels (optional): Choose between 0.25 or 1 megapixel.
  • imageFormat (optional): Output formats available are webp, jpg, or png.
  • imageQuality (optional): Quality level of the output image.
  • guidanceScale (optional): Affects the realism of the image, with recommended values between 2 to 3.5.
  • additional properties: Include parameters for LoRA weights, fast mode, number of outputs, and more.

Example Input:

{
  "model": "dev",
  "prompt": "A black and white photo of an older man. He is sitting outside a building and looking to the side. The man has a beard and mustache. The photo is in the style of RNDLL",
  "imageFormat": "png",
  "imageQuality": 90,
  "guidanceScale": 3.5,
  "loraIntensity": 1,
  "numberOfOutputs": 4,
  "promptIntensity": 0.8,
  "imageAspectRatio": "5:4",
  "numberOfInferenceSteps": 28,
  "additionalLoraIntensity": 1
}

Output

Upon successful execution, the action returns an array of image URLs that point to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/8c2aa4d6-b820-462a-8a3a-81adf3add9c0/accff703-0680-4d54-accc-d4952c855a12.png",
  "https://assets.cognitiveactions.com/invocations/8c2aa4d6-b820-462a-8a3a-81adf3add9c0/4d836890-afcc-4540-8a92-a3d54d561782.png",
  "https://assets.cognitiveactions.com/invocations/8c2aa4d6-b820-462a-8a3a-81adf3add9c0/90511c7d-b4f2-48ec-adb3-1de7b8368c48.png",
  "https://assets.cognitiveactions.com/invocations/8c2aa4d6-b820-462a-8a3a-81adf3add9c0/2f3a13f5-f5f5-4b1b-b467-f1fde3e16aff.png"
]

Conceptual Usage Example (Python)

Here’s how you might structure a request to call this action using Python:

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 = "872abeb8-9547-4496-87e9-256b072bbf85" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "A black and white photo of an older man. He is sitting outside a building and looking to the side. The man has a beard and mustache. The photo is in the style of RNDLL",
    "imageFormat": "png",
    "imageQuality": 90,
    "guidanceScale": 3.5,
    "loraIntensity": 1,
    "numberOfOutputs": 4,
    "promptIntensity": 0.8,
    "imageAspectRatio": "5:4",
    "numberOfInferenceSteps": 28,
    "additionalLoraIntensity": 1
}

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 will need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured to meet the requirements of the Generate Image with Inpainting action.

Conclusion

The hartmamt/randall Cognitive Actions empower developers to create stunning images with ease, leveraging advanced AI techniques. By integrating these actions into your applications, you can unlock a new realm of possibilities in image generation, from artistic creations to practical applications. Start experimenting with the Generate Image with Inpainting action and explore the creative potential it offers!