Skip to content

Commit

Permalink
Add Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Aug 12, 2024
1 parent 353e496 commit 2ec639c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 0 additions & 1 deletion dev_requirements.txt

This file was deleted.

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# supervisely==6.73.128

git+https://github.com/supervisely/supervisely.git@update-app-workflow
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.")
26 changes: 26 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -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"<h4>{file.name}</h4>",
"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)}")

0 comments on commit 2ec639c

Please sign in to comment.