Generate Stunning Images with the adarvishian/paradin Cognitive Actions

22 Apr 2025
Generate Stunning Images with the adarvishian/paradin Cognitive Actions

In the realm of image generation, the adarvishian/paradin API opens doors to creative possibilities with its powerful set of Cognitive Actions. These pre-built actions enable developers to generate detailed and customizable images through various techniques such as image inpainting. By leveraging these capabilities, you can enhance your applications with visually stunning content that meets specific user requirements.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform.
  • A basic understanding of HTTP requests and JSON formatting, as you'll be interacting with the API using structured payloads.
  • Familiarity with Python for executing the conceptual code examples provided.

Authentication typically requires including the API key in the request headers, enabling secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action is designed to create detailed images based on user-defined prompts and customizable parameters. This action supports fast generation with optimized models to provide high-quality results efficiently.

Input:

The input schema requires a variety of fields, with the prompt being mandatory. Here’s a breakdown of the input fields:

  • prompt (required): A string guiding the generation (e.g., "In the style of TOK, an emblem of a fierce head of a lion with the great sun").
  • mask (optional): URI of an image mask for inpainting. If provided, aspect_ratio, width, and height are ignored.
  • seed (optional): Integer seed for reproducibility.
  • image (optional): URI of an input image for inpainting.
  • width and height (optional): Integers specifying the dimensions of the image (applicable if aspect_ratio is 'custom').
  • goFast (optional): Boolean to enable faster predictions using optimized models.
  • aspectRatio (optional): Specifies the aspect ratio of the generated image (default is "1:1").
  • imageFormat (optional): Desired output format (e.g., "jpg").
  • outputCount (optional): Number of images to generate (between 1 and 4).
  • guidanceScale, outputQuality, promptStrength, etc. (optional): Various parameters to fine-tune the generation.
Example Input:
{
  "prompt": "In the style of TOK, an emblem of a fierce head of a lion with the great sun",
  "loraScale": 1,
  "modelType": "dev",
  "aspectRatio": "1:1",
  "imageFormat": "jpg",
  "outputCount": 4,
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "inferenceStepCount": 28
}

Output:

The action returns an array of image URLs based on the input parameters. Here's an example of the output you might receive:

Example Output:
[
  "https://assets.cognitiveactions.com/invocations/ae1c4e9f-c32c-4212-9475-41afae71f03b/4ebe41a6-918f-4342-8530-57e0477acccb.jpg",
  "https://assets.cognitiveactions.com/invocations/ae1c4e9f-c32c-4212-9475-41afae71f03b/cb4eafbf-881e-4a08-884c-1577ef985088.jpg",
  "https://assets.cognitiveactions.com/invocations/ae1c4e9f-c32c-4212-9475-41afae71f03b/e0f17c59-0436-47bb-a515-9d3c5fdd233e.jpg",
  "https://assets.cognitiveactions.com/invocations/ae1c4e9f-c32c-4212-9475-41afae71f03b/e897a980-e008-4db2-8a80-882135566701.jpg"
]

Conceptual Usage Example (Python):

Here’s how you might utilize the Generate Image with Inpainting action in 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 = "79e9f00b-a715-426b-b304-529b7d876073"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "In the style of TOK, an emblem of a fierce head of a lion with the great sun",
    "loraScale": 1,
    "modelType": "dev",
    "aspectRatio": "1:1",
    "imageFormat": "jpg",
    "outputCount": 4,
    "guidanceScale": 3.5,
    "outputQuality": 100,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "inferenceStepCount": 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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and ensure the endpoint URL is correct. The action ID and input payload are structured according to the requirements specified in the Cognitive Action documentation.

Conclusion

The adarvishian/paradin Cognitive Actions empower developers to create stunning images through simple API calls. With customizable parameters and optimized models, integrating image generation into your applications can enhance user engagement and creativity. Explore these capabilities in your projects and unlock new possibilities for content creation!