diff --git a/config.json b/config.json index 2298240..6532ff5 100644 --- a/config.json +++ b/config.json @@ -2,12 +2,9 @@ "name": "Export to Supervisely format", "type": "app", "version": "2.0.0", - "categories": [ - "images", - "export" - ], + "categories": ["images", "export"], "description": "images and JSON annotations", - "docker_image": "supervisely/import-export:6.73.128", + "docker_image": "supervisely/import-export:6.73.156", "instance_version": "6.10.0", "main_script": "src/main.py", "modal_template": "src/modal.html", @@ -21,10 +18,7 @@ "icon": "https://i.imgur.com/1hqGMyg.png", "icon_background": "#FFFFFF", "context_menu": { - "target": [ - "images_project", - "images_dataset" - ], + "target": ["images_project", "images_dataset"], "context_root": "Download as" }, "poster": "https://user-images.githubusercontent.com/106374579/186665737-ec3da9cc-193f-43ee-85db-a6f802b2dfe4.png" diff --git a/dev_requirements.txt b/dev_requirements.txt index fc7b119..fc7199d 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1 +1 @@ -supervisely==6.73.128 +supervisely==6.73.156 \ No newline at end of file diff --git a/src/main.py b/src/main.py index 27b0701..31ac29c 100644 --- a/src/main.py +++ b/src/main.py @@ -6,6 +6,8 @@ from supervisely.api.module_api import ApiField from supervisely.io.fs import get_file_ext +import workflow as w + if sly.is_development(): load_dotenv("local.env") load_dotenv(os.path.expanduser("~/supervisely.env")) @@ -107,5 +109,7 @@ def download(project: sly.Project) -> str: if __name__ == "__main__": project = api.project.get_info_by_id(project_id) download_dir = download(project) - sly.output.set_download(download_dir) + w.workflow_input(api, project.id) + file_info = sly.output.set_download(download_dir) + w.workflow_output(api, file_info) sly.logger.info("Archive uploaded and ready for download.") 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)}")