Skip to content

Commit

Permalink
Add Workflow class for input and output handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Jun 26, 2024
1 parent 1432738 commit 5fa110d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions annotation-tool/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import supervisely as sly
import yaml
from supervisely.imaging.color import generate_rgb, random_rgb
from workflow import Workflow

root_source_path = str(pathlib.Path(sys.argv[0]).parents[2])
sly.logger.info(f"Root source directory: {root_source_path}")
Expand Down Expand Up @@ -129,8 +130,7 @@ def inference(api: sly.Api, task_id, context, state, app_logger):
project_meta = sly.ProjectMeta.from_json(api.project.get_meta(project_id))

# -------------------------------------- Add Workflow Input -------------------------------------- #
api.app.add_input_project(project_id)
api.app.add_input_task(int(state["sessionId"]))
Workflow.add_input(api, project_id, state)
# ----------------------------------------------- - ---------------------------------------------- #

if image_id not in ann_cache:
Expand Down Expand Up @@ -455,8 +455,9 @@ def inference(api: sly.Api, task_id, context, state, app_logger):
{"field": "state.processing", "payload": False},
]
api.task.set_fields(task_id, fields)

# -------------------------------------- Add Workflow Output ------------------------------------- #
api.app.add_output_project(project_id)
Workflow.add_output(api, project_id)
# ----------------------------------------------- - ---------------------------------------------- #


Expand Down
36 changes: 36 additions & 0 deletions annotation-tool/src/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import supervisely as sly


def check_compatibility(func):
def wrapper(self, *args, **kwargs):
if self.is_compatible is None:
self.is_compatible = self.check_instance_ver_compatibility()
if not self.is_compatible:
return
return func(self, *args, **kwargs)

return wrapper


class Workflow:
def __init__(self):
self.is_compatible = None
self._min_instance_version = "6.9.22"

@check_compatibility
def add_input(self, api: sly.Api, project_id: int, state: dict):
if api.project.get_info_by_id(project_id).version: # to prevent cycled workflow
api.app.add_input_project(project_id)
api.app.add_input_task(int(state["sessionId"]))

@check_compatibility
def add_output(self, api: sly.Api, project_id: int):
api.app.add_output_project(project_id)

def check_instance_ver_compatibility(self, api: sly.Api):
if api.instance_version < self._min_instance_version:
sly.logger.info(
f"Supervisely instance version does not support workflow and versioning features. To use them, please update your instance minimum to version {self._min_instance_version}."
)
return False
return True

0 comments on commit 5fa110d

Please sign in to comment.