Skip to content

Commit

Permalink
Merge pull request #24 from supervisely-ecosystem/add-workflow
Browse files Browse the repository at this point in the history
Add Workflow and upgrade SDK to v6.73.156
  • Loading branch information
GoldenAnpu authored Aug 14, 2024
2 parents 6402a23 + 53c044b commit 68224c3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
13 changes: 4 additions & 9 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
"name": "Export to COCO",
"type": "app",
"version": "2.0.0",
"categories": [
"images",
"export"
],
"categories": ["images", "export"],
"description": "Converts Supervisely to COCO format and prepares tar archive for download",
"docker_image": "supervisely/import-export:6.73.93",
"docker_image": "supervisely/import-export:6.73.156",
"min_instance_version": "6.9.22",
"main_script": "src/main.py",
"modal_template": "src/modal.html",
Expand All @@ -23,10 +20,8 @@
"captions": false
},
"context_menu": {
"target": [
"images_project"
],
"target": ["images_project"],
"context_root": "Download as"
},
"poster": "https://user-images.githubusercontent.com/48913536/183899083-64d7683d-57f9-4f7a-b5f4-bf9e7ffd3246.png"
}
}
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
supervisely==6.73.93
supervisely==6.73.156
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import convert_geometry
import functions as f
import workflow as w

# region constants
USER_NAME = "Supervisely"
Expand Down Expand Up @@ -45,6 +46,8 @@ def export_to_coco(api: sly.Api) -> None:
project_meta = sly.ProjectMeta.from_json(api.project.get_meta(project_id))
sly.logger.debug("Project meta retrieved...")

w.workflow_input(api, project.id)

coco_base_dir = os.path.join(STORAGE_DIR, project.name)
sly.logger.debug(f"Data in COCO format will be saved to {coco_base_dir}.")

Expand Down Expand Up @@ -121,7 +124,8 @@ def export_to_coco(api: sly.Api) -> None:
sly.logger.info(f"Total images: {total_files - len(datasets)}")
sly.logger.info(f"Total directory size: {dir_size}")

sly.output.set_download(coco_base_dir)
file_info = sly.output.set_download(coco_base_dir)
w.workflow_output(api, file_info)


if __name__ == "__main__":
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 68224c3

Please sign in to comment.