Enhance Your Applications with Image Generation Using sundai-club/snow_bunny Cognitive Actions

22 Apr 2025
Enhance Your Applications with Image Generation Using sundai-club/snow_bunny Cognitive Actions

Integrating advanced image generation capabilities into your applications has never been easier with the sundai-club/snow_bunny Cognitive Actions. This API provides a powerful action called Generate Enhanced Images, which leverages the fine-tuned FLUX.1 model to create and enhance images with various features. The benefits of using these pre-built actions include reduced development time, high-quality outputs, and the ability to customize images effortlessly.

Prerequisites

Before you begin integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • Basic knowledge of JSON and Python for constructing input payloads and making API calls.

To authenticate, you typically pass the API key in the request headers as follows:

headers = {
    "Authorization": f"Bearer {YOUR_COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

Cognitive Actions Overview

Generate Enhanced Images

The Generate Enhanced Images action is designed to generate and enhance images based on a text prompt. It supports various features such as image inpainting, control over dimensions, and output quality. This action is categorized under image-generation.

Input

The input for this action is structured as follows:

  • prompt (required): A text prompt to guide the image generation.
  • mask (optional): An image mask to use during inpainting.
  • seed (optional): An integer seed for reproducible results.
  • image (optional): Input image for manipulation or inpainting.
  • width (optional): Width of the generated image (valid for custom aspect ratios).
  • height (optional): Height of the generated image (valid for custom aspect ratios).
  • outputCount (optional): Number of image outputs (default: 1, max: 4).
  • customWeights (optional): Load custom LoRA weights.
  • enableFastMode (optional): Toggle for faster predictions.
  • inferenceModel (optional): Choose the inference model (default: dev).
  • loraWeightScale (optional): Scale for the main LoRA application.
  • imageAspectRatio (optional): Aspect ratio for the generated image.
  • imageOutputFormat (optional): Format for the output image (default: webp).
  • imageOutputQuality (optional): Quality level for output images (default: 80).
  • inferenceStepCount (optional): Steps for the denoising process (default: 28).
  • additionalLoraScale (optional): Scale for additional LoRA.
  • additionalLoraWeights (optional): Load additional LoRA weights.
  • approximateMegapixels (optional): Approximate number of megapixels.
  • img2ImgPromptStrength (optional): Strength of the prompt in img2img mode.
  • safetyCheckerDisabled (optional): Option to disable safety checks.
  • diffusionGuidanceScale (optional): Adjusts guidance scale for image generation.
Example Input

Here is a practical example of the JSON payload needed to invoke this action:

{
  "prompt": "SNOWBUNNY is now wrapped in a small blanket, pretending to be asleep on the couch, still with visible cookie crumbs around its mouth. A confused-looking human mom is standing in the kitchen doorway, looking at the mess. Realistic style.",
  "outputCount": 1,
  "enableFastMode": false,
  "inferenceModel": "dev",
  "loraWeightScale": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "inferenceStepCount": 28,
  "additionalLoraScale": 1,
  "approximateMegapixels": "1",
  "img2ImgPromptStrength": 0.8,
  "diffusionGuidanceScale": 3
}

Output

Upon successful execution, the action typically returns a URL to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/91fee852-3363-4a37-a953-f6fbf274b762/3770e4f9-55ab-493b-a251-238a80c6483a.webp"
]

Conceptual Usage Example (Python)

Here's how you might call the Generate Enhanced Images 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 = "46511b66-8cbf-4e22-b3ae-afc40b15c70a" # Action ID for Generate Enhanced Images

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "SNOWBUNNY is now wrapped in a small blanket, pretending to be asleep on the couch, still with visible cookie crumbs around its mouth. A confused-looking human mom is standing in the kitchen doorway, looking at the mess. Realistic style.",
    "outputCount": 1,
    "enableFastMode": false,
    "inferenceModel": "dev",
    "loraWeightScale": 1,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "inferenceStepCount": 28,
    "additionalLoraScale": 1,
    "approximateMegapixels": "1",
    "img2ImgPromptStrength": 0.8,
    "diffusionGuidanceScale": 3
}

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 Python code snippet, replace the placeholder for the API key with your actual key. The payload variable structures your input according to the required schema, and the endpoint URL and request structure are illustrative.

Conclusion

The Generate Enhanced Images action from the sundai-club/snow_bunny Cognitive Actions offers a powerful and flexible way to incorporate image generation into your applications. By leveraging this action, developers can create unique images tailored to their specific needs. Explore further use cases, experiment with different parameters, and enhance your applications with the capabilities of Cognitive Actions.