Enhance Your Images with Cognitive Actions: A Guide to swk23/quigon-live-2

21 Apr 2025
Enhance Your Images with Cognitive Actions: A Guide to swk23/quigon-live-2

The swk23/quigon-live-2 specification offers developers a powerful way to enhance images through Cognitive Actions. This integration allows for sophisticated image manipulation, particularly through the action of image inpainting. By utilizing pre-built Cognitive Actions, developers can save time and resources while delivering exceptional image processing capabilities in their applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic familiarity with making API calls and handling JSON data.
  • Import the requests library in Python for making HTTP requests.

Authentication typically involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image Inpainting

The Generate Image Inpainting action allows users to input an image and apply transformations such as inpainting using a specific mask. This action optimizes for either speed or precision during image generation, offering flexibility in image dimensions, output quality, and aspect ratios.

Input

The input schema requires the following fields:

  • prompt: (required) A detailed description of the image you want to create.
  • mask: (optional) A URI string for an image mask to be used in inpainting mode.
  • seed: (optional) An integer for setting a random seed to ensure reproducibility.
  • image: (optional) A URI string for the input image, which will be inpainting.
  • width: (optional) An integer specifying the width of the output image (if aspect_ratio is custom).
  • height: (optional) An integer specifying the height of the output image (if aspect_ratio is custom).
  • fastMode: (optional) A boolean to enable faster predictions (default: false).
  • aspectRatio: (optional) A string specifying the aspect ratio of the generated image (default: "1:1").
  • guidanceScale: (optional) A number to control the guidance scale in the diffusion process (default: 3).
  • inferenceModel: (optional) A string to choose the inference model (default: "dev").
  • imageOutputFormat: (optional) The format of the output image (default: "webp").
  • numberOfOutputs: (optional) An integer for the number of outputs to generate (default: 1).

Here’s an example input payload:

{
  "prompt": "Qui-Gon Jinn looking slightly to the left, his expression calm yet intense, filled with quiet wisdom and conviction. His long brown hair frames his weathered face, and his piercing eyes reflect both serenity and defiance. Soft, natural light illuminates his features, highlighting the lines of experience and compassion. His Jedi robes drape over his shoulders and chest, textured and worn, symbolizing years of service and spiritual depth. Behind him, the blurred interior of the Jedi Temple adds a sacred, timeless atmosphere. A sense of quiet strength radiates from him—this is a Jedi who listens to the Force above all else.",
  "fastMode": false,
  "aspectRatio": "21:9",
  "guidanceScale": 3,
  "mainLoraScale": 1,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1
}

Output

The output will typically return a URL string of the generated image. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/2b35995f-8ff4-4e48-a0c7-2e3b9ec208a8/13af3280-7de1-498a-8158-600242e0aad6.jpg"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Generate Image Inpainting 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 = "00fa7fa1-5b16-4af6-9b3f-bb1b5bf26e73"  # Action ID for Generate Image Inpainting

# Construct the input payload based on the action's requirements
payload = {
  "prompt": "Qui-Gon Jinn looking slightly to the left, his expression calm yet intense, filled with quiet wisdom and conviction. His long brown hair frames his weathered face, and his piercing eyes reflect both serenity and defiance. Soft, natural light illuminates his features, highlighting the lines of experience and compassion. His Jedi robes drape over his shoulders and chest, textured and worn, symbolizing years of service and spiritual depth. Behind him, the blurred interior of the Jedi Temple adds a sacred, timeless atmosphere. A sense of quiet strength radiates from him—this is a Jedi who listens to the Force above all else.",
  "fastMode": false,
  "aspectRatio": "21:9",
  "guidanceScale": 3,
  "mainLoraScale": 1,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 80,
  "additionalLoraScale": 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 with your actual API key. The action_id specifies which action to execute, while the payload contains the required input structured as JSON.

Conclusion

By leveraging the Generate Image Inpainting action from the swk23/quigon-live-2 specification, developers can enhance their applications with advanced image processing capabilities. Whether you are generating new images or applying transformations to existing ones, these Cognitive Actions offer robust features that can elevate the quality of your visual content. Consider experimenting with various input parameters to see how they affect the output and enrich your user experience!