import requestsimport json"""Details for creating JOBS,project_id ->> ID of project in which the job will be createdx_api_key ->> API key for authentication workflow_id ->> The workflow in which the job will be createdbatch_id ->> The batch in which job will be created"""# Additional helper function to create a batchdefcreate_batch(BATCH_NAME): base_url =f"https://api.playment.io/v1/projects/{PROJECT_ID}/batch" DATA ={"name":BATCH_NAME} response = requests.post(base_url, headers={'x-api-key': CLIENT_KEY}, json=DATA) response_data = response.json()if response.status_code >=500:raiseException(f"Something went wrong at Playment's end {response.status_code}")if400<= response.status_code <500:raiseException(f"{response_data['error']['message']}{response.status_code}")print(response_data)return response_data#method that can be used to call the job creation apidefcreate_job(project_id,data,x_api_key): base_url ="https://api.playment.io/v1/projects/{}/jobs".format(project_id) headers ={'x-api-key': x_api_key} response = requests.post(base_url, headers=headers, json=data)print(response.json())if response.status_code >=500:raiseException(response.text)if400<= response.status_code <500:raiseException(response.text)return response.json()if__name__=="__main__":#list of frames in a single job image_url ="https://example.com/image_url_1"#reference_id should be unique for each job reference_id="job1" project_id ='' x_api_key ='' workflow_id ='' batch_id ='' job_data ={'reference_id':reference_id,'work_flow_id':workflow_id,'data':{'image_url':image_url},'batch_id': batch_id} response =create_job(project_id=project_id, data=job_data, x_api_key= x_api_key)print(response)
Creating jobs with pre-labeled data
If you have data which has been labeled previously by an ML model or by human labelers, you can create jobs with such labels already created. To do this, you need to send the annotation data in the data.maker_response key in the payload. The annotation data needs to be in Playment's annotation format.
In our annotation output, the x and y coordinates are normalised to ensure consistency across different image sizes. Normalisation is crucial for accurately representing object positions relative to the image dimensions.
X and Y Coordinates:
X Coordinate:
The result ranges from 0.0 to 1.0, where 0.0(Origin) corresponds to the leftmost edge of the image, and 1.0 corresponds to the rightmost edge.
Y Coordinate:
The result ranges from 0.0 to 1.0, where 0.0(Origin) corresponds to the topmost edge of the image, and 1.0 corresponds to the bottommost edge.
Normalised xcoordinates (Xnorm) are calculated using the formula:
Xnorm=Xraw/ImageWidth
Normalised y coordinates (Ynorm) are calculated using the formula:
Ynorm=Yraw/ImageHeight
project_id
string
ID of the project in which you want to create the job
x-api-key
string
API key for authentication
batch_id
string
A batch is a way to organize multiple jobs under one batch_id. You can create new batches from the dashboard or by using the batch creation API.
If batch_id is left empty or the key is not present, the job is created in the Default batch in your project.
work_flow_id
string
The ID of the workflow inside which you want to create the job
data
object
The data object contains all the information and attachments required to label a job. The data object is defined below