diff --git a/config.json b/config.json index 736a2e3..654dcd0 100644 --- a/config.json +++ b/config.json @@ -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", @@ -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" -} \ No newline at end of file +} diff --git a/dev_requirements.txt b/dev_requirements.txt index a1e9b07..c8bec4f 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1 +1 @@ -supervisely==6.73.93 +supervisely==6.73.156 diff --git a/src/main.py b/src/main.py index 491241d..ba4a859 100644 --- a/src/main.py +++ b/src/main.py @@ -8,6 +8,7 @@ import convert_geometry import functions as f +import workflow as w # region constants USER_NAME = "Supervisely" @@ -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}.") @@ -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__": diff --git a/src/workflow.py b/src/workflow.py new file mode 100644 index 0000000..52b32cf --- /dev/null +++ b/src/workflow.py @@ -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)}")