Skip to content

Commit

Permalink
Add workflow functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Aug 12, 2024
1 parent e74b2f2 commit c489a0e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 0 additions & 1 deletion dev_requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# supervisely==6.73.145
git+https://github.com/supervisely/supervisely.git@update-app-workflow
6 changes: 4 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

import functions as f
import globals as g

import workflow as w

def export_as_masks(api: sly.Api):
project_info = api.project.get_info_by_id(g.PROJECT_ID)
project_dir = os.path.join(g.STORAGE_DIR, f"{project_info.id}_{project_info.name}")
sly.logger.debug(f"Project will be saved to: {project_dir}")
sly.Project.download(api, g.PROJECT_ID, project_dir)
sly.logger.debug("Project downloaded.")
w.workflow_input(api, project_info.id)

if g.MACHINE_MASKS or g.HUMAN_MASKS or g.INSTANCE_MASKS:
sly.logger.debug("Started mask creation...")
Expand Down Expand Up @@ -141,7 +142,8 @@ def export_as_masks(api: sly.Api):
sly.logger.debug(f"Finished processing dataset {dataset.name}.")
sly.logger.info(f"Finished processing project {project.name}.")

sly.output.set_download(project_dir)
file_info = sly.output.set_download(project_dir)
w.workflow_output(api, file_info)
sly.logger.debug("Application finished, output set.")


Expand Down
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 project - {file}")
except Exception as e:
sly.logger.debug(f"Failed to add output to the workflow: {repr(e)}")

0 comments on commit c489a0e

Please sign in to comment.