Generate Stunning Images with the wglint/2_sdv2-1 Cognitive Actions

23 Apr 2025
Generate Stunning Images with the wglint/2_sdv2-1 Cognitive Actions

In today's digital landscape, the ability to generate high-quality images programmatically is transforming creative workflows. The wglint/2_sdv2-1 specification provides developers with powerful Cognitive Actions for image generation using the Stable Diffusion 2.1 model. These pre-built actions streamline the process, allowing you to focus on creativity rather than complex implementations. With options to filter NSFW content and store results in Supabase, you can customize the output to meet your project needs.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON and making HTTP requests.
  • A Supabase project set up if you want to store generated images.

Authentication typically involves passing the API key in the request headers, allowing you access to the Cognitive Actions endpoint.

Cognitive Actions Overview

Generate Image with Stable Diffusion 2.1

The Generate Image with Stable Diffusion 2.1 action allows you to create images based on a text prompt while offering various customization options such as dimensions, number of images, and a seed for reproducibility.

Input

The input schema for this action includes several fields:

  • seed (integer): Sets the seed for the random generator for reproducibility. Default is 1334.
  • width (integer): Specifies the width of the generated image in pixels (maximum is 1024). Default is 512.
  • height (integer): Specifies the height of the generated image in pixels (maximum is 1024). Default is 512.
  • prompt (string): Text prompt to guide the image generation. Default is "black cat".
  • supabase (boolean): Determines whether the image should be uploaded to Supabase storage. Default is false.
  • supabaseKey (string): The API key for accessing your Supabase project.
  • supabaseUrl (string): The URL for your Supabase project.
  • nsfwDetector (boolean): Enables the NSFW detector to filter inappropriate content. Default is true.
  • stableDiffusion (string): Selects the Stable Diffusion model version to use. Default is "Stable Diffusion 2.1".
  • numberOfPictures (integer): The number of images to generate (between 1 and 4). Default is 1.
  • numberOfInferenceSteps (integer): The number of steps during inference, affecting quality and speed (maximum is 50). Default is 20.

Here’s an example input payload:

{
  "seed": 1334,
  "width": 512,
  "height": 512,
  "prompt": "black cat",
  "supabase": false,
  "supabaseKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "supabaseUrl": "https://mesbgfvrhzlgbjifowqa.supabase.co",
  "nsfwDetector": true,
  "numberOfPictures": 1,
  "numberOfInferenceSteps": 20
}

Output

The action returns a list of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/015c37ba-c8a7-4fe2-a9a5-519c2668a147/2aaf9035-4e05-4293-954a-91cc7791d6bd.png"
]

This output contains a link to the generated image, which can be easily accessed or displayed in your application.

Conceptual Usage Example (Python)

Here’s how a developer might invoke this action using Python, ensuring the input payload is structured correctly:

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 = "b52dfd37-6730-44ba-8091-f37f19e152d0" # Action ID for Generate Image with Stable Diffusion 2.1

# Construct the input payload based on the action's requirements
payload = {
    "seed": 1334,
    "width": 512,
    "height": 512,
    "prompt": "black cat",
    "supabase": false,
    "supabaseKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "supabaseUrl": "https://mesbgfvrhzlgbjifowqa.supabase.co",
    "nsfwDetector": true,
    "numberOfPictures": 1,
    "numberOfInferenceSteps": 20
}

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

    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 placeholder API key and endpoint with your actual values. The action_id corresponds to the specific action you want to execute. The input JSON payload is structured based on the action's requirements, ensuring successful execution.

Conclusion

Integrating the Cognitive Actions from the wglint/2_sdv2-1 specification into your applications can significantly enhance your image generation capabilities. By leveraging the flexibility of the Stable Diffusion 2.1 model, you can create customized images while managing content safety and storage efficiently. Explore potential use cases such as creative art, marketing visuals, or any application that benefits from automated image generation. Happy coding!