Create Stunning Character Images with mhohenwald/psgreenboy Cognitive Actions

21 Apr 2025
Create Stunning Character Images with mhohenwald/psgreenboy Cognitive Actions

The mhohenwald/psgreenboy specification offers innovative Cognitive Actions that empower developers to generate detailed custom images of characters. By leveraging advanced image generation techniques, these actions provide an intuitive way to create images tailored to specific prompts, poses, attire, and environments. This article will guide you through the capabilities of these actions and how to integrate them into your applications.

Prerequisites

To start using the Cognitive Actions under the mhohenwald/psgreenboy spec, you will need:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of crafting JSON payloads for API calls.

Authentication typically involves including your API key in the request headers, ensuring secure access to the service.

Cognitive Actions Overview

Generate Character Image

Purpose:
The "Generate Character Image" action allows you to create a detailed image of a character using advanced image generation techniques. You can customize aspects such as pose, attire, and environment, making it a versatile tool for developers focusing on visual content creation.

Category: image-generation

Input

The input for this action is a JSON object that includes several properties. Below is an overview of the required and optional fields:

  • Required:
    • prompt: A text prompt guiding the image generation (e.g., "a portrait from PSGREENBOY sitting on his Bed, looking at his smartphone").
  • Optional:
    • mask: URI for an image mask.
    • seed: Integer for reproducible image generation.
    • image: URI for an input image for transformations.
    • model: Select between "dev" or "schnell" for inference.
    • width and height: Specify dimensions when aspect ratio is custom.
    • goFast: Boolean to enable faster predictions.
    • imageFormat: Choose between "webp", "jpg", "png".
    • outputCount: Number of images to generate (1 to 4).
    • imageQuality: Quality of output images (0 to 100).
    • loraStrength: Main LoRA application strength.
    • guidanceScale: Scale for the diffusion process (0 to 10).
    • additionalLora: Load additional LoRA weights.
    • promptStrength: Strength of the prompt in img2img operations.
    • imageMegapixels: Approximate megapixel count.
    • imageAspectRatio: Aspect ratio for the generated image.
    • inferenceStepCount: Denoising steps for finer details.
    • safetyCheckerDisabled: Control over the safety checker for generated images.
    • additionalLoraStrength: Strength of secondary LoRA application.

Example Input:

{
  "model": "dev",
  "goFast": false,
  "prompt": "a portrait from PSGREENBOY sitting on his Bed, looking at his smartphone",
  "imageFormat": "png",
  "outputCount": 1,
  "imageQuality": 80,
  "loraStrength": 1,
  "guidanceScale": 3,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "16:9",
  "inferenceStepCount": 28,
  "additionalLoraStrength": 1
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/b3a2c24b-d91c-4c18-9211-0336827e6dae/a8358b33-187e-4b59-b7b7-291bcc44ab34.png"
]

Conceptual Usage Example (Python)

Here’s how you might implement the "Generate Character Image" action in a Python application:

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 = "528f8ac1-6a47-4355-8251-ccc755022b8e" # Action ID for Generate Character Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": False,
    "prompt": "a portrait from PSGREENBOY sitting on his Bed, looking at his smartphone",
    "imageFormat": "png",
    "outputCount": 1,
    "imageQuality": 80,
    "loraStrength": 1,
    "guidanceScale": 3,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "16:9",
    "inferenceStepCount": 28,
    "additionalLoraStrength": 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, you will see how to structure the input JSON payload properly and call the hypothetical Cognitive Actions execution endpoint. The action ID and input payload are highlighted to guide you in implementing it correctly.

Conclusion

The Cognitive Actions provided by the mhohenwald/psgreenboy spec open up exciting possibilities for character image generation, enhancing your applications with visually stunning content. By following this guide, you can easily integrate these actions into your projects and customize your character images to fit various scenarios. Consider experimenting with different prompts and parameters to fully explore the capabilities of this powerful tool!