Create Stunning Videos with Hunyuan-Video LoRA Cognitive Actions

In the world of video generation, the Hunyuan-Video model powered by Cognitive Actions offers developers the ability to transform text descriptions into visually compelling videos. By utilizing LoRA files, developers can enhance customization and style integration without modifying the core model. This blog post will guide you through the capabilities of the Hunyuan-Video LoRA action and how to integrate it into your applications.
Prerequisites
Before you dive into using the Hunyuan-Video Cognitive Actions, ensure you have the following:
- An API key for authenticating requests to the Cognitive Actions platform.
- Basic knowledge of JSON, as you will be constructing JSON payloads for requests.
- Familiarity with Python, as we will provide a conceptual code snippet for making API calls.
Authentication typically involves passing your API key in the headers of your requests.
Cognitive Actions Overview
Explore and Train Hunyuan-Video Using LoRA
The Explore and Train Hunyuan-Video Using LoRA action allows developers to leverage the Hunyuan-Video model to create, train, and style videos based on text prompts. This action is categorized under video-generation.
Input
The input required for this action is structured as follows:
- seed (integer, optional): Specifies a seed for consistent outputs across runs. Default is random if not set.
- steps (integer, optional): Defines the number of diffusion steps (1-150). Higher values can enhance quality, defaulting to 50.
- width (integer, optional): Video width in pixels (64-1536), default is 640.
- height (integer, optional): Video height in pixels (64-1024), default is 360.
- prompt (string, required): A textual description guiding scene creation in the video.
- flowShift (integer, optional): Adjusts continuity of video frames (0-20), default is 9.
- frameRate (integer, optional): Frames per second for the video (1-60), default is 16.
- numFrames (integer, optional): Total frames in the video (1-1440), default is 33.
- scheduler (string, optional): Algorithm for frame generation, default is "DPMSolverMultistepScheduler".
- loraFileUrl (string, required): URL linking to your LoRA .safetensors file or Hugging Face repository.
- enhancePairs (boolean, optional): Apply enhancements across pairs of frames, default is true.
- forceOffload (boolean, optional): Offload model layers to CPU, default is true.
- enhanceFrames (boolean, optional): Apply enhancements to individual frames, default is true.
- guidanceScale (number, optional): Balance between adherence to prompts and model predictions (0-30), default is 6.
- loraInfluence (number, optional): Scale of influence for your LoRA (-10 to 10), default is 1.
- denoiseStrength (number, optional): Intensity of noise applied in each step (0-2), default is 1.
- enhancementEndTime (number, optional): End time for enhancements, must be greater than enhancementStartTime, default is 1.
- enhancementStrength (number, optional): Intensity of the enhancement effect (0-2), default is 0.3.
- enhancementStartTime (number, optional): Start time for enhancements, must be less than enhancementEndTime, default is 0.
- compressionRateFactor (integer, optional): CRF value for H264 encoding (0-51), default is 19.
Here is an example input JSON payload for this action:
{
"steps": 30,
"width": 512,
"height": 512,
"prompt": "In the style of RSNG. A woman with blonde hair stands on a balcony at night, framed against a backdrop of city lights. She wears a white crop top and a dark jacket, exuding a confident presence as she gazes directly at the camera",
"flowShift": 9,
"frameRate": 15,
"numFrames": 33,
"scheduler": "DPMSolverMultistepScheduler",
"loraFileUrl": "lucataco/hunyuan-musubi-rose-6",
"enhancePairs": true,
"forceOffload": true,
"enhanceFrames": true,
"guidanceScale": 6,
"loraInfluence": 1,
"denoiseStrength": 1,
"enhancementEndTime": 1,
"enhancementStrength": 0.3,
"enhancementStartTime": 0,
"compressionRateFactor": 19
}
Output
Upon successful execution, the action will return a URL to the generated video. An example output might look like this:
https://assets.cognitiveactions.com/invocations/369e4d4c-267c-43ad-905b-c5ed13cadb2b/07673834-21a5-407f-a624-d7ee10a22a11.mp4
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet demonstrating how to call the Hunyuan-Video 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 = "0cc0129f-5695-4609-bf73-7b2f30cbc1e8" # Action ID for Explore and Train Hunyuan-Video Using LoRA
# Construct the input payload based on the action's requirements
payload = {
"steps": 30,
"width": 512,
"height": 512,
"prompt": "In the style of RSNG. A woman with blonde hair stands on a balcony at night, framed against a backdrop of city lights. She wears a white crop top and a dark jacket, exuding a confident presence as she gazes directly at the camera",
"flowShift": 9,
"frameRate": 15,
"numFrames": 33,
"scheduler": "DPMSolverMultistepScheduler",
"loraFileUrl": "lucataco/hunyuan-musubi-rose-6",
"enhancePairs": True,
"forceOffload": True,
"enhanceFrames": True,
"guidanceScale": 6,
"loraInfluence": 1,
"denoiseStrength": 1,
"enhancementEndTime": 1,
"enhancementStrength": 0.3,
"enhancementStartTime": 0,
"compressionRateFactor": 19
}
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:
- Replace
YOUR_COGNITIVE_ACTIONS_API_KEYwith your actual API key. - The
payloadvariable is constructed according to the action's input schema. - The endpoint URL and request structure are illustrative, helping you understand how to call the Cognitive Actions API.
Conclusion
The Hunyuan-Video LoRA Cognitive Action empowers developers to create unique, stylized videos directly from text prompts, making it a valuable tool for applications in content creation, marketing, and more. With its extensive customization options, you can produce high-quality videos tailored to your specifications.
Explore the possibilities, experiment with different parameters, and take your video generation to the next level!