Generate Unique Images with the cjwbw/sd-textual-inversion-ugly-sonic Cognitive Actions

23 Apr 2025
Generate Unique Images with the cjwbw/sd-textual-inversion-ugly-sonic Cognitive Actions

In the realm of image generation, the cjwbw/sd-textual-inversion-ugly-sonic spec offers a powerful solution for developers looking to create unique visuals using Stable Diffusion fine-tuned on the quirky "Ugly Sonic" theme. This set of Cognitive Actions allows for a high level of customization, enabling you to produce tailored images by adjusting parameters like prompts, seeds, guidance scales, and more. In this article, we'll explore how to utilize these actions effectively.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform, which you will use to authenticate your requests. Typically, this involves passing the API key in the headers of your HTTP requests.
  • Basic knowledge of JSON and Python, as we will be using these for constructing requests and handling responses.

Cognitive Actions Overview

Generate Image with Stable Diffusion Fine-Tuned on Ugly Sonic

This action allows you to generate images based on a prompt that includes the "Ugly Sonic" concept. It provides the flexibility to customize various parameters, giving you creative control over the output.

Input

The action requires a JSON object with the following fields:

  • seed (optional): An integer value for random seed initialization (leave blank for a random seed).
  • prompt (required): A string that serves as the input prompt for image generation, which should include the term <ugly-sonic>.
  • guidanceScale (optional): A number between 1 and 20 that defines the scale factor used for classifier-free guidance (default is 7.5).
  • numberOfOutputs (optional): An integer indicating how many images to generate (either 1 or 4, default is 1).
  • numberOfInferenceSteps (optional): An integer specifying the number of denoising steps (ranging from 1 to 500, default is 50).

Example Input:

{
  "prompt": "a beautiful portrait of [[[<ugly-sonic>]]] by Leonardo Da Vinci, (((painting, oil on canvas)))",
  "guidanceScale": 7.5,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

Output

The output of this action is typically an array of URLs pointing to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/5b9e9403-6b81-4bf5-a4ed-e9e6854d424b/6f07c1ee-c5d9-46ec-9ec7-b08681149094.png"
]

Conceptual Usage Example (Python)

Here’s how you could structure a request to execute 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 = "f4c91a9f-65c1-473e-a3c3-fbf23418a9ff"  # Action ID for Generate Image with Stable Diffusion Fine-Tuned on Ugly Sonic

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "a beautiful portrait of [[[<ugly-sonic>]]] by Leonardo Da Vinci, (((painting, oil on canvas)))",
    "guidanceScale": 7.5,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 50
}

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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id variable holds the ID for this specific action, and the payload variable is constructed according to the input schema requirements.

Conclusion

The Cognitive Actions provided under the cjwbw/sd-textual-inversion-ugly-sonic spec allow developers to generate unique and creative images themed around "Ugly Sonic". By leveraging the parameters available, you can customize the image generation process to suit your project's needs. Whether you're looking to create art, illustrations, or other visual content, these actions provide a robust solution for your image generation tasks. Happy coding!