Create Stunning Images with the Doobls AI Cognitive Actions

24 Apr 2025
Create Stunning Images with the Doobls AI Cognitive Actions

In the rapidly evolving landscape of artificial intelligence, the ability to generate images through innovative techniques like inpainting has taken center stage. The Doobls AI Cognitive Actions library, specifically the doobls-ai/marc-gt3-rs-04-12-2024 spec, offers developers a powerful toolset for image generation. With customizable parameters and support for various models, these pre-built actions streamline the process of creating high-quality visuals that meet diverse needs.

Prerequisites

To get started with the Cognitive Actions, you will need:

  • An API key for the Cognitive Actions platform, which you’ll include in your request headers for authentication.
  • Familiarity with JSON format for structuring your input data.

Conceptually, authentication typically involves passing your API key as a bearer token in the request headers.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create an image using inpainting mode, with a variety of customizable parameters. This action supports both the 'dev' and 'schnell' models, enabling you to choose between quality and speed based on your requirements.

Input

The input for this action is structured as follows:

  • Required Fields:
    • prompt (string): The descriptive text that guides the image generation.
  • Optional Fields:
    • mask (string): URI for the image mask for inpainting.
    • seed (integer): Random seed for reproducibility.
    • image (string): Input image URI for image-to-image transformations.
    • model (string): Choose between 'dev' (optimized for quality) and 'schnell' (optimized for speed).
    • width (integer): Width of the generated image (only if aspect_ratio is set to custom).
    • height (integer): Height of the generated image (only if aspect_ratio is set to custom).
    • aspectRatio (string): Aspect ratio for the generated image.
    • outputFormat (string): Format of the output images (default is 'webp').
    • guidanceScale (number): Scale for the diffusion process.
    • And many more...

Example Input:

{
  "model": "dev",
  "prompt": "gt3-rs driving at night, fotoshoot neon lights in japan",
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "loraIntensity": 1,
  "outputQuality": 80,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 28,
  "additionalLoraIntensity": 1
}

Output

The output from this action will typically return a URL pointing to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/1706a1d2-9852-4197-abdb-bfddce406092/c9d294a8-c863-4953-95eb-37d3cf1f3ad5.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet to demonstrate how to call the Generate Image with Inpainting 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 = "d56a7ceb-846c-47c0-8f91-e6707a7c840e"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "gt3-rs driving at night, fotoshoot neon lights in japan",
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "loraIntensity": 1,
    "outputQuality": 80,
    "enableFastMode": False,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 28,
    "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 code, we define the action ID and structure our input payload according to the required schema. The response will provide a URL where the generated image can be accessed.

Conclusion

The Doobls AI Cognitive Actions library enables developers to harness the power of AI image generation with ease. By utilizing the Generate Image with Inpainting action, you can create stunning visuals tailored to your specific requirements. Explore the possibilities and enhance your applications with high-quality images generated through cutting-edge AI technology. Happy coding!