Create Engaging Live Portraits with the BuddhiRaz LivePortraitV1 Cognitive Actions

In today's digital landscape, the ability to create dynamic and engaging content is essential. The BuddhiRaz LivePortraitV1 Cognitive Actions allow developers to generate stunning live portrait animations by combining static images with driving videos. This integration harnesses advanced features such as lip zero, eye retargeting, and customizable parameters to enhance the quality of animations. The pre-built actions simplify the development process, letting you focus on creativity rather than complex algorithms.
Prerequisites
Before diving into the integration of LivePortraitV1 Cognitive Actions, ensure you have:
- An API key for the Cognitive Actions platform.
- A basic understanding of how to make HTTP requests and handle JSON data.
Authentication typically involves passing the API key in the headers of your requests, ensuring secure access to the service.
Cognitive Actions Overview
Generate Live Portrait Animation
Description:
This action creates a live portrait animation by combining a base image portrait with a driving video. It enhances animation quality with features like lip zero, eye retargeting, and lip retargeting, allowing customization in portrait size, shift ratios, and frame selection.
Category: Image Animation
Input
The input schema for this action requires the following properties:
- inputImagePath (string, required): URI of the portrait image containing a face.
- inputVideoPath (string, required): URI of the video that will drive the animation.
- lipZeroFlag (boolean, optional): Enable lip zero feature (default: true).
- frameLoadCap (integer, optional): Maximum number of frames to load from the video (default: 128).
- portraitSize (integer, optional): Size of the output image in pixels (default: 512, range: 64-2048).
- cropInputFlag (boolean, optional): Enable cropping of the input image (default: true).
- pastebackFlag (boolean, optional): Enable paste-back feature for output images (default: true).
- portraitScale (number, optional): Scaling factor for the face (default: 2.3, range: 1-4).
- relativeInputFlag (boolean, optional): Enable relative motion input (default: true).
- eyeRetargetingFlag (boolean, optional): Enable eye retargeting feature (default: false).
- lipRetargetingFlag (boolean, optional): Enable lip retargeting feature (default: false).
- selectEveryNFrames (integer, optional): Select every nth frame from the video (default: 1).
- verticalShiftRatio (number, optional): Adjust vertical shift of the portrait (default: -0.12, range: -1 to 1).
- horizontalShiftRatio (number, optional): Adjust horizontal shift of the portrait (default: 0, range: -1 to 1).
- relativePositioningFlag (boolean, optional): Use relative positioning in rendering (default: true).
- eyeRetargetingMultiplier (number, optional): Eye retargeting adjustment multiplier (default: 1, range: 0.01 to 10).
- lipRetargetingMultiplier (number, optional): Lip retargeting adjustment multiplier (default: 1, range: 0.01 to 10).
Example Input:
{
"lipZeroFlag": true,
"frameLoadCap": 128,
"portraitSize": 512,
"cropInputFlag": true,
"pastebackFlag": true,
"portraitScale": 2.3,
"stitchingFlag": true,
"inputImagePath": "https://replicate.delivery/pbxt/LFzuXbwINYxNv26erUHNYNR85H3hROWAHbnR2nCsfhf4YHzA/Screenshot%20from%202024-07-08%2014-50-41.png",
"inputVideoPath": "https://replicate.delivery/pbxt/LFzuXFbzMx12AJnrrpRNqXuwDXpTCEoLajXvo1LC3GSCFlHk/d14.mp4",
"relativeInputFlag": true,
"eyeRetargetingFlag": false,
"lipRetargetingFlag": false,
"selectEveryNFrames": 1,
"verticalShiftRatio": -0.12,
"horizontalShiftRatio": 0,
"relativePositioningFlag": true,
"eyeRetargetingMultiplier": 1,
"lipRetargetingMultiplier": 1
}
Output
The action typically returns a URI of the generated animation. For example:
https://assets.cognitiveactions.com/invocations/883e2028-d5b0-42c7-a0f1-24d2d30db059/4cf5ea10-69f4-4d75-b78e-6f9122318abf.mp4
Conceptual Usage Example (Python)
Here’s how you might call the Generate Live Portrait Animation 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 = "e163ebc9-4669-4136-bb73-5b3df66465f2" # Action ID for Generate Live Portrait Animation
# Construct the input payload based on the action's requirements
payload = {
"lipZeroFlag": true,
"frameLoadCap": 128,
"portraitSize": 512,
"cropInputFlag": true,
"pastebackFlag": true,
"portraitScale": 2.3,
"stitchingFlag": true,
"inputImagePath": "https://replicate.delivery/pbxt/LFzuXbwINYxNv26erUHNYNR85H3hROWAHbnR2nCsfhf4YHzA/Screenshot%20from%202024-07-08%2014-50-41.png",
"inputVideoPath": "https://replicate.delivery/pbxt/LFzuXFbzMx12AJnrrpRNqXuwDXpTCEoLajXvo1LC3GSCFlHk/d14.mp4",
"relativeInputFlag": true,
"eyeRetargetingFlag": false,
"lipRetargetingFlag": false,
"selectEveryNFrames": 1,
"verticalShiftRatio": -0.12,
"horizontalShiftRatio": 0,
"relativePositioningFlag": true,
"eyeRetargetingMultiplier": 1,
"lipRetargetingMultiplier": 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 snippet, the action ID and the structured input payload are clearly defined. The endpoint URL and request structure are illustrative, emphasizing that they may differ in actual implementation.
Conclusion
The BuddhiRaz LivePortraitV1 Cognitive Actions provide a powerful tool for developers looking to create interactive and engaging animations. By leveraging the capabilities of the Generate Live Portrait Animation action, you can easily transform static images into dynamic content. Explore various configurations to find the perfect combination for your projects, and enhance your applications with captivating visual experiences!