Create Stunning Images with the emibob/bavis Cognitive Actions

24 Apr 2025
Create Stunning Images with the emibob/bavis Cognitive Actions

In the world of application development, integrating advanced image generation capabilities can significantly enhance user experience and engagement. The emibob/bavis Cognitive Actions provide developers with a powerful toolset to create detailed, lifelike images with a high degree of customization. By leveraging these pre-built actions, developers can quickly implement sophisticated image generation features in their applications, allowing for creative expression and functionality.

Prerequisites

To utilize the Cognitive Actions from the emibob/bavis spec, you'll need to ensure that you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of making API calls and handling JSON payloads.

Authentication typically involves passing your API key in the request headers to securely access the actions.

Cognitive Actions Overview

Generate Enhanced Image

The Generate Enhanced Image action allows developers to create detailed and lifelike images using specified image transformations or inpainting techniques. You can control various properties such as image size, format, and quality, making it a versatile option for developers looking to enhance their applications with custom imagery.

Input

The input for this action requires a structured JSON payload. The key fields include:

  • prompt (required): A detailed description of the image you wish to generate.
  • mask (optional): URI for an image mask, used in inpainting mode.
  • image (optional): URI for an input image, used in image-to-image transformations.
  • width (optional): An integer specifying the width of the generated image.
  • height (optional): An integer specifying the height of the generated image.
  • isFastMode (optional): Boolean to enable faster predictions.
  • imageFormat (optional): Specifies the output image format (webp, jpg, png).
  • modelChoice (optional): Selects the model for inference (dev or schnell).
  • imageQuality (optional): Sets the quality level of the output image (0-100).
  • numberOfOutputs (optional): Specifies how many images to generate (up to 4).

Here’s an example JSON payload for the Generate Enhanced Image action:

{
  "prompt": "TOK: A breathtaking, lifelike portrait of Baylor dressed in a simple yet stylish white top against a soft peach background. He wears a well-fitted, crisp white T-shirt or button-up shirt, exuding effortless confidence and timeless appeal. The fabric is high-quality and drapes naturally over his frame, creating a casual yet polished look. His posture is relaxed, and his expression is calm and self-assured. His hair is styled in a natural, effortlessly cool way, and his skin glows with a healthy, sun-kissed warmth. The soft peach background enhances his presence, creating a warm, modern, and inviting aesthetic. The image should feel deeply realistic, rich in texture and detail, capturing Baylor’s effortless style and quiet charisma.",
  "isFastMode": false,
  "imageFormat": "webp",
  "modelChoice": "dev",
  "imageQuality": 80,
  "guidanceScale": 3,
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "loraWeightScale": 1,
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "additionalLoraWeightScale": 1
}

Output

Upon executing the Generate Enhanced Image action, you will receive a response containing the URI of the generated image. Here’s an example of what the output might look like:

[
  "https://assets.cognitiveactions.com/invocations/b9a1805d-8d85-4931-8df5-e247e348e6f6/87e9326f-94f5-4464-bbbc-5571b8df054a.webp"
]

This URI can be used to access and display the generated image in your application.

Conceptual Usage Example (Python)

To demonstrate how to call the Generate Enhanced Image action, here’s a conceptual Python code snippet. This example assumes you have the necessary API key and endpoint ready.

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 = "a93397a1-4159-4aac-8e7b-83106f252eb4" # Action ID for Generate Enhanced Image

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "TOK: A breathtaking, lifelike portrait of Baylor dressed in a simple yet stylish white top against a soft peach background. He wears a well-fitted, crisp white T-shirt or button-up shirt, exuding effortless confidence and timeless appeal. The fabric is high-quality and drapes naturally over his frame, creating a casual yet polished look. His posture is relaxed, and his expression is calm and self-assured. His hair is styled in a natural, effortlessly cool way, and his skin glows with a healthy, sun-kissed warmth. The soft peach background enhances his presence, creating a warm, modern, and inviting aesthetic. The image should feel deeply realistic, rich in texture and detail, capturing Baylor’s effortless style and quiet charisma.",
    "isFastMode": false,
    "imageFormat": "webp",
    "modelChoice": "dev",
    "imageQuality": 80,
    "guidanceScale": 3,
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "loraWeightScale": 1,
    "numberOfOutputs": 1,
    "imageAspectRatio": "1:1",
    "additionalLoraWeightScale": 1
}

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, you construct the input payload based on the required fields, set up the request headers for authentication, and handle the response to retrieve the generated image URI.

Conclusion

The emibob/bavis Cognitive Actions, particularly the Generate Enhanced Image action, empower developers to seamlessly integrate advanced image generation into their applications. With customizable parameters and high-quality output, these actions can significantly enhance the visual appeal and functionality of your projects.

Consider exploring further use cases, such as inpainting, custom image transformations, or even batch processing multiple images, to fully leverage the capabilities of this powerful API.