Skip to content

Commit

Permalink
Refactor workflow.py for improved readability and maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Aug 13, 2024
1 parent 731b27e commit 3834355
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -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"<h4>{file.name}</h4>",
"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)}")
sly.logger.debug(f"Failed to add output to the workflow: {repr(e)}")

0 comments on commit 3834355

Please sign in to comment.