Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev committed Nov 21, 2023
1 parent 3dde2ea commit ea19648
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 2 additions & 8 deletions project-dataset/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions shared_utils/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}
)
Expand Down
5 changes: 3 additions & 2 deletions shared_utils/ui2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down

0 comments on commit ea19648

Please sign in to comment.