diff --git a/config.json b/config.json index a16be7b2..85646de3 100644 --- a/config.json +++ b/config.json @@ -23,5 +23,5 @@ "files_file" ] }, - "instance_version": "6.11.22" + "instance_version": "6.12.8" } diff --git a/src/main.py b/src/main.py index e9e99d1a..baaa52c6 100644 --- a/src/main.py +++ b/src/main.py @@ -200,6 +200,8 @@ def run_pipeline_from_api(response: Response, request: Request): # pipeline_preset = state["pipeline_preset"] if g.pipeline_running: return {"result": "pipeline is already running. Please wait until it's finished."} + + time.sleep(5) # delay to init layers run_btn_clicked() return {"result": "pipeline was successfully processed"} except Exception as e: diff --git a/src/scripts/api_request.py b/src/scripts/api_request.py new file mode 100644 index 00000000..26de1a1c --- /dev/null +++ b/src/scripts/api_request.py @@ -0,0 +1,28 @@ +# Example on how to send API requests to ML Pipelines app from a script +# Available endpoints: +# 1. run_pipeline - runs a pipeline with currently selected layers on the scene +# 2. get_pipeline_status - returns the status of the pipeline (e.g "Pipeline status is 21/50") + +import os + +import supervisely as sly +from dotenv import load_dotenv + +load_dotenv(os.path.expanduser("~/supervisely.env")) +load_dotenv("local.env") + +team_id = sly.env.team_id() +workspace_id = sly.env.workspace_id() + +api: sly.Api = sly.Api.from_env() + +task_id = 68139 + +is_ready = api.app.is_ready_for_api_calls(task_id) + +# is_ready = api.app.wait_until_ready_for_api_calls(task_id) +# if is_ready: +api.task.send_request(task_id=task_id, method="run_pipeline", data={}) + +# status = api.task.send_request(task_id=task_id, method="get_pipeline_status", data={}) +# print(status) diff --git a/src/scripts/auto_start.py b/src/scripts/auto_start.py new file mode 100644 index 00000000..015db18e --- /dev/null +++ b/src/scripts/auto_start.py @@ -0,0 +1,57 @@ +# AutoStart ML Pipelines from preset file + +import os + +import supervisely as sly +from dotenv import load_dotenv + +load_dotenv(os.path.expanduser("~/supervisely.env")) +load_dotenv("local.env") + +team_id = sly.env.team_id() +workspace_id = sly.env.workspace_id() + +api: sly.Api = sly.Api.from_env() + +agent_id = 452 # 359 +app_slug = "supervisely-ecosystem/data-nodes" + +# preset_path = "/data-nodes/presets/images/preset.json" +preset_path = "/data-nodes/presets/images/api_pipeline.json" + +module_id = api.app.get_ecosystem_module_id(app_slug) +module_info = api.app.get_ecosystem_module_info(module_id) + + +params = {"modalityType": "images", "slyFile": preset_path} + +# app_params = { +# "agent_id": agent_id, +# # "app_id": 0, +# "module_id": module_id, +# "workspace_id": workspace_id, +# "description": "Start ML Pipelines from py", +# "task_name": "ML Pipelines", +# "params": {"autostart": False, **params}, +# "app_version": None, +# "is_branch": False, +# } + +app_params = { + "agent_id": agent_id, + # "app_id": 0, + "module_id": module_id, + "workspace_id": workspace_id, + "description": "Start ML Pipelines from API", + "task_name": "ML Pipelines", + "params": {"autostart": False, **params}, + "app_version": "run-from-api", + "is_branch": True, +} + +session_info = api.app.start(**app_params) + +# Run pipeline +is_ready = api.app.wait_until_ready_for_api_calls(session_info.task_id) +if is_ready: + api.task.send_request(task_id=session_info.task_id, method="run_pipeline", data={})