Create Stunning Videos with Wan2.1 and Lora Integration

25 Apr 2025
Create Stunning Videos with Wan2.1 and Lora Integration

In the realm of video content creation, the demand for high-quality, customizable videos continues to grow. The "Wan2.1 With Lora" service offers developers a powerful solution for generating captivating videos tailored to specific needs. By leveraging the advanced capabilities of the Wan2.1 models, coupled with the Lora enhancement, users can produce videos that are not only visually appealing but also aligned with their creative vision.

This service provides significant benefits, including the ability to choose between two model types—14b for superior quality and 1.3b for faster processing—allowing developers to optimize for either quality or speed depending on the project requirements. Additionally, the customization options available—such as frame count, resolution, aspect ratio, and more—enable a high degree of flexibility in video production.

Common use cases include creating animated videos for marketing campaigns, educational content, or social media posts where visual storytelling is essential. With the ability to fine-tune various parameters, developers can ensure their videos resonate with their target audience while maintaining a unique style.

Prerequisites

To get started, developers will need a Cognitive Actions API key and a basic understanding of making API calls.

Generate Video with Wan2.1 and Lora

The "Generate Video with Wan2.1 and Lora" action allows developers to produce videos by utilizing the Wan2.1 models enhanced with Lora. This action addresses the need for high-quality video content generation while providing various customization options.

Input Requirements

The action requires a CompositeRequest object with the following fields:

  • textPrompt (string, required): A descriptive prompt to guide the video generation, e.g., "flat color 2d animation of a portrait of woman with white hair and green eyes, dynamic scene."
  • modelType (string, optional): Choose between "1.3b" for speed or "14b" for quality, defaulting to "14b."
  • frameCount (integer, optional): Specify the number of frames (17-81) for the video.
  • videoResolution (string, optional): Select either "480p" or "720p" (only for the 14b model).
  • videoAspectRatio (string, optional): Choose the aspect ratio, such as "16:9," "9:16," or "1:1."
  • guideScale (number, optional): Control adherence to the text prompt, ranging from 0 to 10.
  • Additional optional parameters include speedMode, randomSeed, externalUrl, shiftFactor, clipStrength, modelStrength, avoidancePrompt, and generationSteps.

Expected Output

The expected output is a URL link to the generated video, which could look something like this:

  • Example: https://assets.cognitiveactions.com/invocations/6a2556c1-2d84-462d-b7d4-7d5f3cff8786/8c51cbbd-f8c3-4ed5-9855-ec852e3417a1.mp4

Use Cases for this Specific Action

  • Marketing Videos: Quickly produce engaging promotional content that aligns with branding guidelines.
  • Educational Content: Create animated tutorials or explainer videos that simplify complex topics.
  • Social Media: Generate eye-catching videos tailored for platforms like Instagram or TikTok, enhancing audience engagement.
  • Artistic Projects: Experiment with unique styles and themes, allowing artists to bring their visions to life through animation.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "59b3e9f9-3d68-4dd7-932b-4d4d2fd1c6c4" # Action ID for: Generate Video with Wan2.1 and Lora

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "modelType": "14b",
  "frameCount": 81,
  "guideScale": 5,
  "textPrompt": "flat color 2d animation of a portrait of woman with white hair and green eyes, dynamic scene",
  "externalUrl": "https://huggingface.co/motimalu/wan-flat-color-v2/resolve/main/wan_flat_color_v2.safetensors",
  "shiftFactor": 8,
  "clipStrength": 1,
  "modelStrength": 1,
  "generationSteps": 30,
  "videoAspectRatio": "16:9"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The "Wan2.1 With Lora" service empowers developers to create high-quality, customizable videos with ease. With its dual model options and a wide range of parameters to adjust, this service is ideal for various applications, from marketing to education. By integrating this powerful tool into your projects, you can streamline video production while ensuring your content stands out.

As a next step, consider experimenting with different model types and settings to discover the optimal configurations for your specific video projects. Embrace the creative potential of AI-driven video generation today!