|
1 | 1 | { |
2 | 2 | "cells": [ |
3 | | - { |
4 | | - "cell_type": "markdown", |
5 | | - "id": "db768cda", |
6 | | - "metadata": {}, |
7 | | - "source": [ |
8 | | - "<td>\n", |
9 | | - " <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n", |
10 | | - "</td>" |
11 | | - ] |
12 | | - }, |
13 | | - { |
14 | | - "cell_type": "markdown", |
15 | | - "id": "cb5611d0", |
16 | | - "metadata": {}, |
17 | | - "source": [ |
18 | | - "<td>\n", |
19 | | - "<a href=\"https://colab.research.google.com/github/Labelbox/labelbox-python/blob/develop/examples/project_configuration/webhooks.ipynb\" target=\"_blank\"><img\n", |
20 | | - "src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>\n", |
21 | | - "</td>\n", |
22 | | - "\n", |
23 | | - "<td>\n", |
24 | | - "<a href=\"https://github.com/Labelbox/labelbox-python/tree/develop/examples/project_configuration/webhooks.ipynb\" target=\"_blank\"><img\n", |
25 | | - "src=\"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\"GitHub\"></a>\n", |
26 | | - "</td>" |
27 | | - ] |
28 | | - }, |
29 | 3 | { |
30 | 4 | "cell_type": "markdown", |
31 | 5 | "id": "registered-pressure", |
|
44 | 18 | " 2. label_updated\n", |
45 | 19 | " 3. label_deleted\n", |
46 | 20 | " 4. review_created\n", |
47 | | - " 5. review_updated\n", |
48 | | - " 6. review_deleted" |
| 21 | + " 5. review_updated" |
49 | 22 | ] |
50 | 23 | }, |
51 | 24 | { |
|
55 | 28 | "metadata": {}, |
56 | 29 | "outputs": [], |
57 | 30 | "source": [ |
58 | | - "!pip install -q labelbox hmac hashlib flask Werkzeug" |
| 31 | + "!pip install labelbox\n", |
| 32 | + "!pip install requests\n", |
| 33 | + "!pip install hmac\n", |
| 34 | + "!pip install hashlib\n", |
| 35 | + "!pip install flask\n", |
| 36 | + "!pip install Werkzeug" |
59 | 37 | ] |
60 | 38 | }, |
61 | 39 | { |
62 | 40 | "cell_type": "code", |
63 | | - "execution_count": 2, |
| 41 | + "execution_count": null, |
64 | 42 | "id": "responsible-clinton", |
65 | 43 | "metadata": {}, |
66 | 44 | "outputs": [], |
|
74 | 52 | "import json\n", |
75 | 53 | "import requests\n", |
76 | 54 | "import os\n", |
| 55 | + "from getpass import getpass\n", |
77 | 56 | "import socket" |
78 | 57 | ] |
79 | 58 | }, |
80 | 59 | { |
81 | 60 | "cell_type": "code", |
82 | | - "execution_count": 4, |
83 | | - "id": "satellite-impossible", |
| 61 | + "execution_count": null, |
| 62 | + "id": "foreign-theorem", |
84 | 63 | "metadata": {}, |
85 | 64 | "outputs": [], |
86 | 65 | "source": [ |
87 | | - "# Set this to a project that you want to use for the webhook\n", |
88 | | - "PROJECT_ID = \"ckm4xyfncfgja0760vpfdxoro\"" |
| 66 | + "# If you don't want to give google access to drive you can skip this cell\n", |
| 67 | + "# and manually set `API_KEY` below.\n", |
| 68 | + "\n", |
| 69 | + "COLAB = \"google.colab\" in str(get_ipython())\n", |
| 70 | + "if COLAB:\n", |
| 71 | + " !pip install colab-env -qU\n", |
| 72 | + " from colab_env import envvar_handler\n", |
| 73 | + "\n", |
| 74 | + " envvar_handler.envload()\n", |
| 75 | + "\n", |
| 76 | + "API_KEY = os.environ.get(\"LABELBOX_API_KEY\")\n", |
| 77 | + "if not os.environ.get(\"LABELBOX_API_KEY\"):\n", |
| 78 | + " API_KEY = getpass(\"Please enter your labelbox api key\")\n", |
| 79 | + " if COLAB:\n", |
| 80 | + " envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)" |
89 | 81 | ] |
90 | 82 | }, |
91 | 83 | { |
92 | | - "cell_type": "markdown", |
93 | | - "id": "170cae56", |
| 84 | + "cell_type": "code", |
| 85 | + "execution_count": null, |
| 86 | + "id": "satellite-impossible", |
94 | 87 | "metadata": {}, |
| 88 | + "outputs": [], |
95 | 89 | "source": [ |
96 | | - "# API Key and Client\n", |
97 | | - "Provide a valid api key below in order to properly connect to the Labelbox Client." |
| 90 | + "# Set this to a project that you want to use for the webhook\n", |
| 91 | + "PROJECT_ID = \"\"\n", |
| 92 | + "# Only update this if you have an on-prem deployment\n", |
| 93 | + "ENDPOINT = \"https://api.labelbox.com/graphql\"" |
98 | 94 | ] |
99 | 95 | }, |
100 | 96 | { |
101 | 97 | "cell_type": "code", |
102 | | - "execution_count": 5, |
| 98 | + "execution_count": null, |
103 | 99 | "id": "clean-ireland", |
104 | 100 | "metadata": {}, |
105 | 101 | "outputs": [], |
106 | 102 | "source": [ |
107 | | - "# Add your api key\n", |
108 | | - "API_KEY = None\n", |
109 | | - "client = Client(api_key=API_KEY)" |
| 103 | + "client = Client(api_key=API_KEY, endpoint=ENDPOINT)" |
110 | 104 | ] |
111 | 105 | }, |
112 | 106 | { |
113 | 107 | "cell_type": "code", |
114 | | - "execution_count": 6, |
| 108 | + "execution_count": null, |
115 | 109 | "id": "bacterial-cheat", |
116 | 110 | "metadata": {}, |
117 | 111 | "outputs": [], |
|
138 | 132 | }, |
139 | 133 | { |
140 | 134 | "cell_type": "code", |
141 | | - "execution_count": 7, |
| 135 | + "execution_count": null, |
142 | 136 | "id": "aboriginal-antibody", |
143 | 137 | "metadata": {}, |
144 | | - "outputs": [ |
145 | | - { |
146 | | - "data": { |
147 | | - "text/plain": [ |
148 | | - "0" |
149 | | - ] |
150 | | - }, |
151 | | - "execution_count": 6, |
152 | | - "metadata": {}, |
153 | | - "output_type": "execute_result" |
154 | | - } |
155 | | - ], |
| 138 | + "outputs": [], |
156 | 139 | "source": [ |
157 | 140 | "if not COLAB:\n", |
158 | 141 | " os.system(f\"ngrok http {WH_PORT} &\")" |
|
168 | 151 | }, |
169 | 152 | { |
170 | 153 | "cell_type": "code", |
171 | | - "execution_count": 8, |
| 154 | + "execution_count": null, |
172 | 155 | "id": "stable-group", |
173 | 156 | "metadata": {}, |
174 | 157 | "outputs": [], |
|
179 | 162 | }, |
180 | 163 | { |
181 | 164 | "cell_type": "code", |
182 | | - "execution_count": 9, |
| 165 | + "execution_count": null, |
183 | 166 | "id": "limiting-variety", |
184 | 167 | "metadata": {}, |
185 | 168 | "outputs": [], |
|
225 | 208 | }, |
226 | 209 | { |
227 | 210 | "cell_type": "code", |
228 | | - "execution_count": 10, |
| 211 | + "execution_count": null, |
229 | 212 | "id": "delayed-convention", |
230 | 213 | "metadata": {}, |
231 | | - "outputs": [ |
232 | | - { |
233 | | - "name": "stderr", |
234 | | - "output_type": "stream", |
235 | | - "text": [ |
236 | | - " * Running on http://0.0.0.0:3001/ (Press CTRL+C to quit)\n", |
237 | | - "127.0.0.1 - - [29/Mar/2021 16:54:32] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n" |
238 | | - ] |
239 | | - }, |
240 | | - { |
241 | | - "name": "stdout", |
242 | | - "output_type": "stream", |
243 | | - "text": [ |
244 | | - "Hello, World!\n" |
245 | | - ] |
246 | | - } |
247 | | - ], |
| 214 | + "outputs": [], |
248 | 215 | "source": [ |
249 | 216 | "print(requests.get(\"http://localhost:3001\").text)" |
250 | 217 | ] |
|
268 | 235 | }, |
269 | 236 | { |
270 | 237 | "cell_type": "code", |
271 | | - "execution_count": 11, |
| 238 | + "execution_count": null, |
272 | 239 | "id": "biblical-scottish", |
273 | 240 | "metadata": {}, |
274 | 241 | "outputs": [], |
|
290 | 257 | }, |
291 | 258 | { |
292 | 259 | "cell_type": "code", |
293 | | - "execution_count": 12, |
| 260 | + "execution_count": null, |
294 | 261 | "id": "raising-preservation", |
295 | 262 | "metadata": {}, |
296 | 263 | "outputs": [], |
|
307 | 274 | }, |
308 | 275 | { |
309 | 276 | "cell_type": "code", |
310 | | - "execution_count": 13, |
| 277 | + "execution_count": null, |
311 | 278 | "id": "approximate-gothic", |
312 | 279 | "metadata": {}, |
313 | | - "outputs": [ |
314 | | - { |
315 | | - "name": "stdout", |
316 | | - "output_type": "stream", |
317 | | - "text": [ |
318 | | - "https://app.labelbox.com/projects/ckm4xyfncfgja0760vpfdxoro\n" |
319 | | - ] |
320 | | - } |
321 | | - ], |
| 280 | + "outputs": [], |
322 | 281 | "source": [ |
323 | 282 | "# Ok so we should be configured assuming everything is setup correctly.\n", |
324 | 283 | "# Go to the following url and make a new label to see if it works\n", |
|
327 | 286 | }, |
328 | 287 | { |
329 | 288 | "cell_type": "code", |
330 | | - "execution_count": 14, |
| 289 | + "execution_count": null, |
331 | 290 | "id": "worst-material", |
332 | 291 | "metadata": {}, |
333 | 292 | "outputs": [], |
|
345 | 304 | }, |
346 | 305 | { |
347 | 306 | "cell_type": "code", |
348 | | - "execution_count": 15, |
| 307 | + "execution_count": null, |
349 | 308 | "id": "stopped-steel", |
350 | 309 | "metadata": {}, |
351 | | - "outputs": [ |
352 | | - { |
353 | | - "name": "stdout", |
354 | | - "output_type": "stream", |
355 | | - "text": [ |
356 | | - "https://eb3e7f8eb089.ngrok.io/webhook-endpoint\n" |
357 | | - ] |
358 | | - }, |
359 | | - { |
360 | | - "name": "stderr", |
361 | | - "output_type": "stream", |
362 | | - "text": [ |
363 | | - "127.0.0.1 - - [17/Mar/2021 09:52:00] \"\u001b[37mPOST /webhook-endpoint HTTP/1.1\u001b[0m\" 200 -\n" |
364 | | - ] |
365 | | - }, |
366 | | - { |
367 | | - "name": "stdout", |
368 | | - "output_type": "stream", |
369 | | - "text": [ |
370 | | - "=========== New Webhook Delivery ============\n", |
371 | | - "Delivery ID: ckmdi74ew57lq063553kuzekq\n", |
372 | | - "Event: LABEL_UPDATED\n", |
373 | | - "Payload: {\n", |
374 | | - " \"id\": \"ckmb8h50t008f3h683tugqsap\",\n", |
375 | | - " \"createdAt\": \"2021-03-15T23:44:18Z\",\n", |
376 | | - " \"updatedAt\": \"2021-03-17T13:51:59Z\",\n", |
377 | | - " \"secondsToLabel\": 79.173,\n", |
378 | | - " \"label\": \"{\\\"objects\\\":[{\\\"featureId\\\":\\\"ckmb8gvd9008b3h68l5tcmrt1\\\",\\\"schemaId\\\":\\\"ckm3se1a5010y0y6rcdc0bvvl\\\",\\\"title\\\":\\\"animal\\\",\\\"value\\\":\\\"animal\\\",\\\"color\\\":\\\"#1CE6FF\\\",\\\"bbox\\\":{\\\"top\\\":325,\\\"left\\\":233,\\\"height\\\":266,\\\"width\\\":413},\\\"instanceURI\\\":\\\"https://api.labelbox.com/masks/feature/ckmb8gvd9008b3h68l5tcmrt1\\\"},{\\\"featureId\\\":\\\"ckmbdp94300013h68y14zluto\\\",\\\"schemaId\\\":\\\"ckmbdol5s1ybk0y96fje86ktu\\\",\\\"title\\\":\\\"human\\\",\\\"value\\\":\\\"human\\\",\\\"color\\\":\\\"#FF34FF\\\",\\\"bbox\\\":{\\\"top\\\":75,\\\"left\\\":527,\\\"height\\\":453,\\\"width\\\":155},\\\"instanceURI\\\":\\\"https://api.labelbox.com/masks/feature/ckmbdp94300013h68y14zluto\\\"},{\\\"featureId\\\":\\\"ckmbdpdda00043h688pqrsoku\\\",\\\"schemaId\\\":\\\"ckmbdol5s1ybk0y96fje86ktu\\\",\\\"title\\\":\\\"human\\\",\\\"value\\\":\\\"human\\\",\\\"color\\\":\\\"#FF34FF\\\",\\\"bbox\\\":{\\\"top\\\":81,\\\"left\\\":666,\\\"height\\\":396,\\\"width\\\":134},\\\"instanceURI\\\":\\\"https://api.labelbox.com/masks/feature/ckmbdpdda00043h688pqrsoku\\\"},{\\\"featureId\\\":\\\"ckmbdpgd200073h68cu3vhjf2\\\",\\\"schemaId\\\":\\\"ckmbdol5s1ybk0y96fje86ktu\\\",\\\"title\\\":\\\"human\\\",\\\"value\\\":\\\"human\\\",\\\"color\\\":\\\"#FF34FF\\\",\\\"bbox\\\":{\\\"top\\\":0,\\\"left\\\":722,\\\"height\\\":535,\\\"width\\\":259},\\\"instanceURI\\\":\\\"https://api.labelbox.com/masks/feature/ckmbdpgd200073h68cu3vhjf2\\\"},{\\\"featureId\\\":\\\"ckmdi72l700043g68i52bq31i\\\",\\\"schemaId\\\":\\\"ckm3se1a5010y0y6rcdc0bvvl\\\",\\\"title\\\":\\\"animal\\\",\\\"value\\\":\\\"animal\\\",\\\"color\\\":\\\"#1CE6FF\\\",\\\"bbox\\\":{\\\"top\\\":94,\\\"left\\\":65,\\\"height\\\":104,\\\"width\\\":67},\\\"instanceURI\\\":\\\"https://api.labelbox.com/masks/feature/ckmdi72l700043g68i52bq31i\\\"}],\\\"classifications\\\":[{\\\"featureId\\\":\\\"ckmb8h0t7008e3h68hhmuf3y4\\\",\\\"schemaId\\\":\\\"ckm3se1a4010w0y6rd579gyl3\\\",\\\"title\\\":\\\"image\\\",\\\"value\\\":\\\"image\\\",\\\"answers\\\":[{\\\"featureId\\\":\\\"ckmb8h0t6008d3h689yq6cnm6\\\",\\\"schemaId\\\":\\\"ckm3se1aw01120y6r7zkcd93v\\\",\\\"title\\\":\\\"contains_human\\\",\\\"value\\\":\\\"contains_human\\\"}]}]}\",\n", |
379 | | - " \"agreement\": null,\n", |
380 | | - " \"benchmarkAgreement\": null,\n", |
381 | | - " \"deleted\": false,\n", |
382 | | - " \"project\": {\n", |
383 | | - " \"id\": \"ckm4xyfncfgja0760vpfdxoro\",\n", |
384 | | - " \"createdAt\": \"2021-03-11T14:03:12Z\",\n", |
385 | | - " \"updatedAt\": \"2021-03-11T18:22:08.523Z\",\n", |
386 | | - " \"name\": \"animal_demo_proj\",\n", |
387 | | - " \"description\": \"\",\n", |
388 | | - " \"deleted\": false\n", |
389 | | - " },\n", |
390 | | - " \"dataRow\": {\n", |
391 | | - " \"id\": \"ckm4y6s5a1s7e0rb6bgf00oqa\",\n", |
392 | | - " \"createdAt\": \"2021-03-11T14:09:41Z\",\n", |
393 | | - " \"updatedAt\": \"2021-03-11T14:09:41Z\",\n", |
394 | | - " \"deletedAt\": null,\n", |
395 | | - " \"externalId\": \"uploaded_images/177.jpg\",\n", |
396 | | - " \"rowData\": \"https://storage.labelbox.com/ckk4q1vgapsau07324awnsjq2%2F7b7f4198-3ea4-68db-9bf7-01dfd0bf3e8c-177.jpg?Expires=1617198719&KeyName=labelbox-assets-key-1&Signature=9mjtUoc61rooqsI8I2unQNU4N-o=\"\n", |
397 | | - " },\n", |
398 | | - " \"dataset\": {\n", |
399 | | - " \"id\": \"ckm4xyfua04cf0z7a3wz58kgj\",\n", |
400 | | - " \"createdAt\": \"2021-03-11T14:03:12Z\",\n", |
401 | | - " \"updatedAt\": \"2021-03-11T14:03:12Z\",\n", |
402 | | - " \"name\": \"animal_demo_ds\",\n", |
403 | | - " \"description\": \"\",\n", |
404 | | - " \"deleted\": false\n", |
405 | | - " },\n", |
406 | | - " \"user\": {\n", |
407 | | - " \"id\": \"ckm570mgm7q880795an0rfzmz\",\n", |
408 | | - " \"email\": \"amanda+1@labelbox.com\"\n", |
409 | | - " }\n", |
410 | | - "}\n" |
411 | | - ] |
412 | | - } |
413 | | - ], |
| 310 | + "outputs": [], |
414 | 311 | "source": [ |
415 | 312 | "# url, topics, and status can all be updated\n", |
416 | 313 | "updated_url = f\"{public_url}/webhook-endpoint\"\n", |
|
431 | 328 | }, |
432 | 329 | { |
433 | 330 | "cell_type": "code", |
434 | | - "execution_count": 16, |
| 331 | + "execution_count": null, |
435 | 332 | "id": "distant-commitment", |
436 | 333 | "metadata": {}, |
437 | 334 | "outputs": [], |
|
468 | 365 | "name": "python", |
469 | 366 | "nbconvert_exporter": "python", |
470 | 367 | "pygments_lexer": "ipython3", |
471 | | - "version": "3.9.2" |
| 368 | + "version": "3.8.2" |
472 | 369 | } |
473 | 370 | }, |
474 | 371 | "nbformat": 4, |
|
0 commit comments