Skip to content

Commit 88d8f61

Browse files
authored
[SN-100] Update notebook for Project move_data_rows_to_task_queue (#1343)
1 parent b38a910 commit 88d8f61

File tree

1 file changed

+129
-5
lines changed

1 file changed

+129
-5
lines changed

examples/basics/projects.ipynb

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{
4949
"metadata": {},
5050
"source": [
51-
"!pip install labelbox -q"
51+
"!pip install -q \"labelbox[data]\""
5252
],
5353
"cell_type": "code",
5454
"outputs": [],
@@ -58,7 +58,7 @@
5858
"metadata": {},
5959
"source": [
6060
"import labelbox as lb\n",
61-
"import os\n",
61+
"import labelbox.types as lb_types\n",
6262
"import uuid"
6363
],
6464
"cell_type": "code",
@@ -76,8 +76,9 @@
7676
{
7777
"metadata": {},
7878
"source": [
79-
"# Add your api key\n",
79+
"# Add your API key\n",
8080
"API_KEY = \"\"\n",
81+
"# To get your API key go to: Workspace settings -> API -> Create API Key\n",
8182
"client = lb.Client(api_key=API_KEY)"
8283
],
8384
"cell_type": "code",
@@ -154,6 +155,127 @@
154155
"outputs": [],
155156
"execution_count": null
156157
},
158+
{
159+
"metadata": {},
160+
"source": [
161+
"### Attach ontology and label data rows\n",
162+
"\n",
163+
"In this section, we are creating an ontology to attach to a project and creating labels to import as ground truths. We need this setup to demonstrate other methods later in the demo. For more information, please reference our [Ontology](https://docs.labelbox.com/reference/ontology) and [Import Image Annotation](https://docs.labelbox.com/reference/import-image-annotations) development guides."
164+
],
165+
"cell_type": "markdown"
166+
},
167+
{
168+
"metadata": {},
169+
"source": [
170+
"Create your ontology"
171+
],
172+
"cell_type": "markdown"
173+
},
174+
{
175+
"metadata": {},
176+
"source": [
177+
"# Create normalized json with a radio classification\n",
178+
"ontology_builder = lb.OntologyBuilder(classifications=[ # List of Classification objects\n",
179+
" lb.Classification(class_type=lb.Classification.Type.RADIO,\n",
180+
" name=\"radio_question\",\n",
181+
" options=[\n",
182+
" lb.Option(value=\"first_radio_answer\"),\n",
183+
" lb.Option(value=\"second_radio_answer\")\n",
184+
" ]),\n",
185+
"])\n",
186+
"# Creating an ontology\n",
187+
"ontology = client.create_ontology(\"test-ontology\",\n",
188+
" ontology_builder.asdict())"
189+
],
190+
"cell_type": "code",
191+
"outputs": [],
192+
"execution_count": null
193+
},
194+
{
195+
"metadata": {},
196+
"source": [
197+
"Attach ontology to project"
198+
],
199+
"cell_type": "markdown"
200+
},
201+
{
202+
"metadata": {},
203+
"source": [
204+
"\n",
205+
"project.setup_editor(ontology)"
206+
],
207+
"cell_type": "code",
208+
"outputs": [],
209+
"execution_count": null
210+
},
211+
{
212+
"metadata": {},
213+
"source": [
214+
"Create labels and upload them to project as ground truths"
215+
],
216+
"cell_type": "markdown"
217+
},
218+
{
219+
"metadata": {},
220+
"source": [
221+
"# Create labels\n",
222+
"labels = []\n",
223+
"for global_key in global_keys:\n",
224+
" labels.append(lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n",
225+
" annotations=[\n",
226+
" # Create radio classification annotation for labels\n",
227+
" lb_types.ClassificationAnnotation(\n",
228+
" name=\"radio_question\",\n",
229+
" value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n",
230+
" name=\"second_radio_answer\")))\n",
231+
" ]))\n",
232+
"\n",
233+
"# Upload labels for the data rows in project\n",
234+
"upload_job = lb.LabelImport.create_from_objects(\n",
235+
" client = client,\n",
236+
" project_id = project.uid,\n",
237+
" name=\"label_import_job\"+str(uuid.uuid4()),\n",
238+
" labels=labels)\n",
239+
"\n",
240+
"upload_job.wait_until_done()\n",
241+
"\n",
242+
"print(f\"Errors: {upload_job.errors}\")"
243+
],
244+
"cell_type": "code",
245+
"outputs": [],
246+
"execution_count": null
247+
},
248+
{
249+
"metadata": {},
250+
"source": [
251+
"### Move data rows in project to different task queues"
252+
],
253+
"cell_type": "markdown"
254+
},
255+
{
256+
"metadata": {},
257+
"source": [
258+
"# Get list of task queues for project\n",
259+
"task_queues = project.task_queues()\n",
260+
"\n",
261+
"for task_queue in task_queues:\n",
262+
" print(task_queue)"
263+
],
264+
"cell_type": "code",
265+
"outputs": [],
266+
"execution_count": null
267+
},
268+
{
269+
"metadata": {},
270+
"source": [
271+
"project.move_data_rows_to_task_queue(data_row_ids=lb.GlobalKeys(global_keys), #Provide a list of global keys\n",
272+
" task_queue_id=task_queues[2].uid #Passing None moves data rows to \"Done\" task queue\n",
273+
")"
274+
],
275+
"cell_type": "code",
276+
"outputs": [],
277+
"execution_count": null
278+
},
157279
{
158280
"metadata": {},
159281
"source": [
@@ -180,14 +302,16 @@
180302
{
181303
"metadata": {},
182304
"source": [
183-
"### Delete"
305+
"### Clean Up"
184306
],
185307
"cell_type": "markdown"
186308
},
187309
{
188310
"metadata": {},
189311
"source": [
190-
"# project.delete()"
312+
"# project.delete()\n",
313+
"# dataset.delete()\n",
314+
"# client.delete_unused_ontology(ontology.uid)"
191315
],
192316
"cell_type": "code",
193317
"outputs": [],

0 commit comments

Comments
 (0)