diff --git a/README.md b/README.md index b3bceb0..72a4d86 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
Overview • @@ -19,13 +19,13 @@ # Overview -Download images project in [Supervisely JSON format](https://docs.supervise.ly/data-organization/00_ann_format_navi). It is possible to download both images and annotations or only annotations. +Download images project or dataset in [Supervisely JSON format](https://docs.supervise.ly/data-organization/00_ann_format_navi). It is possible to download both images and annotations or only annotations. # How To Use **Step 1**: Add app to your team from [Ecosystem](https://ecosystem.supervise.ly/apps/export-to-supervisely-format) if it is not there -**Step 2**: Open context menu of images project -> `Run App` -> `Download via app` -> `Export to Supervisely format` +**Step 2**: Open context menu of images project (or images dataset) -> `Run App` -> `Download via app` -> `Export to Supervisely format` diff --git a/config.json b/config.json index 7ba73eb..aa0b713 100644 --- a/config.json +++ b/config.json @@ -21,7 +21,8 @@ "icon_background": "#FFFFFF", "context_menu": { "target": [ - "images_project" + "images_project", + "images_dataset" ], "context_root": "Download as" }, diff --git a/src/main.py b/src/main.py index 10aa77f..1058bab 100644 --- a/src/main.py +++ b/src/main.py @@ -11,6 +11,9 @@ TEAM_ID = int(os.environ['context.teamId']) WORKSPACE_ID = int(os.environ['context.workspaceId']) PROJECT_ID = int(os.environ['modal.state.slyProjectId']) +DATASET_ID = os.environ.get('modal.state.slyDatasetId', None) +if DATASET_ID is not None: + DATASET_ID = int(DATASET_ID) task_id = int(os.environ["TASK_ID"]) mode = os.environ['modal.state.download'] replace_method = bool(util.strtobool(os.environ['modal.state.fixExtension'])) @@ -60,9 +63,16 @@ def init(data, state): @my_app.callback("download_as_sly") @sly.timeit def download_as_sly(api: sly.Api, task_id, context, state, app_logger): + global TEAM_ID, PROJECT_ID, DATASET_ID, mode + if DATASET_ID is not None: + dataset_ids = [DATASET_ID] + dataset = api.dataset.get_info_by_id(DATASET_ID) + if PROJECT_ID is None: + PROJECT_ID = dataset.project_id + else: + datasets = api.dataset.get_list(PROJECT_ID) + dataset_ids = [dataset.id for dataset in datasets] project = api.project.get_info_by_id(PROJECT_ID) - datasets = api.dataset.get_list(project.id) - dataset_ids = [dataset.id for dataset in datasets] if mode == 'all': download_json_plus_images(api, project, dataset_ids) else: