Enhance Your Images: A Developer's Guide to micoblanc/dad-23-images Cognitive Actions

23 Apr 2025
Enhance Your Images: A Developer's Guide to micoblanc/dad-23-images Cognitive Actions

In the world of image processing, the ability to generate and enhance images based on textual prompts can significantly elevate your applications. The micoblanc/dad-23-images spec provides a powerful Cognitive Action: Generate Enhanced Image. This action leverages advanced techniques like inpainting and image-to-image transformation, allowing developers to create high-quality images with customizable parameters.

Using these pre-built actions not only saves development time but also empowers developers to harness sophisticated image generation capabilities quickly and effectively.

Prerequisites

To get started with the Cognitive Actions for micoblanc/dad-23-images, you'll need:

  • API Key: An API key from the Cognitive Actions platform to authenticate your requests.
  • Basic Setup: Familiarity with making API calls and handling JSON payloads.

Authentication typically involves passing your API key in the headers of your requests, ensuring that all actions are secured and traceable.

Cognitive Actions Overview

Generate Enhanced Image

The Generate Enhanced Image action creates high-quality images using both inpainting and image-to-image modes. It offers adjustable parameters such as image quality, aspect ratio, and LoRA scaling to cater to diverse needs in image generation.

Input

The input for this action is defined in the CompositeRequest schema, with the required fields and their descriptions outlined below:

  • prompt (string): Text prompt to guide image generation (required).
  • mask (string, optional): URI of the image mask for inpainting mode.
  • seed (integer, optional): Seed for randomization to ensure reproducibility.
  • image (string, optional): URI of the input image for image-to-image or inpainting modes.
  • width (integer, optional): Desired width of the generated image (must be between 256 and 1440).
  • height (integer, optional): Desired height of the generated image (must be between 256 and 1440).
  • goFast (boolean, optional): Enables faster generation for quicker results (defaults to false).
  • guidanceScale (number, optional): Scale of guidance during the diffusion process (defaults to 3).
  • outputQuality (integer, optional): Quality for saving output images (0 to 100, defaults to 80).
  • numOutputs (integer, optional): Number of outputs to generate (1 to 4, defaults to 1).
  • imageOutputFormat (string, optional): Format of the saved output image (options: 'webp', 'jpg', 'png', defaults to 'webp').

Example Input:

{
  "goFast": true,
  "prompt": "TOK man looking at the camera with natural light",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "guidanceScale": 2,
  "outputQuality": 90,
  "extraLoraScale": 1.5,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 32
}

Output

The output of the action typically returns a URL to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/2b8ece5e-569d-4429-9d24-b85d816b8b5e/0b8f96bc-8221-4419-b44e-3ce44e1d1539.jpg"
]

This URL links to the enhanced image generated based on the provided prompt and settings.

Conceptual Usage Example (Python)

Here’s how you might call the Generate Enhanced Image 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 = "9d71d77f-8d2d-4af9-b630-76e73f001511" # Action ID for Generate Enhanced Image

# Construct the input payload based on the action's requirements
payload = {
    "goFast": true,
    "prompt": "TOK man looking at the camera with natural light",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "guidanceScale": 2,
    "outputQuality": 90,
    "extraLoraScale": 1.5,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "jpg",
    "numInferenceSteps": 32
}

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 COGNITIVE_ACTIONS_API_KEY with your API key. The payload variable contains the input parameters structured according to the schema, and the action ID is specified for the Generate Enhanced Image action. This example demonstrates how to make a request to the hypothetical endpoint and handle the response.

Conclusion

The Generate Enhanced Image action within the micoblanc/dad-23-images spec provides developers with a valuable tool for creating and enhancing images efficiently. By leveraging customizable parameters, you can generate high-quality images tailored to your application's needs.

Explore these capabilities further and consider integrating them into your projects to enhance user experience and visual appeal. Happy coding!