Generate AI-Enhanced Images with the jfals82/nathan Cognitive Actions

24 Apr 2025
Generate AI-Enhanced Images with the jfals82/nathan Cognitive Actions

In the world of artificial intelligence and creative applications, the ability to generate compelling images from text prompts is a game-changer. The jfals82/nathan API offers a powerful Cognitive Action called Generate AI-Enhanced Image that allows developers to create stunning AI-generated visuals based on descriptive prompts. This action not only caters to artistic needs but also provides features like inpainting and refinement, making it versatile for various use cases.

Prerequisites

Before you start integrating the jfals82/nathan Cognitive Actions into your application, make sure you have the following prerequisites:

  • An API key for the Cognitive Actions platform. This key will allow you to authenticate your requests.
  • Familiarity with JSON format, as you'll be constructing input payloads in this format.

Authentication typically involves passing your API key in the headers of your requests to the Cognitive Actions endpoint.

Cognitive Actions Overview

Generate AI-Enhanced Image

The Generate AI-Enhanced Image action creates an AI-generated image based on a text prompt, with options for customization such as output dimensions, style prompts, and inpainting features.

Category: Image Generation

Input

The input schema for this action consists of various fields, each allowing for different configurations:

  • mask (string, optional): A URI to an input mask for inpainting.
  • seed (integer, optional): A random seed integer for generation.
  • image (string, optional): A URI to the input image for image-to-image or inpainting modes.
  • width (integer, default: 1024): The width of the output image in pixels.
  • height (integer, default: 1024): The height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): Describes the desired output.
  • loraScale (number, default: 0.6): Scale factor for LoRA, valid for trained models.
  • scheduler (string, default: "K_EULER"): The scheduling algorithm during generation.
  • guidanceScale (number, default: 7.5): Scaling factor for classifier-free guidance.
  • applyWatermark (boolean, default: true): Specifies if a watermark should be applied.
  • negativePrompt (string, optional): Suggests features to exclude in the output.
  • promptStrength (number, default: 0.8): Influence strength of the prompt in image transformation.
  • numberOfOutputs (integer, default: 1): Number of output images (1 to 4).
  • refinementSteps (integer, optional): Count of refinement steps for 'base_image_refiner'.
  • refinementMethod (string, default: "no_refiner"): Method used for refining the output image.
  • weightParameters (string, optional): LoRA model weights to use.
  • highNoiseFraction (number, default: 0.8): Fraction of noise for 'expert_ensemble_refiner'.
  • disableSafetyChecker (boolean, default: false): Disables the safety checker for generated images.
  • numberOfInferenceSteps (integer, default: 50): Number of denoising steps during generation.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A picture of Nathan, headshot, muscle, birthday hat, desert",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.6,
  "numberOfOutputs": 1,
  "refinementMethod": "no_refiner",
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 105
}

Output

The output of the action is a URL pointing to the generated image. Here’s an example of what you might receive:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/e55de8f2-7297-4764-bc15-76a75f55b3db/6c064e41-f1f1-450c-a042-259d6d15f769.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet illustrating how to call the Generate AI-Enhanced Image action:

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 = "7eb8db35-73f1-4d7f-a8f3-36b386414d3d" # Action ID for Generate AI-Enhanced Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A picture of Nathan, headshot, muscle, birthday hat, desert",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "negativePrompt": "",
    "promptStrength": 0.6,
    "numberOfOutputs": 1,
    "refinementMethod": "no_refiner",
    "highNoiseFraction": 0.8,
    "numberOfInferenceSteps": 105
}

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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id should be set to the ID of the action being executed. The payload is structured according to the action's input schema, and the output will provide a URL to the generated image.

Conclusion

The Generate AI-Enhanced Image action from the jfals82/nathan Cognitive Actions suite offers developers a robust tool for creating unique images tailored to their specifications. Whether for artistic projects, marketing materials, or creative explorations, this API empowers you to bring your imaginative concepts to life. Start integrating this powerful action into your applications and explore the endless possibilities of AI-generated imagery!