-
Notifications
You must be signed in to change notification settings - Fork 68
[PLT-1305] Vb/start labeling service plt 1305 #1749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Project Labeling Service | ||
=============================================================================================== | ||
|
||
.. automodule:: labelbox.schema.labeling_service | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from datetime import datetime | ||
from enum import Enum | ||
from typing import Any | ||
|
||
from labelbox.exceptions import ResourceNotFoundError | ||
|
||
from labelbox.data.annotation_types.types import Cuid | ||
from labelbox.pydantic_compat import BaseModel | ||
from labelbox.utils import _CamelCaseMixin | ||
|
||
|
||
class LabelingServiceStatus(Enum): | ||
Accepted = 'ACCEPTED', | ||
Calibration = 'CALIBRATION', | ||
Complete = 'COMPLETE', | ||
Production = 'PRODUCTION', | ||
Requested = 'REQUESTED', | ||
SetUp = 'SET_UP' | ||
|
||
|
||
class LabelingService(BaseModel): | ||
id: Cuid | ||
project_id: Cuid | ||
created_at: datetime | ||
updated_at: datetime | ||
created_by_id: Cuid | ||
status: LabelingServiceStatus | ||
client: Any # type Any to avoid circular import from client | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
if not self.client.enable_experimental: | ||
raise RuntimeError( | ||
"Please enable experimental in client to use LabelingService") | ||
|
||
class Config(_CamelCaseMixin.Config): | ||
... | ||
|
||
@classmethod | ||
def start(cls, client, project_id: Cuid) -> 'LabelingService': | ||
""" | ||
Starts the labeling service for the project. This is equivalent to a UI acction to Request Specialized Labelers | ||
|
||
Returns: | ||
LabelingService: The labeling service for the project. | ||
Raises: | ||
Exception: If the service fails to start. | ||
""" | ||
query_str = """mutation CreateProjectBoostWorkforcePyApi($projectId: ID!) { | ||
upsertProjectBoostWorkforce(data: { projectId: $projectId }) { | ||
success | ||
} | ||
}""" | ||
result = client.execute(query_str, {"projectId": project_id}) | ||
success = result["upsertProjectBoostWorkforce"]["success"] | ||
if not success: | ||
raise Exception("Failed to start labeling service") | ||
return cls.get(client, project_id) | ||
|
||
@classmethod | ||
def get(cls, client, project_id: Cuid) -> 'LabelingService': | ||
""" | ||
Returns the labeling service associated with the project. | ||
|
||
Raises: | ||
ResourceNotFoundError: If the project does not have a labeling service. | ||
""" | ||
query = """ | ||
query GetProjectBoostWorkforcePyApi($projectId: ID!) { | ||
projectBoostWorkforce(data: { projectId: $projectId }) { | ||
id | ||
projectId | ||
createdAt | ||
updatedAt | ||
createdById | ||
status | ||
} | ||
} | ||
""" | ||
result = client.execute(query, {"projectId": project_id}) | ||
if result["projectBoostWorkforce"] is None: | ||
raise ResourceNotFoundError( | ||
message="The project does not have a labeling service.") | ||
data = result["projectBoostWorkforce"] | ||
data["client"] = client | ||
return LabelingService(**data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
from labelbox.exceptions import ResourceNotFoundError | ||
from labelbox.schema.labeling_service import LabelingServiceStatus | ||
|
||
|
||
def test_get_labeling_service_throws_exception(project): | ||
with pytest.raises(ResourceNotFoundError): # No labeling service by default | ||
project.get_labeling_service() | ||
|
||
|
||
def test_start_labeling_service(project): | ||
labeling_service = project.request_labeling_service() | ||
assert labeling_service.status == LabelingServiceStatus.SetUp | ||
assert labeling_service.project_id == project.uid | ||
|
||
# Check that the labeling service is now available | ||
labeling_service = project.get_labeling_service() | ||
assert labeling_service.status == LabelingServiceStatus.SetUp | ||
assert labeling_service.project_id == project.uid |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these type ignores?