Class: RunApi::Wan::Resources::Animate

Inherits:
Object
  • Object
show all
Includes:
Core::ResourceHelpers
Defined in:
lib/runapi/wan/resources/animate.rb

Overview

Transfers motion from a reference video onto a subject in the source image. Use wan-2.2-animate-move to preserve the subject and animate its motion, or wan-2.2-animate-replace to swap the subject with the reference video’s subject.

Constant Summary collapse

ENDPOINT =
"/api/v1/wan/animate"
RESPONSE_CLASS =
Types::VideoTaskResponse
COMPLETED_RESPONSE_CLASS =
Types::CompletedVideoTaskResponse

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Animate

Returns a new instance of Animate.



16
17
18
# File 'lib/runapi/wan/resources/animate.rb', line 16

def initialize(http)
  @http = http
end

Instance Method Details

#create(**params) ⇒ RunApi::Wan::Types::VideoTaskResponse

Create an animation task.

Parameters:

  • params (Hash)

    animation parameters

Returns:



33
34
35
36
37
# File 'lib/runapi/wan/resources/animate.rb', line 33

def create(**params)
  params = compact_params(params)
  validate_params!(params)
  request(:post, ENDPOINT, body: params)
end

#get(id) ⇒ RunApi::Wan::Types::VideoTaskResponse

Get animation status by task ID.

Parameters:

  • id (String)

    task ID

Returns:



43
44
45
# File 'lib/runapi/wan/resources/animate.rb', line 43

def get(id)
  request(:get, "#{ENDPOINT}/#{id}")
end

#run(**params) ⇒ RunApi::Wan::Types::CompletedVideoTaskResponse

Transfer motion and wait until complete.

Parameters:

  • params (Hash)

    animation parameters

Returns:



24
25
26
27
# File 'lib/runapi/wan/resources/animate.rb', line 24

def run(**params)
  task = create(**params)
  poll_until_complete { get(task.id) }
end