From 2ec639c434facec50bcf7acad4bd41d6a23cba02 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Mon, 12 Aug 2024 20:10:52 +0200 Subject: [PATCH] Add Workflow --- dev_requirements.txt | 1 - requirements.txt | 3 +++ src/main.py | 6 +++++- src/workflow.py | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) delete mode 100644 dev_requirements.txt create mode 100644 requirements.txt create mode 100644 src/workflow.py diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index fc7b119..0000000 --- a/dev_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -supervisely==6.73.128 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d28f5da --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# supervisely==6.73.128 + +git+https://github.com/supervisely/supervisely.git@update-app-workflow 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..73d20b6 --- /dev/null +++ b/src/workflow.py @@ -0,0 +1,26 @@ +# This module contains the functions that are used to configure the input and output of the workflow for the current app. + +import supervisely as sly +from typing import Union + +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) + meta = {"customRelationSettings": { + "icon": { + "icon": "zmdi-archive", + "color": "#33c94c", + "backgroundColor": "#d9f7e4" + }, + "title": f"

{file.name}

", + "mainLink": {"url": f"/files/{file.id}/true/?teamId={file.team_id}", "title": "Download"} + }} + 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)}") \ No newline at end of file