Skip to content

Add workflow management #1975

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions libs/labelbox/src/labelbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@
from labelbox.schema.taskstatus import TaskStatus
from labelbox.schema.api_key import ApiKey
from labelbox.schema.timeunit import TimeUnit
from labelbox.schema.workflow import ProjectWorkflow
40 changes: 40 additions & 0 deletions libs/labelbox/src/labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ProjectOverview,
ProjectOverviewDetailed,
)
from labelbox.schema.workflow import ProjectWorkflow
from labelbox.schema.resource_tag import ResourceTag
from labelbox.schema.task import Task
from labelbox.schema.task_queue import TaskQueue
Expand Down Expand Up @@ -1718,6 +1719,45 @@ def get_labeling_service_dashboard(self) -> LabelingServiceDashboard:
"""
return LabelingServiceDashboard.get(self.client, self.uid)

def get_workflow(self):
"""Get the workflow configuration for this project.

Workflows are automatically created when projects are created.

Returns:
ProjectWorkflow: A ProjectWorkflow object containing the project workflow information.
"""
warnings.warn(
"Workflow Management is currently in alpha and its behavior may change in future releases.",
)

return ProjectWorkflow.get_workflow(self.client, self.uid)

def clone_workflow_from(self, source_project_id: str) -> "ProjectWorkflow":
"""Clones a workflow from another project to this project.

Args:
source_project_id (str): The ID of the project to clone the workflow from

Returns:
ProjectWorkflow: The cloned workflow in this project
"""
warnings.warn(
"Workflow Management is currently in alpha and its behavior may change in future releases.",
)

# Get the source workflow
source_workflow = ProjectWorkflow.get_workflow(
self.client, source_project_id
)

# Use copy_workflow_structure to clone the workflow
return ProjectWorkflow.copy_workflow_structure(
source_workflow=source_workflow,
target_client=self.client,
target_project_id=self.uid,
)


class ProjectMember(DbObject):
user = Relationship.ToOne("User", cache=True)
Expand Down
132 changes: 132 additions & 0 deletions libs/labelbox/src/labelbox/schema/workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""
This module contains classes for managing project workflows in Labelbox.
It provides strongly-typed classes for nodes, edges, and workflow configuration.
"""

# Import all workflow classes to expose them at the package level
from labelbox.schema.workflow.enums import (
WorkflowDefinitionId,
NodeOutput,
NodeInput,
MatchFilters,
Scope,
FilterField,
FilterOperator,
IndividualAssignment,
)
from labelbox.schema.workflow.base import (
BaseWorkflowNode,
NodePosition,
)

# Import nodes from the nodes subdirectory
from labelbox.schema.workflow.nodes import (
InitialLabelingNode,
InitialReworkNode,
ReviewNode,
ReworkNode,
DoneNode,
CustomReworkNode,
UnknownWorkflowNode,
LogicNode,
AutoQANode,
)

from labelbox.schema.workflow.edges import (
WorkflowEdge,
WorkflowEdgeFactory,
)
from labelbox.schema.workflow.graph import ProjectWorkflowGraph

# Import from monolithic workflow.py file
from labelbox.schema.workflow.workflow import ProjectWorkflow, NodeType

# Import from monolithic project_filter.py file
from labelbox.schema.workflow.project_filter import (
ProjectWorkflowFilter,
created_by,
labeled_by,
annotation,
dataset,
issue_category,
sample,
metadata,
model_prediction,
natural_language,
labeling_time,
review_time,
labeled_at,
consensus_average,
batch,
feature_consensus_average,
MetadataCondition,
ModelPredictionCondition,
m_condition,
mp_condition,
convert_to_api_format,
)

# Re-export key classes at the module level
__all__ = [
# Core workflow components
"WorkflowDefinitionId",
"NodeOutput",
"NodeInput",
"MatchFilters",
"Scope",
"FilterField",
"FilterOperator",
"IndividualAssignment",
"BaseWorkflowNode",
"NodePosition",
"InitialLabelingNode",
"InitialReworkNode",
"ReviewNode",
"ReworkNode",
"LogicNode",
"DoneNode",
"CustomReworkNode",
"AutoQANode",
"UnknownWorkflowNode",
"WorkflowEdge",
"WorkflowEdgeFactory",
"ProjectWorkflow",
"NodeType",
"ProjectWorkflowGraph",
"ProjectWorkflowFilter",
# Filter construction functions
"created_by",
"labeled_by",
"annotation",
"sample",
"dataset",
"issue_category",
"model_prediction",
"natural_language",
"labeled_at",
"labeling_time",
"review_time",
"consensus_average",
"batch",
"feature_consensus_average",
"metadata",
"MetadataCondition",
"ModelPredictionCondition",
"m_condition",
"mp_condition",
# Utility functions
"convert_to_api_format",
]

# Define a mapping of node types for workflow creation
NODE_TYPE_MAP = {
WorkflowDefinitionId.InitialLabelingTask: InitialLabelingNode,
WorkflowDefinitionId.InitialReworkTask: InitialReworkNode,
WorkflowDefinitionId.ReviewTask: ReviewNode,
WorkflowDefinitionId.SendToRework: ReworkNode,
WorkflowDefinitionId.Logic: LogicNode,
WorkflowDefinitionId.Done: DoneNode,
WorkflowDefinitionId.CustomReworkTask: CustomReworkNode,
WorkflowDefinitionId.AutoQA: AutoQANode,
WorkflowDefinitionId.Unknown: UnknownWorkflowNode,
}
Loading
Loading