Skip to content

Submit a Job

SDK calls are made via the PortalClient object. Follow the Authentication guide on how to initialize and authenticate the PortalClient.

A job can be submitted to a project.

project = await client.get_project("{PROJECT_ID}")

Note

This is the ID of an enabled project, can be found in the Portal projects dashboard

A job requires the following parameters to be set:

Parameter Description
actor_name A string describing the actor in the video, you can use this as a search term. Does not need to be unique
tracking_model The tracking model to use. Options are STATIC_CAM, HEAD_CAM or HEAD_CAM_GRAYSCALE
video_file_path A valid path to the video that you want to track
calibration_image_file_path (Optional) A path to a calibration image. A calibration image is an image file of a neutral pose of the actor taken from one of the videos
video_rotation (Optional) Rotation angle to be applied while processing the video. Defaults to NONE
import uuid
from faceware.pyportal.job import TrackingModel, Job
from faceware.pyportal.job_result import JobStatus
from faceware.pyportal.project import Project
from faceware.pyportal import PortalClient

unique_str = str(uuid.uuid4())[0:5]

client = PortalClient(
    access_token="{YOUR-ACCESS-TOKEN}",
    organization_id="{YOUR-ORGANIZATION-ID}"
)

project = await client.get_project("{PROJECT-ID}")

job = await project.submit_job(
    actor_name=f"sample-actor-{unique_str}",
    tracking_model=TrackingModel.STATIC_CAM,
    video_file_path="sample/test-video.mp4"
)

Because job submission is asynchronous, the above call will return immediately after the video has been uploaded. Now we can write a simple polling loop that checks the job status until it reaches a terminal state (namely, JobStatus.COMPLETED or JobStatus.FAILED).

async def wait_until_status(job, status_to_wait_for):
    while await job.get_status() not in status_to_wait_for:
        print(f"status: {status}")

await wait_until_status(job, [JobStatus.COMPLETED, JobStatus.FAILED])
print("Finished processing job")

Tip

It's not recommended to have infinite polling loops. If you decide to have a timeout, make sure it has a reasonable timeout period depending on the length of the video uploaded.