Create Stunning Custom Portraits with the tokaito14/portrait Cognitive Actions

22 Apr 2025
Create Stunning Custom Portraits with the tokaito14/portrait Cognitive Actions

In today's digital landscape, generating unique and customizable images has become increasingly accessible. The tokaito14/portrait Cognitive Actions enable developers to create stunning portrait images through sophisticated image inpainting and transformation techniques. By leveraging specified prompts, image masks, and various model parameters, these actions enhance productivity and creativity. This article will guide you through the capabilities of the Generate Customized Portraits action, detailing its input requirements, output possibilities, and a conceptual example of how to integrate it into your applications.

Prerequisites

Before you can use the Cognitive Actions, you'll need to set up a few essentials:

  • API Key: Ensure you have an API key for the Cognitive Actions platform to authenticate your requests.
  • Endpoint URL: Familiarize yourself with the generic endpoint URL used to execute the actions (to be used in your code).

Authentication typically involves passing your API key in the headers of your requests, ensuring that your application can communicate securely with the Cognitive Actions service.

Cognitive Actions Overview

Generate Customized Portraits

The Generate Customized Portraits action creates unique and customizable portrait images through image inpainting or image-to-image transformations. By utilizing specified prompts, image masks, and model parameters, developers can generate high-quality images tailored to their needs. This action falls under the image-generation category.

Input

The input for this action is structured as follows:

  • Required Field:
    • prompt: A string that describes the desired image (e.g., "Fashionable person dressed in black and gold").
  • Optional Fields:
    • mask: (string) URI for an image mask used in inpainting mode.
    • seed: (integer) Random seed for reproducible generation.
    • image: (string) URI of an input image for image-to-image or inpainting mode.
    • model: (string) Select the model for inference (options: "dev", "schnell").
    • width: (integer) Width of the generated image in pixels (only applicable if aspect ratio is "custom").
    • height: (integer) Height of the generated image in pixels (only applicable if aspect ratio is "custom").
    • aspectRatio: (string) Defines the aspect ratio (e.g., "1:1", "16:9", or "custom").
    • outputCount: (integer) Number of output images to generate (1 to 4).
    • outputFormat: (string) File format for output images (options: "webp", "jpg", "png").
    • outputQuality: (integer) Quality level for output images (0 to 100).
    • denoisingSteps: (integer) Number of denoising steps (1 to 50).
    • Additional parameters for advanced customization (e.g., extraLora, loraScale, fastMode, etc.).

Example Input:

{
  "model": "dev",
  "width": 846,
  "height": 846,
  "prompt": "Fashionable person dressed in black and gold",
  "loraScale": 1,
  "aspectRatio": "9:16",
  "outputCount": 1,
  "outputFormat": "jpg",
  "outputQuality": 90,
  "denoisingSteps": 28,
  "extraLoraScale": 0.8,
  "diffusionGuidanceScale": 3.5
}

Output

The action typically returns a list of generated image URLs. Here’s an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/0c0ca7c1-32b8-466e-947f-2886828d5fc4/38259953-ea55-4f0b-aad3-811e0a4718d7.jpg"
]

This URL points to the generated portrait image, which can be accessed directly.

Conceptual Usage Example (Python)

Here’s how a developer might call the Generate Customized Portraits action using Python. This example focuses on structuring the input JSON payload correctly.

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 = "570d9171-30db-492c-bb34-3bfe6f99d0c2"  # Action ID for Generate Customized Portraits

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "width": 846,
    "height": 846,
    "prompt": "Fashionable person dressed in black and gold",
    "loraScale": 1,
    "aspectRatio": "9:16",
    "outputCount": 1,
    "outputFormat": "jpg",
    "outputQuality": 90,
    "denoisingSteps": 28,
    "extraLoraScale": 0.8,
    "diffusionGuidanceScale": 3.5
}

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 Python snippet:

  • The action_id corresponds to the Generate Customized Portraits action.
  • The payload is constructed based on the required and optional fields.
  • The request is sent to the hypothetical execution endpoint, and the response is processed accordingly.

Conclusion

The Generate Customized Portraits action from the tokaito14/portrait Cognitive Actions opens up exciting possibilities for developers looking to integrate sophisticated image generation capabilities into their applications. By utilizing prompts and customization options, you can create unique and high-quality portraits tailored to your needs. As you explore these functionalities, consider various use cases, from creative projects to practical applications, that can benefit from enhanced image generation. Happy coding!