From eaf1fe6137f3cdef44a0dd186945c0ed2897be34 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Sun, 10 Nov 2024 01:20:10 +0100 Subject: [PATCH 1/2] Add async download functionality for projects --- requirements.txt | 1 + src/main.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a76f6fb --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +git+https://github.com/supervisely/supervisely.git@project_download_async \ No newline at end of file diff --git a/src/main.py b/src/main.py index 0185b95..61a4017 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,4 @@ +import asyncio import os from distutils import util @@ -118,16 +119,24 @@ def download(project: sly.Project) -> str: sly.logger.info(f"Starting download of project {project.name} to {download_dir}...") - sly.Project.download( + loop = sly.fs.get_or_create_event_loop() + coro = sly.Project.download_async( api, project_id, dest_dir=download_dir, dataset_ids=dataset_ids, log_progress=True, - batch_size=batch_size, save_image_meta=True, save_images=save_images, ) + if loop.is_running(): + sly.logger.debug("Loop is already running, using run_coroutine_threadsafe") + future = asyncio.run_coroutine_threadsafe(coro, loop) + future.result() + else: + sly.logger.debug("Loop is not running, using run_until_complete") + loop.run_until_complete(coro) + meta_path = os.path.join(download_dir, "meta.json") meta = sly.ProjectMeta.from_json(sly.json.load_json_file(meta_path)) if any(obj_cls.geometry_type == sly.Cuboid2d for obj_cls in meta.obj_classes): From 496dee0b6761e68d2e733040f4d8e55b64a0b4f7 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Wed, 4 Dec 2024 15:42:10 +0100 Subject: [PATCH 2/2] Update docker image and instance version in config.json; remove requirements.txt --- config.json | 54 ++++++++++++++++++++------------------------ dev_requirements.txt | 2 +- requirements.txt | 1 - 3 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 requirements.txt diff --git a/config.json b/config.json index 35a9a19..0ba9c40 100644 --- a/config.json +++ b/config.json @@ -1,31 +1,25 @@ { - "name": "Export to Supervisely format", - "type": "app", - "version": "2.0.0", - "categories": [ - "images", - "export" - ], - "description": "images and JSON annotations", - "docker_image": "supervisely/import-export:6.73.162", - "instance_version": "6.11.8", - "main_script": "src/main.py", - "modal_template": "src/modal.html", - "modal_template_state": { - "download": "all", - "fixExtension": false - }, - "task_location": "workspace_tasks", - "isolate": true, - "headless": true, - "icon": "https://i.imgur.com/1hqGMyg.png", - "icon_background": "#FFFFFF", - "context_menu": { - "target": [ - "images_project", - "images_dataset" - ], - "context_root": "Download as" - }, - "poster": "https://user-images.githubusercontent.com/106374579/186665737-ec3da9cc-193f-43ee-85db-a6f802b2dfe4.png" -} \ No newline at end of file + "name": "Export to Supervisely format", + "type": "app", + "version": "2.0.0", + "categories": ["images", "export"], + "description": "images and JSON annotations", + "docker_image": "supervisely/import-export:6.73.248", + "instance_version": "6.12.12", + "main_script": "src/main.py", + "modal_template": "src/modal.html", + "modal_template_state": { + "download": "all", + "fixExtension": false + }, + "task_location": "workspace_tasks", + "isolate": true, + "headless": true, + "icon": "https://i.imgur.com/1hqGMyg.png", + "icon_background": "#FFFFFF", + "context_menu": { + "target": ["images_project", "images_dataset"], + "context_root": "Download as" + }, + "poster": "https://user-images.githubusercontent.com/106374579/186665737-ec3da9cc-193f-43ee-85db-a6f802b2dfe4.png" +} diff --git a/dev_requirements.txt b/dev_requirements.txt index 5d6a7a6..8fb9dfa 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1 +1 @@ -supervisely==6.73.162 \ No newline at end of file +supervisely==6.73.248 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a76f6fb..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -git+https://github.com/supervisely/supervisely.git@project_download_async \ No newline at end of file