Create Stunning Images with swk23/youngquigon's Cognitive Actions

21 Apr 2025
Create Stunning Images with swk23/youngquigon's Cognitive Actions

The swk23/youngquigon spec offers a robust set of Cognitive Actions designed to facilitate advanced image generation. With the ability to customize parameters such as image masks, prompts, and various model choices, developers can harness these pre-built actions to create high-quality images tailored to specific needs. This article will guide you through the key capabilities of the available actions and provide practical examples of how to integrate them into your applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON and HTTP requests.

Authentication typically involves passing your API key in the request headers. This ensures secure access to the Cognitive Actions you will be using.

Cognitive Actions Overview

Generate Image with Mask and Prompt

Description: This action allows developers to create an image based on a specific image mask and a text prompt. It supports a variety of adjustable parameters like width, height, output format, and model selection for optimal image quality and speed.

Category: Image Generation

Input

The input schema for this action requires a minimum of one field, which is the prompt. Here’s the structure you need to follow:

{
  "image": "https://example.com/input_image.png",
  "goFast": false,
  "prompt": "TOK he stands tall with a green lightsaber",
  "loraScale": 1,
  "numOutputs": 1,
  "modelChoice": "dev",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "21:9",
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 28
}
  • Required Field:
    • prompt: Text guiding the image generation (e.g., "TOK he stands tall with a green lightsaber").
  • Optional Fields:
    • image: URI of the input image for transformation.
    • width and height: Dimensions of the output image.
    • goFast: Enable or disable faster predictions.
    • numOutputs: Number of images to generate (1-4).
    • Additional parameters for LoRA weights, model choice, guidance scale, and output quality.

Output

The output of the action typically returns a list of image URLs corresponding to the generated images. Here’s an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/a5aa508f-e4b1-4118-a327-f419c959688a/e5606e76-2a7b-4273-9d14-45f236891656.jpg"
]

This output can include multiple links if multiple images were requested.

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Mask and Prompt 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 = "93de86ae-05d7-40c4-b5ce-062470e0c77f" # Action ID for Generate Image with Mask and Prompt

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MIIwN0ZYcfVXg5kcBmjzZh3kOAMXOkPLjeDU8OTset184kpX/Screenshot%20%28805%29.png",
    "goFast": false,
    "prompt": "TOK he stands tall with a green lightsaber",
    "loraScale": 1,
    "numOutputs": 1,
    "modelChoice": "dev",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "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() # 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:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The payload variable contains the input JSON structured according to the action's requirements.
  • The response is printed out, showing either the generated image URLs or an error message.

Conclusion

The swk23/youngquigon Cognitive Actions provide powerful tools for developers looking to integrate advanced image generation capabilities into their applications. By utilizing the Generate Image with Mask and Prompt action, you can create highly customized images efficiently. Explore these actions further to enhance your applications, and consider experimenting with different input parameters to achieve the best results!