Skip to content

Commit

Permalink
Add auto_start example scripts, update min instance version in config
Browse files Browse the repository at this point in the history
  • Loading branch information
cxnt committed Nov 15, 2024
1 parent 4f09653 commit 3223706
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"files_file"
]
},
"instance_version": "6.11.22"
"instance_version": "6.12.8"
}
2 changes: 2 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions src/scripts/api_request.py
Original file line number Diff line number Diff line change
@@ -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)
57 changes: 57 additions & 0 deletions src/scripts/auto_start.py
Original file line number Diff line number Diff line change
@@ -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={})

0 comments on commit 3223706

Please sign in to comment.