Unleashing Creativity: Image Generation with ratimics/project89 Cognitive Actions

24 Apr 2025
Unleashing Creativity: Image Generation with ratimics/project89 Cognitive Actions

In the evolving landscape of image generation, the ratimics/project89 Cognitive Actions provide developers with powerful tools to create stunning visuals through advanced inpainting techniques. These pre-built actions allow for customizable parameters such as image dimensions, output quality, and various inference models, enabling seamless integration into applications. Whether you are building an art application, a game, or any platform requiring dynamic image generation, these Cognitive Actions can enhance your project significantly.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • A basic understanding of JSON structure for input and output data.
  • Familiarity with making HTTP requests in your chosen programming language.

For authentication, you will typically pass your API key in the headers of your requests, ensuring a secure connection to the Cognitive Actions API.

Cognitive Actions Overview

Generate Images with Custom Inpainting

Description:
This action enables the creation of images using advanced inpainting techniques. You can customize parameters such as image dimensions, LoRA intensities, and output quality. It supports fast execution and different inference models for optimized performance.

Category: image-generation

Input

The input for this action requires a JSON object structured according to the following schema:

  • prompt (required): A text prompt guiding image generation (e.g., "P89 A male Executive. Anime Style").
  • Optional fields include:
    • mask: Image mask for inpainting mode (URI format).
    • seed: Integer seed for reproducibility.
    • image: Input image for image-to-image or inpainting mode (URI format).
    • width: Integer for image width (256-1440 pixels).
    • height: Integer for image height (256-1440 pixels).
    • goFast: Boolean to enable fast predictions (default: false).
    • aspectRatio: Aspect ratio for the image (default: "1:1").
    • numOutputs: Integer to define the number of output images (1-4).
    • outputFormat: File format for output images (e.g., "webp").
    • guidanceScale: Number to guide the diffusion process (default: 3).
    • outputQuality: Integer for image output quality (0-100).
    • numInferenceSteps: Integer for the number of denoising steps in generation (1-50).
    • Additional parameters for LoRA weights and scaling are also available.

Example Input:

{
  "goFast": false,
  "prompt": "P89 A male Executive. Anime Style",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numInferenceSteps": 28
}

Output

The action typically returns a URL to the generated image file.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/d0bdefb2-7454-434f-af12-d150a27bf036/91be5a84-5670-42bc-b157-520b6b5b712a.webp"
]

Conceptual Usage Example (Python)

Here’s how a developer might call this action using a hypothetical Cognitive Actions execution endpoint:

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 = "bcb5e42b-7c60-4113-bf13-7853244f5e23" # Action ID for Generate Images with Custom Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "P89 A male Executive. Anime Style",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "numInferenceSteps": 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 this example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload structure are defined by the Cognitive Actions specification.

Conclusion

The ratimics/project89 Cognitive Actions empower developers to generate custom images efficiently, leveraging advanced inpainting techniques and various customizable parameters. By integrating these actions, you can enhance user experience and creativity in your applications. Explore further use cases, experiment with different parameters, and unlock the full potential of your projects!