4141 "id" : " manual-parks" ,
4242 "metadata" : {},
4343 "outputs" : [],
44- "source" : " !pip install labelbox\n !pip install requests"
44+ "source" : [
45+ " !pip install labelbox\n " ,
46+ " !pip install requests"
47+ ]
4548 },
4649 {
4750 "cell_type" : " code" ,
4851 "execution_count" : 2 ,
4952 "id" : " supported-shield" ,
5053 "metadata" : {},
5154 "outputs" : [],
52- "source" : " from labelbox import Client\n from getpass import getpass\n import requests\n from collections import Counter\n import os"
55+ "source" : [
56+ " from labelbox import Client\n " ,
57+ " from getpass import getpass\n " ,
58+ " import requests\n " ,
59+ " from collections import Counter\n " ,
60+ " import os"
61+ ]
5362 },
5463 {
5564 "cell_type" : " code" ,
5665 "execution_count" : 3 ,
5766 "id" : " preceding-vitamin" ,
5867 "metadata" : {},
5968 "outputs" : [],
60- "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\n COLAB = \" google.colab\" in str(get_ipython())\n if COLAB:\n !pip install colab-env -qU\n from colab_env import envvar_handler\n envvar_handler.envload()\n\n API_KEY = os.environ.get(\" LABELBOX_API_KEY\" )\n if 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)"
69+ "source" : [
70+ " # If you don't want to give google access to drive you can skip this cell\n " ,
71+ " # and manually set `API_KEY` below.\n " ,
72+ " \n " ,
73+ " COLAB = \" google.colab\" in str(get_ipython())\n " ,
74+ " if COLAB:\n " ,
75+ " !pip install colab-env -qU\n " ,
76+ " from colab_env import envvar_handler\n " ,
77+ " envvar_handler.envload()\n " ,
78+ " \n " ,
79+ " API_KEY = os.environ.get(\" LABELBOX_API_KEY\" )\n " ,
80+ " if not os.environ.get(\" LABELBOX_API_KEY\" ):\n " ,
81+ " API_KEY = getpass(\" Please enter your labelbox api key\" )\n " ,
82+ " if COLAB:\n " ,
83+ " envvar_handler.add_env(\" LABELBOX_API_KEY\" , API_KEY)"
84+ ]
6185 },
6286 {
6387 "cell_type" : " code" ,
6488 "execution_count" : 4 ,
6589 "id" : " nominated-press" ,
6690 "metadata" : {},
6791 "outputs" : [],
68- "source" : " # Pick a project that has entity tools in the ontology and has completed labels\n PROJECT_ID = \" ckme5v7aykpoj0709ufi5h6i2\"\n # Only update this if you have an on-prem deployment\n ENDPOINT = \" https://api.labelbox.com/graphql\" "
92+ "source" : [
93+ " # Pick a project that has entity tools in the ontology and has completed labels\n " ,
94+ " PROJECT_ID = \" ckme5v7aykpoj0709ufi5h6i2\"\n " ,
95+ " # Only update this if you have an on-prem deployment\n " ,
96+ " ENDPOINT = \" https://api.labelbox.com/graphql\" "
97+ ]
6998 },
7099 {
71100 "cell_type" : " code" ,
72101 "execution_count" : 5 ,
73102 "id" : " aerial-general" ,
74103 "metadata" : {},
75104 "outputs" : [],
76- "source" : " client = Client(api_key=API_KEY, endpoint=ENDPOINT)\n project = client.get_project(PROJECT_ID)"
105+ "source" : [
106+ " client = Client(api_key=API_KEY, endpoint=ENDPOINT)\n " ,
107+ " project = client.get_project(PROJECT_ID)"
108+ ]
77109 },
78110 {
79111 "cell_type" : " markdown" ,
89121 "id" : " gothic-investing" ,
90122 "metadata" : {},
91123 "outputs" : [],
92- "source" : " export_url = project.export_labels()"
124+ "source" : [
125+ " export_url = project.export_labels()\n " ,
126+ " \n " ,
127+ " # labels can also be exported with `start` and `end` filters\n " ,
128+ " # export_url = project.export_labels(start=\" 2020-01-01\" , end=\" 2020-01-02\" )"
129+ ]
93130 },
94131 {
95132 "cell_type" : " code" ,
105142 ]
106143 }
107144 ],
108- "source" : " print(export_url)"
145+ "source" : [
146+ " print(export_url)"
147+ ]
109148 },
110149 {
111150 "cell_type" : " code" ,
112151 "execution_count" : 8 ,
113152 "id" : " sustained-retro" ,
114153 "metadata" : {},
115154 "outputs" : [],
116- "source" : " exports = requests.get(export_url).json()"
155+ "source" : [
156+ " exports = requests.get(export_url).json()"
157+ ]
117158 },
118159 {
119160 "cell_type" : " markdown" ,
148189 "output_type" : " execute_result"
149190 }
150191 ],
151- "source" : " # Print first label\n exports[0][\" Label\" ][\" objects\" ][0]"
192+ "source" : [
193+ " # Print first label\n " ,
194+ " exports[0][\" Label\" ][\" objects\" ][0]"
195+ ]
152196 },
153197 {
154198 "cell_type" : " markdown" ,
166210 "id" : " crazy-swing" ,
167211 "metadata" : {},
168212 "outputs" : [],
169- "source" : " text = exports[0][\" Labeled Data\" ]"
213+ "source" : [
214+ " text = exports[0][\" Labeled Data\" ]"
215+ ]
170216 },
171217 {
172218 "cell_type" : " code" ,
173219 "execution_count" : 11 ,
174220 "id" : " separated-girlfriend" ,
175221 "metadata" : {},
176222 "outputs" : [],
177- "source" : " people = []\n orgs = []\n for entity in exports[0][\" Label\" ][\" objects\" ]:\n location = entity[\" data\" ][\" location\" ]\n if entity[\" title\" ] == \" person\" :\n people.append(text[location[\" start\" ]:location[\" end\" ]])\n elif entity[\" title\" ] == \" org\" :\n orgs.append(text[location[\" start\" ]:location[\" end\" ]])"
223+ "source" : [
224+ " people = []\n " ,
225+ " orgs = []\n " ,
226+ " for entity in exports[0][\" Label\" ][\" objects\" ]:\n " ,
227+ " location = entity[\" data\" ][\" location\" ]\n " ,
228+ " if entity[\" title\" ] == \" person\" :\n " ,
229+ " people.append(text[location[\" start\" ]:location[\" end\" ]])\n " ,
230+ " elif entity[\" title\" ] == \" org\" :\n " ,
231+ " orgs.append(text[location[\" start\" ]:location[\" end\" ]])"
232+ ]
178233 },
179234 {
180235 "cell_type" : " code" ,
200255 "output_type" : " execute_result"
201256 }
202257 ],
203- "source" : " Counter(people)"
258+ "source" : [
259+ " Counter(people)"
260+ ]
204261 },
205262 {
206263 "cell_type" : " code" ,
273330 "output_type" : " execute_result"
274331 }
275332 ],
276- "source" : " Counter(orgs)"
333+ "source" : [
334+ " Counter(orgs)"
335+ ]
277336 },
278337 {
279338 "cell_type" : " code" ,
280339 "execution_count" : 14 ,
281340 "id" : " abandoned-knight" ,
282341 "metadata" : {},
283342 "outputs" : [],
284- "source" : " "
343+ "source" : []
285344 }
286345 ],
287346 "metadata" : {
305364 },
306365 "nbformat" : 4 ,
307366 "nbformat_minor" : 5
308- }
367+ }
0 commit comments