Skip to content
Closed
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
2 changes: 2 additions & 0 deletions libs/labelbox/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies = [
"tqdm>=4.66.2",
"geojson>=3.1.0",
"lbox-clients==1.1.2",
"PyYAML>=6.0",
]
readme = "README.md"
requires-python = ">=3.9,<3.14"
Expand Down Expand Up @@ -68,6 +69,7 @@ dev-dependencies = [
"types-python-dateutil>=2.9.0.20240316",
"types-requests>=2.31.0.20240311",
"types-tqdm>=4.66.0.20240106",
"types-PyYAML>=6.0.12.20240311",
]

[tool.ruff]
Expand Down
2 changes: 1 addition & 1 deletion libs/labelbox/src/labelbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from labelbox.schema.ontology_kind import OntologyKind
from labelbox.schema.organization import Organization
from labelbox.schema.project import Project
from labelbox.alignerr.schema.project_rate import ProjectRateV2 as ProjectRate
from labelbox.schema.project_model_config import ProjectModelConfig
from labelbox.schema.project_overview import (
ProjectOverview,
Expand All @@ -98,7 +99,6 @@
ResponseOption,
PromptResponseClassification,
)
from lbox.exceptions import *
from labelbox.schema.taskstatus import TaskStatus
from labelbox.schema.api_key import ApiKey
from labelbox.schema.timeunit import TimeUnit
Expand Down
3 changes: 3 additions & 0 deletions libs/labelbox/src/labelbox/alignerr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .alignerr_project import AlignerrWorkspace

__all__ = ["AlignerrWorkspace"]
175 changes: 175 additions & 0 deletions libs/labelbox/src/labelbox/alignerr/alignerr_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
from enum import Enum
from typing import TYPE_CHECKING, Optional

import logging

from labelbox.alignerr.schema.project_rate import ProjectRateV2
from labelbox.alignerr.schema.project_domain import ProjectDomain
from labelbox.alignerr.schema.enchanced_resource_tags import (
EnhancedResourceTag,
ResourceTagType,
)
from labelbox.alignerr.schema.project_boost_workforce import (
ProjectBoostWorkforce,
)
from labelbox.pagination import PaginatedCollection

logger = logging.getLogger(__name__)


if TYPE_CHECKING:
from labelbox import Client
from labelbox.schema.project import Project
from labelbox.alignerr.schema.project_domain import ProjectDomain


class AlignerrRole(Enum):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this role QQ we have other custom roles right?

Labeler = "LABELER"
Reviewer = "REVIEWER"
Admin = "ADMIN"
ProjectCoordinator = "PROJECT_COORDINATOR"
AlignerrLabeler = "ALIGNERR_LABELER"
EndLabellingRole = "ENDLABELLINGROLE"


class AlignerrProject:
def __init__(
self, client: "Client", project: "Project", _internal: bool = False
):
if not _internal:
raise RuntimeError(
"AlignerrProject cannot be initialized directly. "
"Use AlignerrProjectBuilder or AlignerrProjectFactory to create instances."
)
self.client = client
self.project = project

@property
def project(self) -> "Project":
return self._project

@project.setter
def project(self, project: "Project"):
self._project = project

def domains(self) -> PaginatedCollection:
return ProjectDomain.get_by_project_id(
client=self.client, project_id=self.project.uid
)

def add_domain(self, project_domain: ProjectDomain):
return ProjectDomain.connect_project_to_domains(
client=self.client,
project_id=self.project.uid,
domain_ids=[project_domain.uid],
)

def get_project_rates(self) -> list["ProjectRateV2"]:
return ProjectRateV2.get_by_project_id(
client=self.client, project_id=self.project.uid
)

def set_project_rate(self, project_rate_input):
return ProjectRateV2.set_project_rate(
client=self.client,
project_id=self.project.uid,
project_rate_input=project_rate_input,
)

def set_tags(self, tag_names: list[str], tag_type: ResourceTagType):
# Convert tag names to tag IDs
tag_ids = []
for tag_name in tag_names:
# Search for the tag by text to get its ID
found_tags = EnhancedResourceTag.search_by_text(
self.client, search_text=tag_name, tag_type=tag_type
)
if found_tags:
tag_ids.append(found_tags[0].id)

# Use the existing project resource tag functionality with IDs
self.project.update_project_resource_tags(tag_ids)
return self

def get_tags(self) -> list[EnhancedResourceTag]:
"""Get enhanced resource tags associated with this project.

Returns:
List of EnhancedResourceTag instances
"""
# Get project resource tags and convert to EnhancedResourceTag instances
project_resource_tags = self.project.get_resource_tags()
enhanced_tags = []
for tag in project_resource_tags:
# Search for the corresponding EnhancedResourceTag by text (try different types)
found_tags = []
for tag_type in [ResourceTagType.Default, ResourceTagType.Billing]:
found_tags = EnhancedResourceTag.search_by_text(
self.client, search_text=tag.text, tag_type=tag_type
)
if found_tags:
break
if found_tags:
enhanced_tags.extend(found_tags)
return enhanced_tags

def add_tag(self, tag: EnhancedResourceTag):
"""Add a single enhanced resource tag to the project.

Args:
tag: EnhancedResourceTag instance to add

Returns:
Self for method chaining
"""
current_tags = self.get_tags()
current_tag_names = [t.text for t in current_tags]

if tag.text not in current_tag_names:
current_tag_names.append(tag.text)
self.set_tags(current_tag_names, tag.type)

return self

def remove_tag(self, tag: EnhancedResourceTag):
"""Remove a single enhanced resource tag from the project.

Args:
tag: EnhancedResourceTag instance to remove

Returns:
Self for method chaining
"""
current_tags = self.get_tags()
current_tag_names = [t.text for t in current_tags if t.uid != tag.uid]
self.set_tags(current_tag_names, tag.type)
return self

def get_project_owner(self) -> Optional[ProjectBoostWorkforce]:
"""Get the ProjectBoostWorkforce for this project.

Returns:
ProjectBoostWorkforce instance or None if not found
"""
return ProjectBoostWorkforce.get_by_project_id(
client=self.client, project_id=self.project.uid
)


class AlignerrWorkspace:
def __init__(self, client: "Client"):
self.client = client

def project_builder(self):
from labelbox.alignerr.alignerr_project_builder import (
AlignerrProjectBuilder,
)

return AlignerrProjectBuilder(self.client)

def project_prototype(self):
from labelbox.alignerr.alignerr_project_factory import (
AlignerrProjectFactory,
)

return AlignerrProjectFactory(self.client)
Loading
Loading