Skip to content

Commit

Permalink
Merge pull request #3 from supervisely-ecosystem/worklow
Browse files Browse the repository at this point in the history
Add Workflow and upgrade SDK to v6.73.157
  • Loading branch information
GoldenAnpu authored Aug 15, 2024
2 parents de5274e + 92951cf commit c861a09
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
16 changes: 5 additions & 11 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
"type": "app",
"version": "2.0.0",
"description": "Converts Supervisely format to COCO Keypoints",
"categories": [
"images",
"export"
],
"categories": ["images", "export"],
"main_script": "src/main.py",
"headless": true,
"icon": "https://github.com/supervisely-ecosystem/export-coco-keypoints/assets/119248312/c915fbea-a418-4e6b-ab74-899bcb6edd3b",
"icon_cover": true,
"poster": "https://github.com/supervisely-ecosystem/export-coco-keypoints/assets/119248312/5777a6fb-efe5-41c3-93b9-4abe92006b77",
"modal_template": "src/modal.html",
"docker_image": "supervisely/import-export:6.73.93",
"min_instance_version": "6.9.22",
"docker_image": "supervisely/import-export:6.73.157",
"min_instance_version": "6.10.0",
"task_location": "workspace_tasks",
"modal_template_state": {
"allDatasets": true,
Expand All @@ -23,10 +20,7 @@
"selectedOutput": "images"
},
"context_menu": {
"target": [
"images_project",
"images_dataset"
],
"target": ["images_project", "images_dataset"],
"context_root": "Download as"
}
}
}
3 changes: 1 addition & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
python-dotenv
supervisely==6.73.93

supervisely==6.73.157
# formatter
black

Expand Down
13 changes: 10 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dotenv import load_dotenv

import functions as f
import workflow as w

if sly.is_development():
load_dotenv("local.env")
Expand All @@ -20,18 +21,23 @@
all_datasets = bool(strtobool(os.getenv("modal.state.allDatasets")))
selected_datasets = ast.literal_eval(os.environ.get("modal.state.datasets", []))

api = sly.Api.from_env()

class MyExport(sly.app.Export):
def process(self, context: sly.app.Export.Context):
api = sly.Api.from_env()

project = api.project.get_info_by_id(id=context.project_id)
if context.dataset_id is not None:
datasets = [api.dataset.get_info_by_id(context.dataset_id)]
w.workflow_input(api, datasets[0].id, type="dataset")
elif len(selected_datasets) > 0 and not all_datasets:
datasets = [api.dataset.get_info_by_id(dataset_id) for dataset_id in selected_datasets]
datasets = [api.dataset.get_info_by_id(dataset_id) for dataset_id in selected_datasets]
if len(datasets) == 1:
w.workflow_input(api, datasets[0].id, type="dataset")
else:
w.workflow_input(api, project.id, type="project")
else:
datasets = api.dataset.get_list(project.id)
w.workflow_input(api, project.id, type="project")

project_meta = sly.ProjectMeta.from_json(api.project.get_meta(project.id))
categories_mapping = f.get_categories_map_from_meta(project_meta)
Expand Down Expand Up @@ -86,6 +92,7 @@ def main():
try:
app = MyExport()
app.run()
w.workflow_output(api, app.output_file)
except Exception as e:
exception_handler = handle_exception(e)
if exception_handler:
Expand Down
33 changes: 33 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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, Literal

import supervisely as sly


def workflow_input(api: sly.Api, id: int, type: Literal["project", "dataset"]):
if type == "project":
api.app.workflow.add_input_project(id)
sly.logger.debug(f"Workflow: Input project - {id}")
elif type == "dataset":
api.app.workflow.add_input_dataset(id)
sly.logger.debug(f"Workflow: Input dataset - {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)}")

0 comments on commit c861a09

Please sign in to comment.