From 2ec639c434facec50bcf7acad4bd41d6a23cba02 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Mon, 12 Aug 2024 20:10:52 +0200 Subject: [PATCH 1/7] 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 From 731b27e8c8136e00867ab42a87ba9798f81af36e Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Tue, 13 Aug 2024 09:31:26 +0200 Subject: [PATCH 2/7] Change branch name for SDK --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d28f5da..4326f54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ # supervisely==6.73.128 -git+https://github.com/supervisely/supervisely.git@update-app-workflow +git+https://github.com/supervisely/supervisely.git@add-workflow-compatibility-check From 383435565a63b00c8d10f238d8a77409d0d7822e Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Tue, 13 Aug 2024 18:22:01 +0200 Subject: [PATCH 3/7] Refactor workflow.py for improved readability and maintainability --- src/workflow.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/workflow.py b/src/workflow.py index 73d20b6..31cdd4d 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -1,26 +1,29 @@ # 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 +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) - 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"} - }} + relation_settings = sly.app.WorkflowSettings( + title=file.name, + icon="archive", + color="#33c94c", + background_color="#d9f7e4", + url=f"/files/{file.id}/true/?teamId={file.team_id}", + url_title="Download", + ) + meta = sly.app.WorkflowMeta.create_as_dict(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)}") \ No newline at end of file + sly.logger.debug(f"Failed to add output to the workflow: {repr(e)}") From 3809ae1835341d1d40cc5be779f76e1edf63dda6 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Tue, 13 Aug 2024 19:24:27 +0200 Subject: [PATCH 4/7] Update imports --- src/workflow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/workflow.py b/src/workflow.py index 31cdd4d..7ec2dd2 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -14,7 +14,7 @@ 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.app.WorkflowSettings( + relation_settings = sly.WorkflowSettings( title=file.name, icon="archive", color="#33c94c", @@ -22,7 +22,7 @@ def workflow_output(api: sly.Api, file: Union[int, sly.api.file_api.FileInfo]): url=f"/files/{file.id}/true/?teamId={file.team_id}", url_title="Download", ) - meta = sly.app.WorkflowMeta.create_as_dict(relation_settings=relation_settings) + meta = sly.WorkflowMeta.create_as_dict(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: From 96255d43ef16a013019fa57f581316005df863ee Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Tue, 13 Aug 2024 19:30:00 +0200 Subject: [PATCH 5/7] FIx arg for init WorkflowSettings --- src/workflow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/workflow.py b/src/workflow.py index 7ec2dd2..c06b7fc 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -17,8 +17,8 @@ def workflow_output(api: sly.Api, file: Union[int, sly.api.file_api.FileInfo]): relation_settings = sly.WorkflowSettings( title=file.name, icon="archive", - color="#33c94c", - background_color="#d9f7e4", + icon_color="#33c94c", + icon_bg_color="#d9f7e4", url=f"/files/{file.id}/true/?teamId={file.team_id}", url_title="Download", ) From 176573219911c344809303180b9d933a956b581d Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Wed, 14 Aug 2024 10:11:12 +0200 Subject: [PATCH 6/7] Upgrade SDK to v6.73.156 --- config.json | 12 +++--------- dev_requirements.txt | 1 + requirements.txt | 3 --- src/workflow.py | 2 +- 4 files changed, 5 insertions(+), 13 deletions(-) create mode 100644 dev_requirements.txt delete mode 100644 requirements.txt diff --git a/config.json b/config.json index 2298240..d523077 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.153", "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 new file mode 100644 index 0000000..fc7199d --- /dev/null +++ b/dev_requirements.txt @@ -0,0 +1 @@ +supervisely==6.73.156 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 4326f54..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -# supervisely==6.73.128 - -git+https://github.com/supervisely/supervisely.git@add-workflow-compatibility-check diff --git a/src/workflow.py b/src/workflow.py index c06b7fc..52b32cf 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -22,7 +22,7 @@ def workflow_output(api: sly.Api, file: Union[int, sly.api.file_api.FileInfo]): url=f"/files/{file.id}/true/?teamId={file.team_id}", url_title="Download", ) - meta = sly.WorkflowMeta.create_as_dict(relation_settings=relation_settings) + 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: From 394c7b2bf75091ec94d10989c4c670fddd7f4df4 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Wed, 14 Aug 2024 11:07:58 +0200 Subject: [PATCH 7/7] Update docker_image version in config.json --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index d523077..6532ff5 100644 --- a/config.json +++ b/config.json @@ -4,7 +4,7 @@ "version": "2.0.0", "categories": ["images", "export"], "description": "images and JSON annotations", - "docker_image": "supervisely/import-export:6.73.153", + "docker_image": "supervisely/import-export:6.73.156", "instance_version": "6.10.0", "main_script": "src/main.py", "modal_template": "src/modal.html",