|
75 | 75 | { |
76 | 76 | "metadata": {}, |
77 | 77 | "source": [ |
78 | | - "!pip install -q 'labelbox[data]'" |
| 78 | + "!pip install -q \"labelbox[data]\"" |
79 | 79 | ], |
80 | 80 | "cell_type": "code", |
81 | | - "outputs": [ |
82 | | - { |
83 | | - "name": "stdout", |
84 | | - "output_type": "stream", |
85 | | - "text": [ |
86 | | - "\n", |
87 | | - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.0.1\u001b[0m\n", |
88 | | - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" |
89 | | - ] |
90 | | - } |
91 | | - ], |
| 81 | + "outputs": [], |
92 | 82 | "execution_count": null |
93 | 83 | }, |
94 | 84 | { |
|
146 | 136 | ")\n", |
147 | 137 | "\n", |
148 | 138 | "text_annotation_ndjson = {\n", |
149 | | - " 'name': 'text_html',\n", |
150 | | - " 'answer': 'sample text',\n", |
| 139 | + " \"name\": \"text_html\",\n", |
| 140 | + " \"answer\": \"sample text\",\n", |
151 | 141 | "}" |
152 | 142 | ], |
153 | 143 | "cell_type": "code", |
|
160 | 150 | "##### Checklist Classification ####### \n", |
161 | 151 | "\n", |
162 | 152 | "checklist_annotation= lb_types.ClassificationAnnotation(\n", |
163 | | - " name=\"checklist_html\", # must match your ontology feature's name\n", |
| 153 | + " name=\"checklist_html\", # must match your ontology feature\"s name\n", |
164 | 154 | " value=lb_types.Checklist(\n", |
165 | 155 | " answer = [\n", |
166 | 156 | " lb_types.ClassificationAnswer(\n", |
|
175 | 165 | "\n", |
176 | 166 | "\n", |
177 | 167 | "checklist_annotation_ndjson = {\n", |
178 | | - " 'name': 'checklist_html',\n", |
179 | | - " 'answers': [\n", |
180 | | - " {'name': 'first_checklist_answer'},\n", |
181 | | - " {'name': 'second_checklist_answer'}\n", |
| 168 | + " \"name\": \"checklist_html\",\n", |
| 169 | + " \"answers\": [\n", |
| 170 | + " {\"name\": \"first_checklist_answer\"},\n", |
| 171 | + " {\"name\": \"second_checklist_answer\"}\n", |
182 | 172 | " ],\n", |
183 | 173 | "}" |
184 | 174 | ], |
|
197 | 187 | " name=\"second_radio_answer\")))\n", |
198 | 188 | "\n", |
199 | 189 | "radio_annotation_ndjson = {\n", |
200 | | - " 'name': 'radio_html',\n", |
201 | | - " 'answer': {\n", |
202 | | - " 'name': 'first_radio_answer'\n", |
| 190 | + " \"name\": \"radio_html\",\n", |
| 191 | + " \"answer\": {\n", |
| 192 | + " \"name\": \"first_radio_answer\"\n", |
203 | 193 | " },\n", |
204 | 194 | "}" |
205 | 195 | ], |
206 | 196 | "cell_type": "code", |
207 | 197 | "outputs": [], |
208 | 198 | "execution_count": null |
209 | 199 | }, |
| 200 | + { |
| 201 | + "metadata": {}, |
| 202 | + "source": [ |
| 203 | + "########## Classification - Radio and Checklist (with subclassifcations) ##########\n", |
| 204 | + "\n", |
| 205 | + "nested_radio_annotation = lb_types.ClassificationAnnotation(\n", |
| 206 | + " name=\"nested_radio_question\",\n", |
| 207 | + " value=lb_types.Radio(\n", |
| 208 | + " answer=lb_types.ClassificationAnswer(\n", |
| 209 | + " name=\"first_radio_answer\",\n", |
| 210 | + " classifications=[\n", |
| 211 | + " lb_types.ClassificationAnnotation(\n", |
| 212 | + " name=\"sub_radio_question\",\n", |
| 213 | + " value=lb_types.Radio(\n", |
| 214 | + " answer=lb_types.ClassificationAnswer(\n", |
| 215 | + " name=\"first_sub_radio_answer\")\n", |
| 216 | + " )\n", |
| 217 | + " )\n", |
| 218 | + " ]\n", |
| 219 | + " )\n", |
| 220 | + " )\n", |
| 221 | + ")\n", |
| 222 | + "\n", |
| 223 | + "nested_radio_annotation_ndjson= {\n", |
| 224 | + " \"name\": \"nested_radio_question\",\n", |
| 225 | + " \"answer\": {\n", |
| 226 | + " \"name\": \"first_radio_answer\",\n", |
| 227 | + " \"classifications\": [{\n", |
| 228 | + " \"name\":\"sub_radio_question\",\n", |
| 229 | + " \"answer\": { \"name\" : \"first_sub_radio_answer\"}\n", |
| 230 | + " \n", |
| 231 | + " }]\n", |
| 232 | + " }\n", |
| 233 | + "}\n", |
| 234 | + "\n", |
| 235 | + "nested_checklist_annotation = lb_types.ClassificationAnnotation(\n", |
| 236 | + " name=\"nested_checklist_question\",\n", |
| 237 | + " value=lb_types.Checklist(\n", |
| 238 | + " answer=[lb_types.ClassificationAnswer(\n", |
| 239 | + " name=\"first_checklist_answer\",\n", |
| 240 | + " classifications=[\n", |
| 241 | + " lb_types.ClassificationAnnotation(\n", |
| 242 | + " name=\"sub_checklist_question\",\n", |
| 243 | + " value=lb_types.Checklist(\n", |
| 244 | + " answer=[lb_types.ClassificationAnswer(\n", |
| 245 | + " name=\"first_sub_checklist_answer\")]\n", |
| 246 | + " ))\n", |
| 247 | + " ]\n", |
| 248 | + " )]\n", |
| 249 | + " )\n", |
| 250 | + ")\n", |
| 251 | + "\n", |
| 252 | + "nested_checklist_annotation_ndjson = {\n", |
| 253 | + " \"name\": \"nested_checklist_question\",\n", |
| 254 | + " \"answer\": [{\n", |
| 255 | + " \"name\": \"first_checklist_answer\", \n", |
| 256 | + " \"classifications\" : [\n", |
| 257 | + " {\n", |
| 258 | + " \"name\": \"sub_checklist_question\", \n", |
| 259 | + " \"answer\": {\"name\": \"first_sub_checklist_answer\"} \n", |
| 260 | + " \n", |
| 261 | + " } \n", |
| 262 | + " ] \n", |
| 263 | + " }]\n", |
| 264 | + "}" |
| 265 | + ], |
| 266 | + "cell_type": "code", |
| 267 | + "outputs": [], |
| 268 | + "execution_count": null |
| 269 | + }, |
210 | 270 | { |
211 | 271 | "metadata": {}, |
212 | 272 | "source": [ |
|
233 | 293 | " \"global_key\": global_key\n", |
234 | 294 | "}\n", |
235 | 295 | "\n", |
236 | | - "dataset = client.create_dataset(name=\"html_annotation_import_demo_dataset\")\n", |
| 296 | + "dataset = client.create_dataset(\n", |
| 297 | + " name=\"html_annotation_import_demo_dataset\", \n", |
| 298 | + " iam_integration=None # Removing this argument will default to the organziation's default iam integration\n", |
| 299 | + ") \n", |
237 | 300 | "task = dataset.create_data_rows([asset])\n", |
238 | 301 | "task.wait_till_done()\n", |
239 | 302 | "print(\"Errors:\", task.errors)\n", |
240 | 303 | "print(\"Failed data rows: \", task.failed_data_rows)" |
241 | 304 | ], |
242 | 305 | "cell_type": "code", |
243 | | - "outputs": [ |
244 | | - { |
245 | | - "name": "stdout", |
246 | | - "output_type": "stream", |
247 | | - "text": [ |
248 | | - "Errors: None\n", |
249 | | - "Failed data rows: None\n" |
250 | | - ] |
251 | | - } |
252 | | - ], |
| 306 | + "outputs": [], |
253 | 307 | "execution_count": null |
254 | 308 | }, |
255 | 309 | { |
|
286 | 340 | " lb.Option(value=\"first_radio_answer\"),\n", |
287 | 341 | " lb.Option(value=\"second_radio_answer\")\n", |
288 | 342 | " ]\n", |
| 343 | + " ),\n", |
| 344 | + " lb.Classification(\n", |
| 345 | + " class_type=lb.Classification.Type.CHECKLIST,\n", |
| 346 | + " name=\"nested_checklist_question\",\n", |
| 347 | + " options=[\n", |
| 348 | + " lb.Option(\"first_checklist_answer\",\n", |
| 349 | + " options=[\n", |
| 350 | + " lb.Classification(\n", |
| 351 | + " class_type=lb.Classification.Type.CHECKLIST,\n", |
| 352 | + " name=\"sub_checklist_question\", \n", |
| 353 | + " options=[lb.Option(\"first_sub_checklist_answer\")]\n", |
| 354 | + " )\n", |
| 355 | + " ]\n", |
| 356 | + " )\n", |
| 357 | + " ]\n", |
| 358 | + " ),\n", |
| 359 | + " lb.Classification(\n", |
| 360 | + " class_type=lb.Classification.Type.RADIO,\n", |
| 361 | + " name=\"nested_radio_question\", \n", |
| 362 | + " options=[\n", |
| 363 | + " lb.Option(value=\"first_radio_answer\",\n", |
| 364 | + " options=[\n", |
| 365 | + " lb.Classification(\n", |
| 366 | + " class_type=lb.Classification.Type.RADIO,\n", |
| 367 | + " name=\"sub_radio_question\",\n", |
| 368 | + " options=[\n", |
| 369 | + " lb.Option(value=\"first_sub_radio_answer\")\n", |
| 370 | + " ]\n", |
| 371 | + " ),\n", |
| 372 | + " ]\n", |
| 373 | + " )\n", |
| 374 | + " ],\n", |
289 | 375 | " )\n", |
290 | 376 | " ]\n", |
291 | 377 | ")\n", |
|
309 | 395 | "metadata": {}, |
310 | 396 | "source": [ |
311 | 397 | "# Create Labelbox project\n", |
312 | | - "project = client.create_project(name=\"html_project\", \n", |
| 398 | + "project = client.create_project(name=\"HTML Import Annotation Demo\", \n", |
313 | 399 | " media_type=lb.MediaType.Html)\n", |
314 | 400 | "\n", |
315 | 401 | "# Setup your ontology \n", |
316 | 402 | "project.setup_editor(ontology) # Connect your ontology and editor to your project" |
317 | 403 | ], |
318 | 404 | "cell_type": "code", |
319 | | - "outputs": [ |
320 | | - { |
321 | | - "name": "stderr", |
322 | | - "output_type": "stream", |
323 | | - "text": [ |
324 | | - "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" |
325 | | - ] |
326 | | - } |
327 | | - ], |
| 405 | + "outputs": [], |
328 | 406 | "execution_count": null |
329 | 407 | }, |
330 | 408 | { |
|
349 | 427 | "print(\"Batch: \", batch)" |
350 | 428 | ], |
351 | 429 | "cell_type": "code", |
352 | | - "outputs": [ |
353 | | - { |
354 | | - "name": "stdout", |
355 | | - "output_type": "stream", |
356 | | - "text": [ |
357 | | - "Batch: <Batch {\n", |
358 | | - " \"consensus_settings_json\": \"{\\\"numberOfLabels\\\":1,\\\"coveragePercentage\\\":0}\",\n", |
359 | | - " \"created_at\": \"2023-03-28 18:31:16+00:00\",\n", |
360 | | - " \"name\": \"first-batch-html-demo\",\n", |
361 | | - " \"size\": 0,\n", |
362 | | - " \"uid\": \"b9c6dec0-cd96-11ed-a79b-bd72128661a2\",\n", |
363 | | - " \"updated_at\": \"2023-03-28 18:31:16+00:00\"\n", |
364 | | - "}>\n" |
365 | | - ] |
366 | | - } |
367 | | - ], |
| 430 | + "outputs": [], |
368 | 431 | "execution_count": null |
369 | 432 | }, |
370 | 433 | { |
|
397 | 460 | " annotations=[\n", |
398 | 461 | " text_annotation,\n", |
399 | 462 | " checklist_annotation,\n", |
400 | | - " radio_annotation\n", |
| 463 | + " radio_annotation,\n", |
| 464 | + " nested_checklist_annotation,\n", |
| 465 | + " nested_radio_annotation\n", |
401 | 466 | " ]\n", |
402 | 467 | " )\n", |
403 | 468 | ")" |
|
420 | 485 | "label_ndjson = []\n", |
421 | 486 | "for annotations in [text_annotation_ndjson,\n", |
422 | 487 | " checklist_annotation_ndjson,\n", |
423 | | - " radio_annotation_ndjson]:\n", |
| 488 | + " radio_annotation_ndjson,\n", |
| 489 | + " nested_radio_annotation_ndjson,\n", |
| 490 | + " nested_checklist_annotation_ndjson\n", |
| 491 | + " ]:\n", |
424 | 492 | " annotations.update({\n", |
425 | | - " 'dataRow': {\n", |
426 | | - " 'globalKey': global_key\n", |
| 493 | + " \"dataRow\": {\n", |
| 494 | + " \"globalKey\": global_key\n", |
427 | 495 | " }\n", |
428 | 496 | " })\n", |
429 | 497 | " label_ndjson.append(annotations)" |
|
462 | 530 | "print(\"Status of uploads: \", upload_job.statuses)" |
463 | 531 | ], |
464 | 532 | "cell_type": "code", |
465 | | - "outputs": [ |
466 | | - { |
467 | | - "name": "stdout", |
468 | | - "output_type": "stream", |
469 | | - "text": [ |
470 | | - "Errors: []\n", |
471 | | - "Status of uploads: [{'uuid': 'cd188c7e-167f-48ce-98e6-571f255ba319', 'dataRow': {'id': 'clfslgefk0um4079rfyajcf18', 'globalKey': 'sample_html_1.html'}, 'status': 'SUCCESS'}, {'uuid': '3153214d-831c-4aa4-bf95-280d657cfe51', 'dataRow': {'id': 'clfslgefk0um4079rfyajcf18', 'globalKey': 'sample_html_1.html'}, 'status': 'SUCCESS'}, {'uuid': '297a9f08-30b4-427f-b8f0-d1139709b97d', 'dataRow': {'id': 'clfslgefk0um4079rfyajcf18', 'globalKey': 'sample_html_1.html'}, 'status': 'SUCCESS'}]\n" |
472 | | - ] |
473 | | - } |
474 | | - ], |
| 533 | + "outputs": [], |
475 | 534 | "execution_count": null |
476 | 535 | }, |
477 | 536 | { |
|
496 | 555 | "print(\"Status of uploads: \", upload_job.statuses)" |
497 | 556 | ], |
498 | 557 | "cell_type": "code", |
499 | | - "outputs": [ |
500 | | - { |
501 | | - "name": "stdout", |
502 | | - "output_type": "stream", |
503 | | - "text": [ |
504 | | - "Errors: []\n", |
505 | | - "Status of uploads: [{'uuid': 'f1c3e6b6-1e7e-41ca-abd5-a0fd919082a6', 'dataRow': {'id': 'clfslgefk0um4079rfyajcf18', 'globalKey': 'sample_html_1.html'}, 'status': 'SUCCESS'}, {'uuid': '44714fd1-e8a8-4da4-aea9-b71392ac78a4', 'dataRow': {'id': 'clfslgefk0um4079rfyajcf18', 'globalKey': 'sample_html_1.html'}, 'status': 'SUCCESS'}, {'uuid': '9d520664-9565-46e7-8b0b-c0615158d004', 'dataRow': {'id': 'clfslgefk0um4079rfyajcf18', 'globalKey': 'sample_html_1.html'}, 'status': 'SUCCESS'}]\n" |
506 | | - ] |
507 | | - } |
508 | | - ], |
| 558 | + "outputs": [], |
509 | 559 | "execution_count": null |
510 | 560 | }, |
511 | 561 | { |
|
0 commit comments