Transform Images Effortlessly with the cliffradical/terence1 Cognitive Actions

22 Apr 2025
Transform Images Effortlessly with the cliffradical/terence1 Cognitive Actions

In today's digital landscape, image generation and manipulation have become essential capabilities for many applications. The cliffradical/terence1 API offers a powerful Cognitive Action that enables developers to generate images using advanced inpainting and image-to-image transformation techniques. This action is optimized for various parameters, allowing for high-quality outputs tailored to specific needs. Let’s dive into how you can leverage this capability in your applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which allows you to authenticate your requests.
  • Basic knowledge of JSON structure and HTTP requests.

To authenticate your requests, you will typically pass your API key in the headers of your HTTP requests to access the Cognitive Actions functionalities.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images through image-to-image transformation or inpainting. This action is particularly useful for generating custom images based on textual prompts or modifying existing images.

Input

The input for this action requires a JSON object, with the following essential fields:

  • prompt (required): A descriptive text for generating an image. For example, "A photo portrait of Terence wearing a suit and red tie and wearing spectacles".

Optional fields include:

  • mask: Image mask for inpainting mode.
  • seed: Sets a random seed for reproducible results.
  • image: Input image for inpainting mode.
  • model: Specifies which model to use (default is "dev").
  • width: Width of the generated image (only applicable if aspect_ratio is set to 'custom').
  • height: Height of the generated image (only applicable if aspect_ratio is set to 'custom').
  • goFast: Enables faster predictions.
  • imageAspectRatio: Defines the aspect ratio of the output image.
  • imageOutputFormat: Specifies the format of the output image (default is "webp").
  • numberOfOutputs: Number of images to generate (default is 1).

Here’s an example input JSON payload:

{
  "model": "dev",
  "width": 1440,
  "goFast": false,
  "height": 1440,
  "prompt": "A photo portrait of Terence wearing a suit and red tie and wearing spectacles",
  "loraScale": 1,
  "guidanceScale": 3,
  "promptStrength": 0.8,
  "numberOfOutputs": 2,
  "imageAspectRatio": "3:4",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28,
  "imageSizeInMegapixels": "1"
}

Output

The action returns an array of URLs pointing to the generated images. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/1fb47414-cf9b-4338-92ec-4985c205a3e6/4d951f83-6843-4e45-a793-198f2e3c1839.webp",
  "https://assets.cognitiveactions.com/invocations/1fb47414-cf9b-4338-92ec-4985c205a3e6/df1e4971-93cf-4b34-b4b3-193e161de8e2.webp"
]

Conceptual Usage Example (Python)

Here’s how you might structure a call to the Cognitive Actions endpoint 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 = "dfb96fc0-38d2-4063-a598-f7b4430fd673"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "width": 1440,
    "goFast": False,
    "height": 1440,
    "prompt": "A photo portrait of Terence wearing a suit and red tie and wearing spectacles",
    "loraScale": 1,
    "guidanceScale": 3,
    "promptStrength": 0.8,
    "numberOfOutputs": 2,
    "imageAspectRatio": "3:4",
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "additionalLoraScale": 1,
    "inferenceStepsCount": 28,
    "imageSizeInMegapixels": "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, replace the COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your actual API key and endpoint. The payload variable is structured according to the action's requirements, and the request is sent to the hypothetical endpoint.

Conclusion

The Generate Image with Inpainting action from the cliffradical/terence1 API opens up exciting possibilities for developers looking to integrate advanced image generation capabilities into their applications. With its flexibility in parameters and output formats, you can create custom images tailored to your needs.

Explore different prompts and configurations to find the best settings for your project, and start transforming your application with powerful image generation features today!