Generate Stunning Images with the Cognitive Actions from jonathan-hubjam/new-spex

23 Apr 2025
Generate Stunning Images with the Cognitive Actions from jonathan-hubjam/new-spex

In today's digital landscape, generating high-quality images programmatically can significantly enhance applications across various domains. The Cognitive Actions from the jonathan-hubjam/new-spex specification allow developers to leverage powerful image generation capabilities. By utilizing these pre-built actions, you can create unique images from textual prompts, customize parameters, and explore advanced features like image-to-image transformations.

Prerequisites

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

  • An API key for the Cognitive Actions platform. This key will authenticate your requests.
  • Familiarity with making HTTP requests in your preferred programming language (Python, JavaScript, etc.).

For authentication, you'll typically pass your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image from Prompt

This action generates images based on a provided text prompt using either the 'dev' or 'schnell' model. You can customize various parameters such as image size, quality, and output format. The 'dev' model excels in producing detailed images, while the 'schnell' model is optimized for speed. This action also supports image-to-image transformations and inpainting.

Input

The input for the Generate Image from Prompt action requires a JSON object that can include the following fields:

  • prompt (required): A string guiding the image generation.
  • model: Specifies which model to use; options are 'dev' (default) or 'schnell'.
  • width and height: Define the dimensions of the generated image.
  • aspectRatio: Determines the aspect ratio of the image.
  • guidanceScale: Affects the realism of the generated image.
  • outputQuality: The quality of the output image on a scale from 0 to 100.
  • numberOfOutputs: Specifies how many images to generate.

Here's a sample input JSON payload:

{
  "model": "dev",
  "prompt": "BLKSPEX bald man with black spectacles looking at the camera with a \"you won't believe this\" expression",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "guidanceScale": 3.77,
  "outputQuality": 80,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "imageOutputFormat": "webp",
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28
}

Output

Upon execution, this action typically returns a list of URLs pointing to the generated images. For example, a successful response might look like this:

[
  "https://assets.cognitiveactions.com/invocations/ef7603df-03a4-4754-9b2f-20bb7ae1ff7e/2ada0a68-b154-49dd-b7f8-319438b2fc5f.webp"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how you might call the Generate Image from Prompt 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 = "5ff21f27-52f8-4c26-acf0-0463392a84c6"  # Action ID for Generate Image from Prompt

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "BLKSPEX bald man with black spectacles looking at the camera with a \"you won't believe this\" expression",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "guidanceScale": 3.77,
    "outputQuality": 80,
    "enableFastMode": False,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "numberOfOutputs": 1,
    "imageOutputFormat": "webp",
    "additionalLoraScale": 1,
    "inferenceStepsCount": 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 example, replace the placeholder for the API key and endpoint with your actual credentials. The JSON payload is structured to match the requirements of the action, ensuring smooth execution.

Conclusion

The Generate Image from Prompt action from the jonathan-hubjam/new-spex specification empowers developers to create visually compelling images directly from text. By customizing parameters, you can refine the output to meet specific aesthetic needs, making it a versatile tool for various applications.

As you integrate these Cognitive Actions, consider exploring additional features like image-to-image transformations and inpainting for even more creative possibilities. Happy coding!