Swiftly Generate Stunning Images with Tania's Cognitive Actions

24 Apr 2025
Swiftly Generate Stunning Images with Tania's Cognitive Actions

In the world of image generation, creativity meets technology in remarkable ways. The maximsasu/tania_photo API offers a powerful set of Cognitive Actions designed to help developers create high-quality images using advanced inpainting techniques. With options for customizing aspect ratios, resolutions, and styles, these actions provide a convenient way to generate visually striking images based on text prompts. In this article, we'll explore how to leverage these capabilities to enhance your applications.

Prerequisites

Before diving into the use of Cognitive Actions, you'll need a few essentials:

  • An API key for the Cognitive Actions platform to authenticate your requests. This key should be included in the request headers to ensure secure access.

Conceptually, authentication might look like this:

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

Cognitive Actions Overview

Generate Image with Inpainting and Rapid Mode

Description: This action allows you to generate images using inpainting and rapid processing mode. It enables the creation of high-quality images based on descriptive text prompts while offering control over aspect ratios, resolutions, and artistic styles. You can choose between the 'dev' or 'schnell' models for efficient image generation.

Category: image-generation

Input

The input for this action is structured as follows:

  • prompt (required): A descriptive text prompt for image generation. For example:
    "prompt": "Tania on a sunny ocean shore, wind blowing through her hair, waves crashing behind her, a mix of serenity and power in her stance, cinematic lighting, ultra-detailed, photorealism."
    
  • mask (optional): An image mask for inpainting.
  • seed (optional): A random seed for reproducible results.
  • image (optional): An input image for image-to-image or inpainting mode.
  • width (optional): Width of the generated image (only applicable if aspect_ratio is custom).
  • height (optional): Height of the generated image (only applicable if aspect_ratio is custom).
  • modelType (optional): Select either "dev" (default) or "schnell".
  • aspectRatio (optional): The aspect ratio of the generated image (default is "1:1").
  • outputCount (optional): Number of output images to generate (default is 1, maximum is 4).
  • outputFormat (optional): Format of the output images (default is "webp").
  • guidanceScale (optional): Scale for the diffusion process (default is 3).
  • loraIntensity (optional): Strength of the LoRA application (default is 1).
  • outputQuality (optional): Quality of the saved output images (default is 80).
  • enableFastMode (optional): Run faster predictions (default is false).
  • promptStrength (optional): Strength of the prompt when using img2img (default is 0.8).

Here's an example JSON payload for the input:

{
  "prompt": "Tania on a sunny ocean shore, wind blowing through her hair, waves crashing behind her, a mix of serenity and power in her stance, cinematic lighting, ultra-detailed, photorealism.",
  "modelType": "dev",
  "aspectRatio": "1:1",
  "outputCount": 4,
  "outputFormat": "png",
  "guidanceScale": 3,
  "loraIntensity": 1,
  "outputQuality": 80,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "numInferenceSteps": 40
}

Output

The output of this action typically returns an array of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/2b7cda53-46c4-4292-bae6-d1a11ad07bf7/497324ce-50b0-4948-93fd-b713c7aa53ec.png",
  "https://assets.cognitiveactions.com/invocations/2b7cda53-46c4-4292-bae6-d1a11ad07bf7/07ef652c-3880-4801-b1d6-6268b801b0af.png",
  "https://assets.cognitiveactions.com/invocations/2b7cda53-46c4-4292-bae6-d1a11ad07bf7/208b46d1-a125-4459-b8b7-7e0f74406c49.png",
  "https://assets.cognitiveactions.com/invocations/2b7cda53-46c4-4292-bae6-d1a11ad07bf7/b5921129-b1f7-4b6a-a0c6-f9c085444ee9.png"
]

Conceptual Usage Example (Python)

Here's a conceptual example of how you might call the Cognitive Actions endpoint 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 = "8000a4da-915d-441e-b810-db80c23f3fdd" # Action ID for Generate Image with Inpainting and Rapid Mode

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Tania on a sunny ocean shore, wind blowing through her hair, waves crashing behind her, a mix of serenity and power in her stance, cinematic lighting, ultra-detailed, photorealism.",
    "modelType": "dev",
    "aspectRatio": "1:1",
    "outputCount": 4,
    "outputFormat": "png",
    "guidanceScale": 3,
    "loraIntensity": 1,
    "outputQuality": 80,
    "enableFastMode": False,
    "promptStrength": 0.8,
    "numInferenceSteps": 40
}

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, you would replace the placeholder for the API key and endpoint with your actual credentials. The payload is structured to meet the input requirements of the action.

Conclusion

The maximsasu/tania_photo Cognitive Actions offer an exciting way to integrate powerful image generation capabilities into your applications. By utilizing the image inpainting and rapid mode features, developers can create stunning visuals that cater to specific needs and styles. As you explore these actions, consider experimenting with various input parameters to unlock the full potential of this API. Happy coding!