Generating Stunning Images with the swetabhsaurav/tealight Cognitive Actions

22 Apr 2025
Generating Stunning Images with the swetabhsaurav/tealight Cognitive Actions

In the digital age, the ability to generate and manipulate images efficiently is a valuable asset for developers. The swetabhsaurav/tealight spec offers a powerful Cognitive Action that allows you to create custom images with advanced inpainting capabilities. This action features customization options for dimensions, quality, and model parameters, making it a versatile tool for developers looking to enhance their applications with image generation.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform.
  • Basic familiarity with JSON and making API requests.
  • A development environment set up for Python, including the requests library.

To authenticate your requests, you will need to include your API key in the request headers. Here's a conceptual overview of how the authentication might look:

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

Cognitive Actions Overview

Generate Image with Inpainting and Customization

This action is designed to create images based on a provided prompt, with options for inpainting using masks and various customization settings. Whether you need to enhance image quality or speed, this action provides the flexibility to meet your requirements.

Category: Image Generation

Input

The input for this action is structured as follows:

{
  "prompt": "A warm and festive Diwali scene featuring several TLGT candles...",
  "model": "dev",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "additionalLoraScale": 1,
  "imagePromptStrength": 0.8,
  "loraApplicationScale": 1,
  "numberOfInferenceSteps": 28
}

Required fields:

  • prompt: The text prompt that guides the image generation.

Optional fields:

  • mask: URI for an image mask to use in inpainting.
  • seed: An integer seed for reproducible results.
  • image: URI for a source image if using image-to-image generation.
  • model: Choose between "dev" for quality or "schnell" for speed.
  • width: Specifies the image width (minimum 256, maximum 1440).
  • height: Specifies the image height (minimum 256, maximum 1440).
  • megapixels: Estimated megapixel count.
  • guidanceScale: Adjusts the influence of the prompt (0 to 10).
  • outputQuality: Set image quality from 0 (lowest) to 100 (highest).
  • numberOfOutputs: How many images to generate (1-4).
  • imageAspectRatio: Aspect ratio of the generated image.
  • imageOutputFormat: Format of the output image (webp, jpg, png).
  • disableSafetyChecker: Toggle safety checks during image generation.

Output

The output of this action typically returns a URL pointing to the generated image:

[
  "https://assets.cognitiveactions.com/invocations/679c108e-db52-4118-aa92-259e60c0dbd0/cea38219-ba17-4d26-b35f-2564c9a36d7b.webp"
]

This URL provides direct access to the generated image, which can be used in your applications or shared with users.

Conceptual Usage Example (Python)

Here’s how you might call this Cognitive 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 = "c5753b02-659e-4267-8d28-1dac57676e6f" # Action ID for Generate Image with Inpainting and Customization

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "A warm and festive Diwali scene featuring several TLGT candles placed on a decorative tray...",
    "model": "dev",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "numberOfOutputs": 1,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "additionalLoraScale": 1,
    "imagePromptStrength": 0.8,
    "loraApplicationScale": 1,
    "numberOfInferenceSteps": 28
}

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 the above Python code, we construct the input payload based on the action's requirements, including the prompt and other optional parameters. The API key is used for authorization, and we handle any potential request exceptions gracefully.

Conclusion

The swetabhsaurav/tealight Cognitive Action for generating images with inpainting and customization offers developers a powerful tool to enhance their applications with rich visual content. By integrating this action, you can provide users with tailored image generation capabilities that elevate the user experience. Consider exploring additional use cases such as artistic content creation, marketing visuals, or personalized graphics. Happy coding!