diff --git a/config.json b/config.json index b6a494b..a28f109 100644 --- a/config.json +++ b/config.json @@ -1,13 +1,10 @@ { "name": "Export to Pascal VOC", "type": "app", - "categories": [ - "images", - "export" - ], + "categories": ["images", "export"], "description": "Converts Supervisely Project to Pascal VOC format", - "docker_image": "supervisely/import-export:6.73.93", - "instance_version": "6.9.22", + "docker_image": "supervisely/import-export:6.73.157", + "instance_version": "6.10.0", "main_script": "src/main.py", "modal_template": "src/modal.html", "modal_template_state": { @@ -20,10 +17,8 @@ "icon_background": "#FFFFFF", "headless": true, "context_menu": { - "target": [ - "images_project" - ], + "target": ["images_project"], "context_root": "Download as" }, "poster": "https://user-images.githubusercontent.com/48245050/182382862-d74f1b2c-b19e-47c2-84db-45cd934ec34e.png" -} \ No newline at end of file +} diff --git a/dev_requirements.txt b/dev_requirements.txt index d3b0052..da72e87 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,4 +1,4 @@ -supervisely==6.73.93 +supervisely==6.73.157 lxml numpy>=1.19.4 Pillow>=8.0.1 diff --git a/src/main.py b/src/main.py index ac947d6..d4d0e04 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,7 @@ import supervisely as sly import globals as g +import workflow as w import utils @@ -14,6 +15,8 @@ def from_sly_to_pascal(api: sly.Api): meta = sly.ProjectMeta.from_json(meta_json) sly.logger.info("Palette has been created") + w.workflow_input(api, project_info.id) + full_result_dir_name = f"{str(project_info.id)}_{project_info.name}{g.RESULT_DIR_NAME_ENDING}" result_dir = os.path.join(g.DATA_DIR, full_result_dir_name) @@ -156,7 +159,9 @@ def from_sly_to_pascal(api: sly.Api): utils.write_segm_set(is_trainval, images_stats, result_imgsets_dir) utils.write_main_set(is_trainval, images_stats, meta, result_imgsets_dir) - sly.output.set_download(result_dir) + file_info = sly.output.set_download(result_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)}")