Skip to content

Commit 3b5ad31

Browse files
author
Matt Sokoloff
committed
basic working
1 parent fc6ff5e commit 3b5ad31

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

labelbox/schema/project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,40 @@ def export_labels(self, timeout_seconds=60):
173173
self.uid)
174174
time.sleep(sleep_time)
175175

176+
def attach_instructions(self, instructions_file: str):
177+
"""
178+
- Upload a set of instructions for labeling
179+
180+
"""
181+
if self.setup_complete is None:
182+
raise Exception("Cannot attach instructions to a project that has not been setup.")
183+
184+
assert self.setup_complete is not None #Change this to an actual exception...
185+
#Assert that the editor type is the editor..
186+
instructions_url = self.client.upload_file(instructions_file)
187+
lfo = list(self.labeling_frontend_options())[-1]
188+
customization_options = json.loads(lfo.customization_options)
189+
customization_options['projectInstructions'] = instructions_url
190+
option_id = lfo.uid
191+
frontendId = self.labeling_frontend().uid
192+
args = {"frontendId": frontendId,
193+
"name": "Editor", #Probably only compatible with the regular editor..
194+
"description": "Video, image, and text annotation",
195+
"optionsId": option_id,
196+
"customizationOptions": json.dumps(customization_options)
197+
}
198+
return self.client.execute("""
199+
mutation UpdateFrontendWithExistingOptions($frontendId: ID!, $optionsId: ID!, $name: String!, $description: String!, $customizationOptions: String!) {
200+
updateLabelingFrontend(where: {id: $frontendId}, data: {name: $name, description: $description}) {
201+
id
202+
}
203+
updateLabelingFrontendOptions(where: {id: $optionsId}, data: {customizationOptions: $customizationOptions}) {
204+
id
205+
}
206+
}
207+
""", args)
208+
209+
176210
def labeler_performance(self):
177211
""" Returns the labeler performances for this Project.
178212

tests/integration/test_project.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from labelbox import Project
44
from labelbox.exceptions import InvalidQueryError
5+
import json
56

67

78
def test_project(client, rand_gen):
@@ -64,3 +65,9 @@ def test_extend_reservations(project):
6465
assert project.extend_reservations("ReviewQueue") == 0
6566
with pytest.raises(InvalidQueryError):
6667
project.extend_reservations("InvalidQueueType")
68+
69+
70+
71+
def test_attach_instructions(setup_project):
72+
setup_project.attach_labeling_instructions("http://www.africau.edu/images/default/sample.pdf")
73+
assert json.loads(list(setup_project.labeling_frontend_options())[-1].customization_options).get('projectInstructions') is not None

0 commit comments

Comments
 (0)