Enhance Your Images Like a Pro with the andyx1976/trkgys Cognitive Actions

24 Apr 2025
Enhance Your Images Like a Pro with the andyx1976/trkgys Cognitive Actions

In today's digital age, the ability to generate and enhance images is essential for developers looking to create visually appealing applications. The andyx1976/trkgys Cognitive Actions offer powerful tools to generate images using advanced techniques such as inpainting and LoRA applications. These pre-built actions allow developers to customize image attributes like resolution, quality, and aspect ratio, making it easier than ever to achieve stunning results.

Prerequisites

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

  • API Key: You’ll need an API key for the Cognitive Actions platform to authenticate your requests.
  • Basic Setup: Familiarity with making HTTP requests and handling JSON data in your programming environment.

To authenticate your requests, you will typically pass the API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Enhanced Image

The Generate Enhanced Image action enables developers to create and improve images through advanced inpainting techniques. This action allows for customizable parameters, including resolution, image quality, and aspect ratio. It also supports fast generation mode and image masking to optimize both speed and detail.

Input

The input schema for this action requires the following fields:

  • prompt (required): A text prompt guiding the image generation (e.g., "two young trk men, schoolboys.").
  • image (optional): URI of the input image for image-to-image or inpainting mode.
  • mask (optional): URI of the image mask for inpainting.
  • width (optional): Width of the generated image, applicable when aspect ratio is set to custom.
  • height (optional): Height of the generated image, applicable when aspect ratio is set to custom.
  • aspectRatio (optional): Specifies the aspect ratio of the generated image (e.g., "3:4").
  • goFast (optional): Toggle for faster predictions.
  • numOutputs (optional): Number of images to generate (1 to 4).
  • outputFormat (optional): Specifies the file format for output images (e.g., "jpg").
  • guidanceScale (optional): Scale of guidance in the diffusion process.
  • outputQuality (optional): Image quality when saved, ranging from 0 to 100.

Example Input:

{
  "image": "https://replicate.delivery/xezq/jzDoAFmKdZpbP9iZAVyjIGjYHRSUfOOxTP6LMPDLTtgzV9OKA/out-1.jpg",
  "goFast": false,
  "prompt": "two young trk men, schoolboys.",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "3:4",
  "outputFormat": "jpg",
  "guidanceScale": 3.4,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.88,
  "imageMegapixels": "1",
  "numInferenceSteps": 28
}

Output

The action typically returns a list of URIs for the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/e0fd0b56-dd8d-45f3-82ec-996ea6bf6a60/21f09123-2195-4d45-a426-a838fd590bf4.jpg"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Enhanced Image 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 = "c41553b0-3ad7-428c-82b9-79387585ea07"  # Action ID for Generate Enhanced Image

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/xezq/jzDoAFmKdZpbP9iZAVyjIGjYHRSUfOOxTP6LMPDLTtgzV9OKA/out-1.jpg",
    "goFast": False,
    "prompt": "two young trk men, schoolboys.",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "3:4",
    "outputFormat": "jpg",
    "guidanceScale": 3.4,
    "outputQuality": 100,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.88,
    "imageMegapixels": "1",
    "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, notice how the action ID and input payload are structured. This conceptual example illustrates the integration process with a generic Cognitive Actions endpoint.

Conclusion

The andyx1976/trkgys Cognitive Actions provide a robust framework for generating and enhancing images with advanced capabilities. With customizable settings and fast generation options, developers can easily integrate these actions into their applications, offering users stunning visual content. Consider experimenting with different parameters to see how they affect the output, and explore additional use cases that leverage image generation and enhancement!