From ea19648429be5c850c49c8717651bc21f63bb499 Mon Sep 17 00:00:00 2001 From: almaz Date: Tue, 21 Nov 2023 19:42:55 +0100 Subject: [PATCH] update logging --- project-dataset/src/main.py | 10 ++-------- shared_utils/connect.py | 10 ++++++++++ shared_utils/ui2.py | 5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/project-dataset/src/main.py b/project-dataset/src/main.py index a9950b6..978657a 100644 --- a/project-dataset/src/main.py +++ b/project-dataset/src/main.py @@ -6,7 +6,7 @@ from shared_utils.connect import get_model_info, log_settings from shared_utils.inference import postprocess -from shared_utils.ui2 import clean_error, set_error +from shared_utils.ui2 import clean_error import init_ui as ui import sliding_window @@ -20,13 +20,7 @@ def connect(api: sly.Api, task_id, context, state, app_logger): clean_error(api, task_id) g.model_meta, g.model_info = get_model_info(api, task_id, context, state, app_logger) - if g.model_meta is None: - set_error( - api, - task_id, - "Couldn't get model info. Please, make sure that model is running and try again.", - ) - else: + if g.model_meta is not None: actual_ui_state = api.task.get_field(task_id, "state") preview(api, task_id, context, actual_ui_state, app_logger) diff --git a/shared_utils/connect.py b/shared_utils/connect.py index 38f3125..26b752d 100644 --- a/shared_utils/connect.py +++ b/shared_utils/connect.py @@ -12,6 +12,16 @@ def get_model_info(api: sly.Api, task_id, context, state, app_logger) -> sly.Pro info["session"] = state["sessionId"] app_logger.debug("Session Info", extra={"info": info}) + except Exception as e: + ui.set_error( + api, + task_id, + "Couldn't get model info. Make sure that model is deployed and try again.", + log_error=False, + ) + return model_meta, info + + try: meta_json = api.task.send_request( state["sessionId"], "get_output_classes_and_tags", data={} ) diff --git a/shared_utils/ui2.py b/shared_utils/ui2.py index a5c0f0d..cd5036e 100644 --- a/shared_utils/ui2.py +++ b/shared_utils/ui2.py @@ -25,8 +25,9 @@ def set_model_info(api: sly.Api, task_id, model_meta: sly.ProjectMeta, model_inf api.task.set_fields(task_id, fields) -def set_error(api: sly.Api, task_id, e: Exception): - sly.logger.error(repr(e)) +def set_error(api: sly.Api, task_id, e: Exception, log_error: bool = True): + if log_error: + sly.logger.error(repr(e)) fields = [ {"field": "data.connected", "payload": False}, {"field": "data.connectionError", "payload": repr(e)},