Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Workflow #19

Merged
merged 7 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
supervisely==6.73.128
supervisely==6.73.156
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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.")
29 changes: 29 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -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)}")