Skip to content

Commit

Permalink
Enhance error handling in pipeline execution and remove outdated API …
Browse files Browse the repository at this point in the history
…request script
  • Loading branch information
cxnt committed Nov 15, 2024
1 parent 3223706 commit f91a7c7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
5 changes: 4 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from src.ui.ui import layout, header
from src.ui.tabs.configure import update_state, update_nodes, nodes_flow
from src.ui.tabs.presets import load_json
from src.ui.tabs.run import run_btn_clicked, progress, circle_progress
from src.ui.tabs.run import run_btn_clicked, error_notification, circle_progress

from src.ui.dtl.Layer import Layer
from src.ui.dtl.actions.input.images_project.images_project import ImagesProjectAction
Expand Down Expand Up @@ -205,6 +205,9 @@ def run_pipeline_from_api(response: Response, request: Request):
run_btn_clicked()
return {"result": "pipeline was successfully processed"}
except Exception as e:
error_notification.set("Error", description=str(e))
error_notification.show()
circle_progress.set_status("exception")
raise e


Expand Down
36 changes: 13 additions & 23 deletions src/scripts/auto_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,35 @@

api: sly.Api = sly.Api.from_env()

agent_id = 452 # 359
agent_id = 555 # <- replace with your agent_id
app_slug = "supervisely-ecosystem/data-nodes"

# preset_path = "/data-nodes/presets/images/preset.json"
preset_path = "/data-nodes/presets/images/api_pipeline.json"
preset_path = "/data-nodes/presets/images/preset.json" # <- replace with your preset path

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",
"description": "Start ML Pipelines from py",
"task_name": "ML Pipelines",
"params": {"autostart": False, **params},
"app_version": "run-from-api",
"is_branch": True,
"app_version": None,
"is_branch": False,
}

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={})
# Uncomment to run pipeline after starting
# 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={})

# Use to check pipeline progress
# status = api.task.send_request(task_id=task_id, method="get_pipeline_status", data={})
# print(status)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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")
# 1. run_pipeline - runs a pipeline with current layers on the canvas
# 2. get_pipeline_status - returns the status of the pipeline ("Pipeline status is 21/50")

import os

Expand All @@ -16,13 +16,12 @@

api: sly.Api = sly.Api.from_env()

task_id = 68139
task_id = 55555 # <- replace with your task_id

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={})
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={})

# Use to check pipeline progress
# status = api.task.send_request(task_id=task_id, method="get_pipeline_status", data={})
# print(status)
1 change: 1 addition & 0 deletions src/ui/tabs/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def run_pipeline(run_dialog: Dialog = None):


def start_pipeline(run_dialog: Dialog = None):
g.current = 0
g.total = 0
if g.pipeline_thread is not None or g.pipeline_running is True:
error_notification.set(
Expand Down

0 comments on commit f91a7c7

Please sign in to comment.