|
20 | 20 | "* A datarow is a member of a dataset \n", |
21 | 21 | "* A datarow cannot exist without belonging to a dataset.\n", |
22 | 22 | "* Datarows are staged to be labeled by attaching the dataset that they are members of to a project\n", |
23 | | - " * See dataset notebook on information about datasets\n", |
24 | | - "---\n", |
25 | | - "To run this notebook on your own data, set the variables in the next cell" |
| 23 | + " * See dataset notebook on information about datasets" |
26 | 24 | ] |
27 | 25 | }, |
28 | 26 | { |
29 | 27 | "cell_type": "code", |
30 | 28 | "execution_count": null, |
31 | | - "id": "rural-fellow", |
| 29 | + "id": "posted-nation", |
32 | 30 | "metadata": {}, |
33 | 31 | "outputs": [], |
34 | 32 | "source": [ |
35 | | - "PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"" |
| 33 | + "!pip install labelbox" |
36 | 34 | ] |
37 | 35 | }, |
38 | 36 | { |
39 | 37 | "cell_type": "code", |
40 | 38 | "execution_count": null, |
41 | | - "id": "filled-disaster", |
| 39 | + "id": "beautiful-ready", |
42 | 40 | "metadata": {}, |
43 | 41 | "outputs": [], |
44 | 42 | "source": [ |
45 | 43 | "from labelbox import Project, Dataset, DataRow, Client\n", |
46 | | - "import uuid" |
| 44 | + "import uuid\n", |
| 45 | + "import os" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "markdown", |
| 50 | + "id": "legendary-harvard", |
| 51 | + "metadata": {}, |
| 52 | + "source": [ |
| 53 | + "* Set the following cell with your data to run this notebook" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": null, |
| 59 | + "id": "rural-fellow", |
| 60 | + "metadata": {}, |
| 61 | + "outputs": [], |
| 62 | + "source": [ |
| 63 | + "# Pick a project that has a dataset attached\n", |
| 64 | + "PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"\n", |
| 65 | + "# Set this if running in colab. Otherwise it should work if you have the LABELBOX_API_KEY set.\n", |
| 66 | + "API_KEY = os.environ[\"LABELBOX_API_KEY\"]\n", |
| 67 | + "# Only update this if you have an on-prem deployment\n", |
| 68 | + "ENDPOINT = \"https://api.labelbox.com/graphql\" " |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": null, |
| 74 | + "id": "proof-detective", |
| 75 | + "metadata": {}, |
| 76 | + "outputs": [], |
| 77 | + "source": [ |
| 78 | + "client = Client(api_key = API_KEY, endpoint = ENDPOINT)" |
47 | 79 | ] |
48 | 80 | }, |
49 | 81 | { |
|
53 | 85 | "metadata": {}, |
54 | 86 | "outputs": [], |
55 | 87 | "source": [ |
56 | | - "client = Client()\n", |
57 | 88 | "project = client.get_project(PROJECT_ID)\n", |
58 | 89 | "dataset = next(project.datasets())\n", |
59 | | - "#This is the same as\n", |
60 | | - "#-> dataset = client.get_dataset(dataset_id)" |
| 90 | + "# This is the same as\n", |
| 91 | + "# -> dataset = client.get_dataset(dataset_id)" |
61 | 92 | ] |
62 | 93 | }, |
63 | 94 | { |
|
86 | 117 | "metadata": {}, |
87 | 118 | "outputs": [], |
88 | 119 | "source": [ |
89 | | - "#Url\n", |
| 120 | + "# Url\n", |
90 | 121 | "print(\"Associated dataset\", datarow.dataset())\n", |
91 | 122 | "print(\"Associated label(s)\", next(datarow.labels()))\n", |
92 | 123 | "print(\"External id\", datarow.external_id)" |
|
99 | 130 | "metadata": {}, |
100 | 131 | "outputs": [], |
101 | 132 | "source": [ |
102 | | - "#External ids can be a reference to your internal datasets\n", |
| 133 | + "# External ids can be a reference to your internal datasets\n", |
103 | 134 | "datarow = dataset.data_row_for_external_id(datarow.external_id)\n", |
104 | 135 | "print(datarow)" |
105 | 136 | ] |
|
123 | 154 | "dataset = client.create_dataset(name = \"testing-dataset\")\n", |
124 | 155 | "dataset.create_data_row(row_data = \"https://picsum.photos/200/300\")\n", |
125 | 156 | "\n", |
126 | | - "#It is reccomended that you use external ids but optional.\n", |
127 | | - "#These are useful for users to maintain references to a data_row.\n", |
| 157 | + "# It is reccomended that you use external ids but optional.\n", |
| 158 | + "# These are useful for users to maintain references to a data_row.\n", |
128 | 159 | "dataset.create_data_row(row_data = \"https://picsum.photos/200/300\", external_id = str(uuid.uuid4()))\n" |
129 | 160 | ] |
130 | 161 | }, |
|
135 | 166 | "metadata": {}, |
136 | 167 | "outputs": [], |
137 | 168 | "source": [ |
138 | | - "#Bulk create datarows\n", |
| 169 | + "# Bulk create datarows\n", |
139 | 170 | "task1 = dataset.create_data_rows([{DataRow.row_data : \"https://picsum.photos/200/300\"}\n", |
140 | 171 | " , {DataRow.row_data : \"https://picsum.photos/200/300\"}])" |
141 | 172 | ] |
|
147 | 178 | "metadata": {}, |
148 | 179 | "outputs": [], |
149 | 180 | "source": [ |
150 | | - "#Local paths\n", |
| 181 | + "# Local paths\n", |
151 | 182 | "local_data_path = '/tmp/test_data_row.txt'\n", |
152 | 183 | "with open(local_data_path, 'w') as file:\n", |
153 | 184 | " file.write(\"sample data\")\n", |
|
162 | 193 | "metadata": {}, |
163 | 194 | "outputs": [], |
164 | 195 | "source": [ |
165 | | - "#You can mix local files with urls\n", |
| 196 | + "# You can mix local files with urls\n", |
166 | 197 | "task3 = dataset.create_data_rows([{DataRow.row_data : \"https://picsum.photos/200/300\"}, local_data_path])" |
167 | 198 | ] |
168 | 199 | }, |
|
173 | 204 | "metadata": {}, |
174 | 205 | "outputs": [], |
175 | 206 | "source": [ |
176 | | - "#Note that you cannot set external_ids at this time when uploading from local files.\n", |
177 | | - "#To do this you have to first\n", |
| 207 | + "# Note that you cannot set external_ids at this time when uploading from local files.\n", |
| 208 | + "# To do this you have to first\n", |
178 | 209 | "item_url = client.upload_file(local_data_path)\n", |
179 | 210 | "task4 = dataset.create_data_rows([{DataRow.row_data : item_url, DataRow.external_id : str(uuid.uuid4())}])" |
180 | 211 | ] |
|
186 | 217 | "metadata": {}, |
187 | 218 | "outputs": [], |
188 | 219 | "source": [ |
189 | | - "#Blocking wait until complete\n", |
| 220 | + "# Blocking wait until complete\n", |
190 | 221 | "task1.wait_till_done()\n", |
191 | 222 | "task2.wait_till_done()\n", |
192 | 223 | "task3.wait_till_done()\n", |
|
210 | 241 | "metadata": {}, |
211 | 242 | "outputs": [], |
212 | 243 | "source": [ |
213 | | - "#Useful for resigning urls\n", |
| 244 | + "# Useful for resigning urls\n", |
214 | 245 | "new_id = str(uuid.uuid4())\n", |
215 | 246 | "datarow.update(external_id = new_id)\n", |
216 | 247 | "print(datarow.external_id, new_id)\n" |
|
223 | 254 | "metadata": {}, |
224 | 255 | "outputs": [], |
225 | 256 | "source": [ |
226 | | - "#We can also attach metadata (See metadata tutorial for more)\n", |
227 | | - "#Metadata is visible for all projects with this datarow attached\n", |
| 257 | + "# We can also attach metadata (See metadata tutorial for more)\n", |
| 258 | + "# Metadata is visible for all projects with this datarow attached\n", |
228 | 259 | "datarow.create_metadata(meta_type = \"TEXT\", meta_value = \"LABELERS WILL SEE THIS \")\n", |
229 | | - "#See more information here:\n", |
230 | | - "#https://docs.labelbox.com/en/import-data/attachments\n", |
231 | | - "#Note that meta_value must always be a string (url to a video/image or a text value to display)" |
| 260 | + "# See more information here:\n", |
| 261 | + "# https://docs.labelbox.com/en/import-data/attachments\n", |
| 262 | + "# Note that meta_value must always be a string (url to a video/image or a text value to display)" |
232 | 263 | ] |
233 | 264 | }, |
234 | 265 | { |
|
247 | 278 | "outputs": [], |
248 | 279 | "source": [ |
249 | 280 | "datarow.delete()\n", |
250 | | - "#Will remove from the dataset too" |
| 281 | + "# Will remove from the dataset too" |
251 | 282 | ] |
252 | 283 | }, |
253 | 284 | { |
|
257 | 288 | "metadata": {}, |
258 | 289 | "outputs": [], |
259 | 290 | "source": [ |
260 | | - "#Bulk delete a list of datarows (in this case all of them we just uploaded)\n", |
| 291 | + "# Bulk delete a list of datarows (in this case all of them we just uploaded)\n", |
261 | 292 | "DataRow.bulk_delete(list(dataset.data_rows()))" |
262 | 293 | ] |
263 | 294 | } |
|
0 commit comments