Generate Stunning Images with the ttop4c/chen Cognitive Actions

25 Apr 2025
Generate Stunning Images with the ttop4c/chen Cognitive Actions

In the world of AI and machine learning, the ability to generate high-quality images is a game changer. The ttop4c/chen API provides a powerful set of Cognitive Actions designed specifically for image generation. This article will guide you through the process of utilizing these Cognitive Actions, particularly focusing on the action that allows for generating images with inpainting or custom dimensions.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have:

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

To authenticate your requests, you will typically need to pass the API key in the request headers.

Cognitive Actions Overview

Generate Image with Inpainting or Custom Dimensions

Description:
This action enables developers to generate high-quality images utilizing inpainting or custom dimensions while allowing for various adjustable properties such as image masks, seed values, aspect ratios, and more. You can also enhance your image outputs with additional LoRA weights and select between speed-optimized or detail-oriented models.

Category: image-generation

Input

The action requires a structured JSON payload with the following schema:

  • Required:
    • prompt: A descriptive prompt for generating the image.
  • Optional:
    • mask: URI of the image mask (for inpainting).
    • seed: Random seed for reproducibility.
    • image: URI of the input image for image-to-image mode.
    • model: Choose between "dev" or "schnell".
    • width: Width of the generated image in pixels (when aspect_ratio is custom).
    • goFast: Enable faster predictions (default is false).
    • height: Height of the generated image in pixels (when aspect_ratio is custom).
    • imageFormat: Output format (webp, jpg, png).
    • outputCount: Number of images to generate (1 to 4).
    • imageQuality: Quality setting for saving output images (0 to 100).
    • guidanceScale: Guidance scale for the diffusion process (0 to 10).
    • loraIntensity: Intensity of the main LoRA application.
    • denoisingSteps: Number of steps for denoising (1 to 50).
    • promptStrength: Strength of the prompt in image-to-image mode (0 to 1).
    • imageResolution: Approximate resolution of generated images.
    • imageAspectRatio: Aspect ratio for the generated image.
    • safetyCheckerDisabled: Disable safety checker (default is false).
    • additionalLora: Additional LoRA weights.
    • additionalLoraIntensity: Intensity for the additional LoRA application.

Example Input:

{
  "image": "https://replicate.delivery/pbxt/MT3uTeXdFwtdzcNKpMXt9gaTSgVjrQy3gWVbnCmqNFsRWOjn/logo.jpeg",
  "model": "dev",
  "goFast": false,
  "prompt": "yin yang symbol, traditional Chinese ink wash painting, misty mountains, gold accents, minimalist oriental art, textured paper, zen aesthetics, high contrast black and white, elegant composition, surreal landscape",
  "imageFormat": "png",
  "outputCount": 1,
  "imageQuality": 80,
  "guidanceScale": 3,
  "loraIntensity": 1,
  "denoisingSteps": 28,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "imageAspectRatio": "1:1",
  "additionalLoraIntensity": 1
}

Output

The action typically returns a URL to the generated image. Here’s an example response:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/688249d2-2212-4a02-9eed-c72d74655836/f26e7e4a-e2df-4f08-be79-ab4c109ef610.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet that demonstrates how to call the Cognitive Actions execution endpoint for this action:

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 = "21b9f122-f0bb-447c-ac13-bfebde689bce"  # Action ID for Generate Image with Inpainting or Custom Dimensions

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MT3uTeXdFwtdzcNKpMXt9gaTSgVjrQy3gWVbnCmqNFsRWOjn/logo.jpeg",
    "model": "dev",
    "goFast": False,
    "prompt": "yin yang symbol, traditional Chinese ink wash painting, misty mountains, gold accents, minimalist oriental art, textured paper, zen aesthetics, high contrast black and white, elegant composition, surreal landscape",
    "imageFormat": "png",
    "outputCount": 1,
    "imageQuality": 80,
    "guidanceScale": 3,
    "loraIntensity": 1,
    "denoisingSteps": 28,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "imageAspectRatio": "1:1",
    "additionalLoraIntensity": 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 snippet:

  • Replace the COGNITIVE_ACTIONS_API_KEY and endpoint with your actual API key and endpoint.
  • The payload is constructed according to the input schema described earlier.
  • The response is printed out after execution.

Conclusion

With the ttop4c/chen Cognitive Actions, developers can seamlessly integrate high-quality image generation into their applications, leveraging the flexibility and power of customizable parameters. Whether you are looking to create artistic images or detailed visuals, these actions provide a robust solution for all your image generation needs. Experiment with different prompts and settings to discover the full potential of this powerful tool!