# 7.1 Create a labelbox project
project = client.create_project(name="Conversational Text Prediction Import Demo",
media_type=lb.MediaType.Conversational)
project.connect_ontology(ontology)
# 7.2 Create a batch to send to the project
project.create_batch(
"batch_convo_prediction_demo", # Each batch in a project must have a unique name
global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys
priority=5 # priority between 1(Highest) - 5(lowest)
)
# 7.3 Create the annotations payload
ner_annotation = lb_types.ObjectAnnotation(
name="ner",
value=lb_types.ConversationEntity(
start=0,
end=8,
message_id="4"
)
)
text_annotation = lb_types.ClassificationAnnotation(
name="text_convo",
value=lb_types.Text(answer="the answer to the text questions are right here"),
message_id="0"
)
checklist_annotation= lb_types.ClassificationAnnotation(
name="checklist_convo", # must match your ontology feature"s name
value=lb_types.Checklist(
answer = [
lb_types.ClassificationAnswer(
name = "first_checklist_answer"
),
lb_types.ClassificationAnswer(
name = "second_checklist_answer"
)
]
),
message_id="2"
)
radio_annotation = lb_types.ClassificationAnnotation(
name="radio_convo",
value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = "first_radio_answer")),
message_id="0"
)
nested_checklist_annotation = lb_types.ClassificationAnnotation(
name="nested_checklist_question",
message_id="10",
value=lb_types.Checklist(
answer=[lb_types.ClassificationAnswer(
name="first_checklist_answer",
classifications=[
lb_types.ClassificationAnnotation(
name="sub_checklist_question",
value=lb_types.Checklist(
answer=[lb_types.ClassificationAnswer(
name="first_sub_checklist_answer"
)]
))
]
)]
)
)
nested_radio_annotation = lb_types.ClassificationAnnotation(
name="nested_radio_question",
value=lb_types.Radio(
answer=lb_types.ClassificationAnswer(
name="first_radio_answer",
classifications=[
lb_types.ClassificationAnnotation(
name="sub_radio_question",
value=lb_types.Radio(
answer=lb_types.ClassificationAnswer(
name="first_sub_radio_answer"
)
)
)
]
)
)
)
# 7.4 Create the label object
label = []
label.append(
lb_types.Label(
data= {"global_key": global_key},
annotations=[
ner_annotation,
text_annotation,
checklist_annotation,
radio_annotation,
nested_radio_annotation,
nested_checklist_annotation
]
)
)
# 7.5 Upload annotations to the project using label import
upload_job_annotation = lb.LabelImport.create_from_objects(
client = client,
project_id = project.uid,
name="text_label_import_job"+ str(uuid.uuid4()),
labels=label)
upload_job_annotation.wait_until_done()
# Errors will appear for annotation uploads that failed.
print("Errors:", upload_job_annotation.errors)
print("Status of uploads: ", upload_job_annotation.statuses)
# 7.6 Send the annotations to the model run
# get the labels from the project
model_run.upsert_labels(project_id=project.uid)