Create Stunning Avatars with the jesusizq/avatar-play Cognitive Actions

22 Apr 2025
Create Stunning Avatars with the jesusizq/avatar-play Cognitive Actions

In today's digital landscape, the demand for personalized avatars is skyrocketing. The jesusizq/avatar-play Cognitive Actions provide a powerful solution for developers looking to generate and refine avatars using advanced image processing techniques. With capabilities such as inpainting, adjustable settings for prompt strength, and various image refinement options, these pre-built actions make it easy to integrate sophisticated image generation features into your applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform. This key will be used for authentication with the service.
  • Familiarity with JSON format, as the input and output structures are JSON-based.
  • An understanding of basic HTTP requests, as you will be sending requests to the Cognitive Actions API.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Avatar with Inpainting

Purpose:
The "Generate Avatar with Inpainting" action allows you to create an avatar by refining and inpainting images. This action supports various settings, including input images, adjustable prompt strength, and the application of watermarks.

Category: Image Generation

Input

The input schema for this action requires several fields, both mandatory and optional:

  • mask (string, URI): The input mask for inpainting. Areas in black remain unchanged, while areas in white are filled.
  • seed (integer, optional): Initializes the random generator for reproducibility. Leave unset for a random seed.
  • image (string, URI): The input image used in img2img or inpainting operations.
  • width (integer, default: 1024): Specifies the output image width in pixels.
  • height (integer, default: 1024): Specifies the output image height in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): A text prompt guiding the content of the generated image.
  • loraScale (number, default: 0.6): Scale applied when utilizing LoRA on trained models.
  • numOutputs (integer, default: 1): Number of output images to generate (1-4).
  • refineSteps (integer, optional): Number of refinement steps for the base image.
  • refineStyle (string, default: "no_refiner"): Defines the refinement method.
  • guidanceScale (number, default: 7.5): Guidance scale factor for classifier-free guidance (1-50).
  • highNoiseFrac (number, default: 0.8): Fraction of noise applied by the expert ensemble refiner.
  • applyWatermark (boolean, default: true): Determines if a watermark is applied.
  • negativePrompt (string, optional): Attributes to avoid in the output.
  • promptStrength (number, default: 0.8): Influence of the prompt on the img2img/inpaint operation.
  • schedulingMethod (string, default: "K_EULER"): Algorithm for scheduling steps.
  • numInferenceSteps (integer, default: 50): Number of denoising steps (1-500).
  • disableSafetyChecker (boolean, default: false): Option to disable verification checks for generated images.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "breathtaking photograph of a 28 year old TOK, short-hair, award-winning, professional, highly detailed, with short hair, upper body framing, on a New York street, with neon lighting from shop signs, frontal shot from a high angle, on a Sony A7111, (hyper-realistic:1.5),",
  "loraScale": 0.75,
  "numOutputs": 1,
  "refineSteps": 5,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract glitch, blurry, hands",
  "promptStrength": 0.8,
  "schedulingMethod": "K_EULER",
  "numInferenceSteps": 50
}

Output

The action typically returns a list of URLs to the generated images. For example:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/2773f0c2-6eab-48e1-b868-cc2b7cdbe87e/2595d0ca-b5d6-4935-afc8-bbf1a7d9d6ec.png"
]

Conceptual Usage Example (Python)

Here's how a developer might call this 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 = "cd9e56ba-86ae-4ad9-b5b4-967a3fe13dc2"  # Action ID for Generate Avatar with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "breathtaking photograph of a 28 year old TOK, short-hair, award-winning, professional, highly detailed, with short hair, upper body framing, on a New York street, with neon lighting from shop signs, frontal shot from a high angle, on a Sony A7111, (hyper-realistic:1.5),",
    "loraScale": 0.75,
    "numOutputs": 1,
    "refineSteps": 5,
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": true,
    "negativePrompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract glitch, blurry, hands",
    "promptStrength": 0.8,
    "schedulingMethod": "K_EULER",
    "numInferenceSteps": 50
}

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 code snippet, replace the placeholder for the API key and endpoint with your actual credentials. The action ID and input payload are structured according to the specifications provided.

Conclusion

The jesusizq/avatar-play Cognitive Actions offer an impressive suite of tools for generating and refining avatars. With the ability to customize prompts, apply watermarks, and utilize various refinement techniques, developers can easily integrate these actions into their applications, enhancing user experiences with personalized visuals. Explore further use cases and consider how these capabilities can fit into your projects to elevate them to the next level!