Skip to content

Commit

Permalink
Merge pull request #11 from supervisely-ecosystem/workflow
Browse files Browse the repository at this point in the history
Add Workflow and upgrade SDK to v6.73.157
  • Loading branch information
GoldenAnpu authored Aug 14, 2024
2 parents 4d44674 + 06ad82f commit c24cb47
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"target": ["images_project", "images_dataset"],
"context_root": "Download as"
},
"docker_image": "supervisely/import-export:6.73.106",
"min_instance_version": "6.9.22"
"docker_image": "supervisely/import-export:6.73.157",
"min_instance_version": "6.10.0"
}
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
supervisely==6.73.156
supervisely==6.73.157
19 changes: 15 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import supervisely as sly

import src.globals as g
import src.functions as f
import src.globals as g
import src.workflow as w

api = None


class MyExport(sly.app.Export):
def process(self, context: sly.app.Export.Context):
global api
api = sly.Api.from_env()

project = api.project.get_info_by_id(id=context.project_id)
Expand All @@ -16,6 +20,8 @@ def process(self, context: sly.app.Export.Context):
else:
datasets = api.dataset.get_list(project.id, recursive=True)

w.workflow_input(api, project.id)

images_count = 0
for ds in datasets:
images_count += ds.images_count
Expand Down Expand Up @@ -47,9 +53,13 @@ def process(self, context: sly.app.Export.Context):
progress = sly.Progress("Transformation ...", images_count)
for ds in datasets:
train_info, val_info = f.process_images(
api, meta, ds,
class_names, progress,
dir_names, skipped,
api,
meta,
ds,
class_names,
progress,
dir_names,
skipped,
max_kpts_count,
)
train_ids, train_img_paths, train_anns = train_info
Expand Down Expand Up @@ -106,6 +116,7 @@ def main():
try:
app = MyExport()
app.run()
w.workflow_output(api, app.output_file)
finally:
if not sly.is_development():
sly.logger.info(f"Remove temp directory: {g.TEMP_DIR}")
Expand Down
29 changes: 29 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This module contains the functions that are used to configure the input and output of the workflow for the current app.

from typing import Union

import supervisely as sly


def workflow_input(api: sly.Api, project_id: int):
api.app.workflow.add_input_project(project_id)
sly.logger.debug(f"Workflow: Input project - {project_id}")


def workflow_output(api: sly.Api, file: Union[int, sly.api.file_api.FileInfo]):
try:
if isinstance(file, int):
file = api.file.get_info_by_id(file)
relation_settings = sly.WorkflowSettings(
title=file.name,
icon="archive",
icon_color="#33c94c",
icon_bg_color="#d9f7e4",
url=f"/files/{file.id}/true/?teamId={file.team_id}",
url_title="Download",
)
meta = sly.WorkflowMeta(relation_settings=relation_settings)
api.app.workflow.add_output_file(file, meta=meta)
sly.logger.debug(f"Workflow: Output file - {file}")
except Exception as e:
sly.logger.debug(f"Failed to add output to the workflow: {repr(e)}")

0 comments on commit c24cb47

Please sign in to comment.