Skip to content

Commit 3f4e423

Browse files
authored
Merge pull request #1011 from Labelbox/ao_latest_notebooks
Wrapping global keys in a list
2 parents 51039b2 + df71892 commit 3f4e423

File tree

11 files changed

+137
-820
lines changed

11 files changed

+137
-820
lines changed

examples/annotation_import/conversational.ipynb

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,7 @@
310310
"project.setup_editor(ontology) # Connect your ontology and editor to your project"
311311
],
312312
"cell_type": "code",
313-
"outputs": [
314-
{
315-
"name": "stderr",
316-
"output_type": "stream",
317-
"text": [
318-
"WARNING:labelbox.client:Default createProject behavior will soon be adjusted to prefer batch projects. Pass in `queue_mode` parameter explicitly to opt-out for the time being.\n"
319-
]
320-
}
321-
],
313+
"outputs": [],
322314
"execution_count": null
323315
},
324316
{
@@ -336,29 +328,14 @@
336328
"# Create a batch to send to your MAL project\n",
337329
"batch = project.create_batch(\n",
338330
" \"first-batch-convo-demo\", # Each batch in a project must have a unique name\n",
339-
" global_keys=global_key, # Paginated collection of data row objects, list of data row ids or global keys\n",
331+
" global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
340332
" priority=5 # priority between 1(Highest) - 5(lowest)\n",
341333
")\n",
342334
"\n",
343335
"print(\"Batch: \", batch)"
344336
],
345337
"cell_type": "code",
346-
"outputs": [
347-
{
348-
"name": "stdout",
349-
"output_type": "stream",
350-
"text": [
351-
"Batch: <Batch {\n",
352-
" \"consensus_settings_json\": \"{\\\"numberOfLabels\\\":1,\\\"coveragePercentage\\\":0}\",\n",
353-
" \"created_at\": \"2022-12-23 20:20:51+00:00\",\n",
354-
" \"name\": \"first-batch-convo-demo\",\n",
355-
" \"size\": 1,\n",
356-
" \"uid\": \"4bceaa60-82ff-11ed-b68f-3b1759fe9ddf\",\n",
357-
" \"updated_at\": \"2022-12-23 20:20:51+00:00\"\n",
358-
"}>\n"
359-
]
360-
}
361-
],
338+
"outputs": [],
362339
"execution_count": null
363340
},
364341
{
@@ -428,16 +405,7 @@
428405
"print(\"Status of uploads: \", upload_job.statuses)"
429406
],
430407
"cell_type": "code",
431-
"outputs": [
432-
{
433-
"name": "stdout",
434-
"output_type": "stream",
435-
"text": [
436-
"Errors: []\n",
437-
" \n"
438-
]
439-
}
440-
],
408+
"outputs": [],
441409
"execution_count": null
442410
},
443411
{
@@ -463,15 +431,7 @@
463431
"print(\"Status of uploads: \", upload_job.statuses)"
464432
],
465433
"cell_type": "code",
466-
"outputs": [
467-
{
468-
"name": "stdout",
469-
"output_type": "stream",
470-
"text": [
471-
"Errors: []\n"
472-
]
473-
}
474-
],
434+
"outputs": [],
475435
"execution_count": null
476436
},
477437
{
@@ -484,7 +444,6 @@
484444
{
485445
"metadata": {},
486446
"source": [
487-
"#upload_job\n",
488447
"# project.delete()\n",
489448
"# dataset.delete()"
490449
],

examples/annotation_import/image.ipynb

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@
304304
"outputs": [],
305305
"execution_count": null
306306
},
307+
{
308+
"metadata": {},
309+
"source": [],
310+
"cell_type": "markdown"
311+
},
307312
{
308313
"metadata": {},
309314
"source": [
@@ -690,28 +695,13 @@
690695
"source": [
691696
"batch = project.create_batch(\n",
692697
" \"Initial batch2\", # name of the batch\n",
693-
" global_keys=global_key, # DataRow objects, a list of global keys or data row ids are supported\n",
698+
" global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
694699
" priority=1 # priority between 1-5\n",
695700
")\n",
696701
"print(\"Batch\", batch)"
697702
],
698703
"cell_type": "code",
699-
"outputs": [
700-
{
701-
"name": "stdout",
702-
"output_type": "stream",
703-
"text": [
704-
"Batch <Batch {\n",
705-
" \"consensus_settings_json\": \"{\\\"numberOfLabels\\\":1,\\\"coveragePercentage\\\":0}\",\n",
706-
" \"created_at\": \"2023-03-17 13:58:44+00:00\",\n",
707-
" \"name\": \"Initial batch2\",\n",
708-
" \"size\": 0,\n",
709-
" \"uid\": \"d4b46230-c4cb-11ed-8ef7-03b2e7ba4cb0\",\n",
710-
" \"updated_at\": \"2023-03-17 13:58:44+00:00\"\n",
711-
"}>\n"
712-
]
713-
}
714-
],
704+
"outputs": [],
715705
"execution_count": null
716706
},
717707
{
@@ -773,7 +763,7 @@
773763
{
774764
"metadata": {},
775765
"source": [
776-
"label_ndjson_method2 = []\n",
766+
"label_ndjson = []\n",
777767
"for annotation in [radio_annotation_ndjson, \n",
778768
" checklist_annotation_ndjson, \n",
779769
" text_annotation_ndjson,\n",
@@ -792,7 +782,7 @@
792782
" annotation.update({\n",
793783
" 'dataRow': {'globalKey':global_key},\n",
794784
" })\n",
795-
" label_ndjson_method2.append(annotation)\n"
785+
" label_ndjson.append(annotation)\n"
796786
],
797787
"cell_type": "code",
798788
"outputs": [],
@@ -821,23 +811,14 @@
821811
" client = client, \n",
822812
" project_id = project.uid, \n",
823813
" name=\"mal_job\"+str(uuid.uuid4()), \n",
824-
" predictions=label_ndjson_method2)\n",
814+
" predictions=label_ndjson)\n",
825815
"\n",
826816
"print(\"Errors:\", upload_job.errors)\n",
827817
"print(\"Status of uploads: \", upload_job.statuses)\n",
828818
"print(\" \")"
829819
],
830820
"cell_type": "code",
831-
"outputs": [
832-
{
833-
"name": "stdout",
834-
"output_type": "stream",
835-
"text": [
836-
"Errors: []\n",
837-
" \n"
838-
]
839-
}
840-
],
821+
"outputs": [],
841822
"execution_count": null
842823
},
843824
{
@@ -855,7 +836,7 @@
855836
" client = client, \n",
856837
" project_id = project.uid, \n",
857838
" name=\"label_import_job\"+str(uuid.uuid4()), \n",
858-
" labels=label_ndjson_method2)\n",
839+
" labels=label_ndjson)\n",
859840
"\n",
860841
"print(\"Errors:\", upload_job.errors)\n",
861842
"print(\"Status of uploads: \", upload_job.statuses)\n",

examples/annotation_import/pdf.ipynb

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
"metadata": {},
292292
"source": [
293293
"## Text layer url is required for uploading entity annotations\n",
294-
"global_key = \"0801.3483.pd\"\n",
294+
"global_key = \"0801.3483.pdf\"\n",
295295
"img_url = {\n",
296296
" \"row_data\": {\n",
297297
" \"pdf_url\": \"https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf\",\n",
@@ -431,23 +431,12 @@
431431
"source": [
432432
"project.create_batch(\n",
433433
" \"PDF_annotation_batch\", # Each batch in a project must have a unique name\n",
434-
" global_keys=global_key, # A list of data rows or data row ids\n",
434+
" global_keys=[global_key], # Paginated collection of data row objects, list of data row ids or global keys\n",
435435
" priority=5 # priority between 1(Highest) - 5(lowest)\n",
436436
")"
437437
],
438438
"cell_type": "code",
439-
"outputs": [
440-
{
441-
"data": {
442-
"text/plain": [
443-
"<Batch ID: e2152a50-c402-11ed-9933-959d2b6c8c3c>"
444-
]
445-
},
446-
"execution_count": 13,
447-
"metadata": {},
448-
"output_type": "execute_result"
449-
}
450-
],
439+
"outputs": [],
451440
"execution_count": null
452441
},
453442
{
@@ -522,16 +511,7 @@
522511
" "
523512
],
524513
"cell_type": "code",
525-
"outputs": [
526-
{
527-
"name": "stdout",
528-
"output_type": "stream",
529-
"text": [
530-
"entities_annotations_ndjson={'name': 'named_entity', 'textSelections': [{'groupId': '2f4336f4-a07e-4e0a-a9e1-5629b03b719b', 'tokenIds': ['3f984bf3-1d61-44f5-b59a-9658a2e3440f', '3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8', '6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80', '87a43d32-af76-4a1d-b262-5c5f4d5ace3a', 'e8606e8a-dfd9-4c49-a635-ad5c879c75d0', '67c7c19e-4654-425d-bf17-2adb8cf02c30', '149c5e80-3e07-49a7-ab2d-29ddfe6a38fa', 'b0e94071-2187-461e-8e76-96c58738a52c'], 'page': 1}]}\n",
531-
"entities_annotation=confidence=None name='named_entity' feature_schema_id=None extra={} value=DocumentEntity(text_selections=[DocumentTextSelection(token_ids=['3f984bf3-1d61-44f5-b59a-9658a2e3440f', '3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8', '6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80', '87a43d32-af76-4a1d-b262-5c5f4d5ace3a', 'e8606e8a-dfd9-4c49-a635-ad5c879c75d0', '67c7c19e-4654-425d-bf17-2adb8cf02c30', '149c5e80-3e07-49a7-ab2d-29ddfe6a38fa', 'b0e94071-2187-461e-8e76-96c58738a52c'], group_id='2f4336f4-a07e-4e0a-a9e1-5629b03b719b', page=1)]) classifications=[]\n"
532-
]
533-
}
534-
],
514+
"outputs": [],
535515
"execution_count": null
536516
},
537517
{
@@ -545,19 +525,20 @@
545525
{
546526
"metadata": {},
547527
"source": [
548-
"# create a Label\n",
528+
"\n",
549529
"\n",
550530
"labels = []\n",
551531
"\n",
552-
"labels.append(lb_types.Label(\n",
553-
" data=lb_types.DocumentData(\n",
554-
" global_key=global_key),\n",
555-
" annotations = [\n",
556-
" entities_annotation,\n",
557-
" checklist_annotation, \n",
558-
" text_annotation,\n",
559-
" radio_annotation\n",
560-
" ]\n",
532+
"labels.append(\n",
533+
" lb_types.Label(\n",
534+
" data=lb_types.DocumentData(\n",
535+
" global_key=global_key),\n",
536+
" annotations = [\n",
537+
" entities_annotation,\n",
538+
" checklist_annotation, \n",
539+
" text_annotation,\n",
540+
" radio_annotation\n",
541+
" ]\n",
561542
" )\n",
562543
")"
563544
],
@@ -577,7 +558,7 @@
577558
"metadata": {},
578559
"source": [
579560
"\n",
580-
"ndjson_annotation = []\n",
561+
"label_ndjson = []\n",
581562
"for annot in [\n",
582563
" entities_annotations_ndjson,\n",
583564
" bbox_annotation_ndjson,\n",
@@ -590,7 +571,7 @@
590571
" annot.update({\n",
591572
" 'dataRow': {'globalKey': global_key},\n",
592573
" })\n",
593-
" ndjson_annotation.append(annot)\n",
574+
" label_ndjson.append(annot)\n",
594575
"\n"
595576
],
596577
"cell_type": "code",
@@ -618,7 +599,7 @@
618599
" client = client,\n",
619600
" project_id = project.uid,\n",
620601
" name=\"pdf_annotation_upload\" + str(uuid.uuid4()),\n",
621-
" predictions=ndjson_annotation)\n",
602+
" predictions=label_ndjson)\n",
622603
"\n",
623604
"upload_job.wait_until_done()\n",
624605
"# Errors will appear for annotation uploads that failed.\n",
@@ -644,7 +625,7 @@
644625
" client = client, \n",
645626
" project_id = project.uid, \n",
646627
" name=\"label_import_job\"+str(uuid.uuid4()), \n",
647-
" labels=ndjson_annotation)\n",
628+
" labels=label_ndjson)\n",
648629
"\n",
649630
"print(\"Errors:\", upload_job.errors)\n",
650631
"print(\"Status of uploads: \", upload_job.statuses)"

0 commit comments

Comments
 (0)