Skip to content

Commit 1d27b92

Browse files
authored
Merge pull request #436 from Labelbox/al-677-colab-key
jtso/AL-677
2 parents ca01b32 + 650e749 commit 1d27b92

29 files changed

+3753
-963
lines changed

examples/annotation_types/basics.ipynb

Lines changed: 432 additions & 89 deletions
Large diffs are not rendered by default.

examples/annotation_types/converters.ipynb

Lines changed: 108 additions & 57 deletions
Large diffs are not rendered by default.

examples/annotation_types/label_containers.ipynb

Lines changed: 281 additions & 50 deletions
Large diffs are not rendered by default.

examples/annotation_types/mal_using_annotation_types.ipynb

Lines changed: 136 additions & 30 deletions
Large diffs are not rendered by default.

examples/basics/basics.ipynb

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,20 @@
6666
"id": "indie-bracket",
6767
"metadata": {},
6868
"outputs": [],
69-
"source": "!pip install labelbox"
69+
"source": [
70+
"!pip install labelbox"
71+
]
7072
},
7173
{
7274
"cell_type": "code",
7375
"execution_count": 2,
7476
"id": "everyday-street",
7577
"metadata": {},
7678
"outputs": [],
77-
"source": "from labelbox import Project, Dataset, Client\nfrom getpass import getpass\nimport os"
78-
},
79-
{
80-
"cell_type": "code",
81-
"execution_count": 3,
82-
"id": "crude-receiver",
83-
"metadata": {},
84-
"outputs": [],
85-
"source": "# If you don't want to give google access to drive you can skip this cell\n# and manually set `API_KEY` below.\n\nCOLAB = \"google.colab\" in str(get_ipython())\nif COLAB:\n !pip install colab-env -qU\n from colab_env import envvar_handler\n envvar_handler.envload()\n\nAPI_KEY = os.environ.get(\"LABELBOX_API_KEY\")\nif not os.environ.get(\"LABELBOX_API_KEY\"):\n API_KEY = getpass(\"Please enter your labelbox api key\")\n if COLAB:\n envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)"
79+
"source": [
80+
"from labelbox import Project, Dataset, Client\n",
81+
"import os"
82+
]
8683
},
8784
{
8885
"cell_type": "markdown",
@@ -109,7 +106,14 @@
109106
"id": "instructional-reply",
110107
"metadata": {},
111108
"outputs": [],
112-
"source": "PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"\nDATASET_ID = \"ckk4q1vjznyhu087203wlghfr\"\nPROJECT_NAME = \"Sample Project\"\nDATASET_NAME = \"Example Jellyfish Dataset\"\n# Only update this if you have an on-prem deployment\nENDPOINT = \"https://api.labelbox.com/graphql\""
109+
"source": [
110+
"PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"\n",
111+
"DATASET_ID = \"ckk4q1vjznyhu087203wlghfr\"\n",
112+
"PROJECT_NAME = \"Sample Project\"\n",
113+
"DATASET_NAME = \"Example Jellyfish Dataset\"\n",
114+
"# Only update this if you have an on-prem deployment\n",
115+
"ENDPOINT = \"https://api.labelbox.com/graphql\""
116+
]
113117
},
114118
{
115119
"cell_type": "markdown",
@@ -126,15 +130,23 @@
126130
"id": "thick-gasoline",
127131
"metadata": {},
128132
"outputs": [],
129-
"source": "client = Client(api_key=API_KEY, endpoint=ENDPOINT)"
133+
"source": [
134+
"# Add your api key\n",
135+
"API_KEY = None\n",
136+
"client = Client(api_key=API_KEY)"
137+
]
130138
},
131139
{
132140
"cell_type": "code",
133141
"execution_count": 6,
134142
"id": "victorian-consumer",
135143
"metadata": {},
136144
"outputs": [],
137-
"source": "#Client can be used to fetch by id:\nproject = client.get_project(PROJECT_ID)\ndataset = client.get_dataset(DATASET_ID)"
145+
"source": [
146+
"#Client can be used to fetch by id:\n",
147+
"project = client.get_project(PROJECT_ID)\n",
148+
"dataset = client.get_dataset(DATASET_ID)"
149+
]
138150
},
139151
{
140152
"cell_type": "code",
@@ -153,7 +165,9 @@
153165
"output_type": "execute_result"
154166
}
155167
],
156-
"source": "project"
168+
"source": [
169+
"project"
170+
]
157171
},
158172
{
159173
"cell_type": "markdown",
@@ -181,7 +195,11 @@
181195
]
182196
}
183197
],
184-
"source": "print(project.name)\nprint(project.description)\nprint(dataset.name)"
198+
"source": [
199+
"print(project.name)\n",
200+
"print(project.description)\n",
201+
"print(dataset.name)"
202+
]
185203
},
186204
{
187205
"cell_type": "markdown",
@@ -197,7 +215,10 @@
197215
"id": "according-subdivision",
198216
"metadata": {},
199217
"outputs": [],
200-
"source": "project.update(description=\"new description field\")\nprint(project.description)"
218+
"source": [
219+
"project.update(description=\"new description field\")\n",
220+
"print(project.description)"
221+
]
201222
},
202223
{
203224
"cell_type": "markdown",
@@ -226,15 +247,23 @@
226247
"output_type": "execute_result"
227248
}
228249
],
229-
"source": "labels_paginated_collection = project.labels()\nlabels_paginated_collection"
250+
"source": [
251+
"labels_paginated_collection = project.labels()\n",
252+
"labels_paginated_collection"
253+
]
230254
},
231255
{
232256
"cell_type": "code",
233257
"execution_count": 11,
234258
"id": "convinced-force",
235259
"metadata": {},
236260
"outputs": [],
237-
"source": "# Note that if you selected a `project_id` without any labels this will raise `StopIteration`\n# Iterate over them to get the items out.\nnext(labels_paginated_collection)\n# list(paginated...) should be avoided for queries that could return more than a dozen results"
261+
"source": [
262+
"# Note that if you selected a `project_id` without any labels this will raise `StopIteration`\n",
263+
"# Iterate over them to get the items out.\n",
264+
"next(labels_paginated_collection)\n",
265+
"# list(paginated...) should be avoided for queries that could return more than a dozen results"
266+
]
238267
},
239268
{
240269
"cell_type": "markdown",
@@ -263,7 +292,21 @@
263292
]
264293
}
265294
],
266-
"source": "datasets = client.get_datasets(where=Dataset.name == DATASET_NAME)\n\nprojects = client.get_projects(\n where=((Project.name == PROJECT_NAME) &\n (Project.description == \"new description field\")))\n\n# The above two queries return PaginatedCollections because the filter parameters aren't guaranteed to be unique.\n# So even if there is one element returned it is in a paginatedCollection.\nprint(projects)\nprint(next(projects, None))\nprint(next(projects, None))\nprint(next(projects, None))\n# We can see there is only one."
295+
"source": [
296+
"datasets = client.get_datasets(where=Dataset.name == DATASET_NAME)\n",
297+
"\n",
298+
"projects = client.get_projects(\n",
299+
" where=((Project.name == PROJECT_NAME) &\n",
300+
" (Project.description == \"new description field\")))\n",
301+
"\n",
302+
"# The above two queries return PaginatedCollections because the filter parameters aren't guaranteed to be unique.\n",
303+
"# So even if there is one element returned it is in a paginatedCollection.\n",
304+
"print(projects)\n",
305+
"print(next(projects, None))\n",
306+
"print(next(projects, None))\n",
307+
"print(next(projects, None))\n",
308+
"# We can see there is only one."
309+
]
267310
},
268311
{
269312
"cell_type": "markdown",
@@ -305,7 +348,11 @@
305348
"output_type": "execute_result"
306349
}
307350
],
308-
"source": "# Dataset has a Relationship to a Project so we can use the following\nlist(dataset.projects())\n# This will return all projects that are attached to this dataset"
351+
"source": [
352+
"# Dataset has a Relationship to a Project so we can use the following\n",
353+
"list(dataset.projects())\n",
354+
"# This will return all projects that are attached to this dataset"
355+
]
309356
},
310357
{
311358
"cell_type": "code",
@@ -324,7 +371,10 @@
324371
"output_type": "execute_result"
325372
}
326373
],
327-
"source": "sample_project_datasets = project.datasets()\nlist(sample_project_datasets)"
374+
"source": [
375+
"sample_project_datasets = project.datasets()\n",
376+
"list(sample_project_datasets)"
377+
]
328378
},
329379
{
330380
"cell_type": "markdown",
@@ -341,7 +391,12 @@
341391
"id": "persistent-briefs",
342392
"metadata": {},
343393
"outputs": [],
344-
"source": "#Eg.\n##### project.delete()\n##### dataset.delete()\n##### data_row.delete()"
394+
"source": [
395+
"#Eg.\n",
396+
"##### project.delete()\n",
397+
"##### dataset.delete()\n",
398+
"##### data_row.delete()"
399+
]
345400
},
346401
{
347402
"cell_type": "markdown",
@@ -351,14 +406,6 @@
351406
"* We reccomend using bulk operations where possible.\n",
352407
"* You can find specific deletion instructions in tutorials on each object."
353408
]
354-
},
355-
{
356-
"cell_type": "code",
357-
"execution_count": 16,
358-
"id": "thirty-interval",
359-
"metadata": {},
360-
"outputs": [],
361-
"source": ""
362409
}
363410
],
364411
"metadata": {
@@ -382,4 +429,4 @@
382429
},
383430
"nbformat": 4,
384431
"nbformat_minor": 5
385-
}
432+
}

0 commit comments

Comments
 (0)