Animate Portraits Effortlessly with mbukerepo/live-portrait Cognitive Actions

22 Apr 2025
Animate Portraits Effortlessly with mbukerepo/live-portrait Cognitive Actions

Integrating animation into applications has never been easier with the mbukerepo/live-portrait Cognitive Actions. This set of actions allows developers to create dynamic portraits by seamlessly blending images with videos, offering enhanced user experiences. The pre-built actions simplify the animation process, allowing for features like input cropping and pasteback functionalities, which give users greater control over how their animations are generated.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with making HTTP requests and handling JSON data.

Authentication typically involves passing your API key in the request headers, which will be detailed in the usage examples below.

Cognitive Actions Overview

Animate Portrait with Retargeting

Description: This action allows you to create animated portraits by stitching together an image and a video. It enhances user control over the animation process with features such as cropping input images and applying pasteback functionalities.

Category: image-animation

Input

The input schema for this action requires the following fields:

  • inputImagePath (required): The URI of the portrait image to be used. Must be accessible over the internet.
  • inputVideoPath (required): The URI of the driving video to be used. Must be accessible over the internet.
  • enableCropInput (optional): A boolean indicating whether to crop the input image. Defaults to true.
  • enablePasteback (optional): A boolean indicating whether the paste-back functionality is enabled. Defaults to true.
  • enableRelativeInput (optional): A boolean indicating whether to apply relative motion processing. Defaults to true.

Example Input:

{
  "inputImagePath": "https://replicate.delivery/pbxt/LENuJxQtTDy21AqLGeIPFR2aWRMUvUUIuzlMWqGAuDQS2T9Y/s9.jpg",
  "inputVideoPath": "https://replicate.delivery/pbxt/LENuJTpAkCkWI1pYnnV8hKJjC1jjUBzw8X6lHt111cliA4WV/d2.mp4",
  "enableCropInput": true,
  "enablePasteback": true,
  "enableRelativeInput": true
}

Output

The output of this action will typically return a URI pointing to the created animated portrait video.

Example Output:

https://assets.cognitiveactions.com/invocations/961858b7-2079-4b03-8f52-028a35ebb793/116e7d88-dce9-4595-8326-9422f2251579.mp4

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet to illustrate how you might call the Animate Portrait with Retargeting 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 = "418cacc3-f2c5-46c3-b2ad-880ea3b6483b"  # Action ID for Animate Portrait with Retargeting

# Construct the input payload based on the action's requirements
payload = {
    "inputImagePath": "https://replicate.delivery/pbxt/LENuJxQtTDy21AqLGeIPFR2aWRMUvUUIuzlMWqGAuDQS2T9Y/s9.jpg",
    "inputVideoPath": "https://replicate.delivery/pbxt/LENuJTpAkCkWI1pYnnV8hKJjC1jjUBzw8X6lHt111cliA4WV/d2.mp4",
    "enableCropInput": true,
    "enablePasteback": true,
    "enableRelativeInput": true
}

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 is specific to the “Animate Portrait with Retargeting” action, and the input payload is structured based on the required schema.

Conclusion

The mbukerepo/live-portrait Cognitive Actions offer a powerful way for developers to create engaging animated portraits with minimal effort. By understanding the capabilities of the Animate Portrait with Retargeting action, you can enhance your applications with dynamic visual content. Consider exploring additional use cases, such as integrating this functionality into social media applications, gaming, or personalized content creation tools. Happy coding!