Generate Stunning Images with swk23/livepalpatine Cognitive Actions

22 Apr 2025
Generate Stunning Images with swk23/livepalpatine Cognitive Actions

In the ever-evolving landscape of artificial intelligence, the ability to generate images using powerful models has become a game-changer for developers. The swk23/livepalpatine specification offers a remarkable set of Cognitive Actions designed for image generation, allowing you to create visually stunning outputs using custom models like 'dev' and 'schnell'. With options for image inpainting, prompt-based creation, and extensive customization settings, these actions can streamline your creative processes and enhance user experiences.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which you will use to authenticate your requests. Generally, this is passed in the request headers as a Bearer token.
  • Familiarity with JSON as the data format for structuring your input and handling outputs.

Cognitive Actions Overview

Generate Image Using Custom Models

Description: This action allows you to generate images using custom models 'dev' and 'schnell'. The 'dev' model is optimized for detailed results with 28 inference steps, while the 'schnell' model offers quicker execution with only 4 steps. It supports various aspect ratios, quality settings, and additional LoRA for versatile output customization.

  • Category: Image Generation

Input:

The input for this action requires the following fields based on the provided schema:

  • Required:
    • prompt: A detailed description to guide the image generation.
  • Optional:
    • mask: URI for an image mask used in inpainting mode.
    • seed: Integer for consistent outputs.
    • image: URI for input image in img2img or inpainting mode.
    • width: Width of the image in pixels (for custom aspect ratio).
    • height: Height of the image in pixels (for custom aspect ratio).
    • goFast: Boolean to optimize for speed.
    • numOutputs: Number of images to generate (1 to 4).
    • imageAspectRatio: Defines the aspect ratio for the image.
    • imageOutputFormat: Specifies output file format (webp, jpg, png).
    • numInferenceSteps: Number of denoising steps for image detail.
    • guidanceScale: Adjusts influence of the prompt.
    • Additional fields for LoRA configurations and quality settings.

Here's an example input payload:

{
  "goFast": false,
  "prompt": "A **close-up shot** of Emperor Palpatine, his **aged, scarred face** illuminated by the eerie glow of Senate chamber lights. His **piercing yellow eyes** radiate sinister intelligence, sunken into the wrinkled depths of his pale, almost translucent skin. His **thin lips curl into a cruel, knowing smirk**, the shadow of his deep hood casting darkness over his forehead. Faint flickers of Sith lightning crackle at his fingertips, a subtle reminder of the power he wields. The background is blurred, emphasizing the pure malice and control in his expression—a man who has orchestrated the fall of the Jedi and the rise of an Empire.",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "21:9",
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 28
}

Output:

The action typically returns an array of image URLs. Here’s an example of a successful output:

[
  "https://assets.cognitiveactions.com/invocations/70cfebae-1b0c-408d-bcea-3a86fd23a564/04f65162-e5bf-4129-8557-d89ec4b281d9.jpg"
]

Conceptual Usage Example (Python):

Here's how you might call this 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 = "ff68c0f4-f3df-464e-b114-995e89535bad" # Action ID for Generate Image Using Custom Models

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "A **close-up shot** of Emperor Palpatine, his **aged, scarred face** illuminated by the eerie glow of Senate chamber lights. His **piercing yellow eyes** radiate sinister intelligence, sunken into the wrinkled depths of his pale, almost translucent skin. His **thin lips curl into a cruel, knowing smirk**, the shadow of his deep hood casting darkness over his forehead. Faint flickers of Sith lightning crackle at his fingertips, a subtle reminder of the power he wields. The background is blurred, emphasizing the pure malice and control in his expression—a man who has orchestrated the fall of the Jedi and the rise of an Empire.",
    "loraScale": 1,
    "numOutputs": 1,
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "21:9",
    "imageOutputFormat": "jpg",
    "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}
    )
    response.raise_for_status()

    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 API key and action ID appropriately. The input payload is structured to match the requirements of the action, ensuring you receive the desired output.

Conclusion

The swk23/livepalpatine Cognitive Actions provide a powerful and flexible solution for image generation, enabling developers to create compelling visuals tailored to specific needs. With diverse parameters for customization and the ability to generate based on rich prompts, these actions can significantly enhance your applications. As you explore these capabilities, consider experimenting with different models and settings to discover the perfect balance between speed and quality for your projects. Happy coding!