Generate Stunning Images with the ferluht/bilibin Cognitive Actions

24 Apr 2025
Generate Stunning Images with the ferluht/bilibin Cognitive Actions

In the world of digital content creation, the ability to generate customized images based on textual descriptions can significantly enhance user experiences. The ferluht/bilibin Cognitive Actions provide developers with powerful tools to create unique images tailored to specific prompts. This API allows for a variety of customization options, including image dimensions, prompt strength, and refinement styles, making it ideal for applications in art generation, gaming, and virtual environments.

Prerequisites

Before integrating the Cognitive Actions into your application, ensure you have the following:

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

Authentication typically involves adding your API key in the request headers to authorize your actions.

Cognitive Actions Overview

Generate Customized Image

The Generate Customized Image action allows developers to create images based on textual descriptions and additional parameters. This action supports various styles and modes, including img2img and inpaint, and includes options for applying watermarks and safety checks.

Input

The action requires a structured input JSON. Here’s the schema:

{
  "mask": "string (optional)",
  "seed": "integer (optional)",
  "image": "string (optional)",
  "width": "integer (default: 1024)",
  "height": "integer (default: 1024)",
  "prompt": "string (default: 'An astronaut riding a rainbow unicorn')",
  "loraScale": "number (default: 0.6, range: 0-1)",
  "loraWeights": "string (optional)",
  "refineStyle": "string (default: 'no_refiner')",
  "scheduleType": "string (default: 'K_EULER')",
  "guidanceScale": "number (default: 7.5, range: 1-50)",
  "applyWatermark": "boolean (default: true)",
  "negativePrompt": "string (optional)",
  "promptStrength": "number (default: 0.8, range: 0-1)",
  "numberOfOutputs": "integer (default: 1, range: 1-4)",
  "refinementSteps": "integer (optional)",
  "highNoiseFraction": "number (default: 0.8, range: 0-1)",
  "inferenceStepsCount": "integer (default: 50, range: 1-500)",
  "disableSafetyChecker": "boolean (default: false)"
}

Here’s an example of a valid input payload:

{
  "width": 1024,
  "height": 1024,
  "prompt": "in style of bilibin a painting of a girl in the forest collecting mushrooms in a basket",
  "loraScale": 0.6,
  "refineStyle": "no_refiner",
  "scheduleType": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "inferenceStepsCount": 50
}

Output

Upon successful execution, the action typically returns an array of URLs for the generated images. Here’s an example of an output:

[
  "https://assets.cognitiveactions.com/invocations/a5b53a67-c57b-4e3c-8a27-6d732c89e118/bf88a9d7-1304-486b-bf16-29824e46bb85.png"
]

Conceptual Usage Example (Python)

Here’s how you might structure a call to the Generate Customized Image action in 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 = "53602d69-24be-47ae-880b-3855284f105b"  # Action ID for Generate Customized Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "in style of bilibin a painting of a girl in the forest collecting mushrooms in a basket",
    "loraScale": 0.6,
    "refineStyle": "no_refiner",
    "scheduleType": "K_EULER",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "inferenceStepsCount": 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 code snippet, replace the placeholder for the API key and endpoint with your actual details. The payload is structured according to the input schema, and the action ID corresponds to the Generate Customized Image action.

Conclusion

The Cognitive Actions within the ferluht/bilibin spec empower developers to create stunning, customized images effortlessly. By leveraging the flexibility of the input parameters, you can tailor the image generation process to meet your application's unique needs. Whether you are creating art, enhancing user engagement, or developing innovative visual content, these actions provide a robust solution for diverse use cases. Start experimenting with these actions today and unlock the potential of automated image generation!