Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ def upsert_instructions(self, instructions_file: str) -> None:
)

frontend = self.labeling_frontend()
frontendId = frontend.uid

if frontend.name != "Editor":
logger.warning(
Expand All @@ -428,35 +427,25 @@ def upsert_instructions(self, instructions_file: str) -> None:
f"instructions_file must be a pdf or html file. Found {instructions_file}"
)

lfo = list(self.labeling_frontend_options())[-1]
instructions_url = self.client.upload_file(instructions_file)
customization_options = self.ontology().normalized
customization_options['projectInstructions'] = instructions_url
option_id = lfo.uid

self.client.execute(
"""mutation UpdateFrontendWithExistingOptionsPyApi (
$frontendId: ID!,
$optionsId: ID!,
$name: String!,
$description: String!,
$customizationOptions: String!

query_str = """mutation setprojectinsructionsPyApi($projectId: ID!, $instructions_url: String!) {
setProjectInstructions(
where: {id: $projectId},
data: {instructionsUrl: $instructions_url}
) {
updateLabelingFrontend(
where: {id: $frontendId},
data: {name: $name, description: $description}
) {id}
updateLabelingFrontendOptions(
where: {id: $optionsId},
data: {customizationOptions: $customizationOptions}
) {id}
}""", {
"frontendId": frontendId,
"optionsId": option_id,
"name": frontend.name,
"description": "Video, image, and text annotation",
"customizationOptions": json.dumps(customization_options)
})
id
ontology {
id
options
}
}
}"""

self.client.execute(query_str, {
'projectId': self.uid,
'instructions_url': instructions_url
})

def labeler_performance(self) -> PaginatedCollection:
""" Returns the labeler performances for this Project.
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import time

import pytest
import requests
Expand Down Expand Up @@ -137,9 +138,8 @@ def test_attach_instructions(client, project):
project.setup(editor, empty_ontology)

project.upsert_instructions('tests/integration/media/sample_pdf.pdf')
assert json.loads(
list(project.labeling_frontend_options())
[-1].customization_options).get('projectInstructions') is not None
time.sleep(3)
assert project.ontology().normalized['projectInstructions'] is not None

with pytest.raises(ValueError) as exc_info:
project.upsert_instructions('/tmp/file.invalid_file_extension')
Expand Down