Skip to content

Commit

Permalink
Error UI notification added for request exceptions (#53)
Browse files Browse the repository at this point in the history
* wip

* move button to sly-notification field

* remove unnecessary line

---------

Co-authored-by: vorozhkog <vorozkhog@icloud.com>
  • Loading branch information
vorozhkog and vorozhkog authored Aug 1, 2024
1 parent 64d374d commit daa8c79
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion annotation-tool/debug.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PYTHONUNBUFFERED=1
LOG_LEVEL="trace"

TASK_ID=63377 # ⬅️ change value (run 'While True Script' app and copy task ID)
TASK_ID=63428 # ⬅️ change value (run 'While True Script' app and copy task ID)

context.userId=328 # ⬅️ change value
context.teamId=570 # ⬅️ change value
Expand Down
18 changes: 13 additions & 5 deletions annotation-tool/src/gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,19 @@
</div>

</div>
<sly-notification
v-if="data.inferenceError.length > 0"
:options="{'name': 'Inference Error', 'type': 'error'}"
:content="data.inferenceError">
</sly-notification>
<div class="mb10" v-if="data.inferenceError.length > 0">
<sly-notification
:options="{'name': 'Inference Error', 'type': 'error'}"
:content="data.inferenceError">
<div v-if="data.servingLink.length > 0">
<a :href="data.servingLink" target="_blank">
<el-button type="primary" size="mini" class="mt10"> Open Serving App </el-button>
</a>
</div>
</sly-notification>

</div>


<div><b>SETTINGS:</b></div>
<el-tabs class="small" v-model="state.tabName">
Expand Down
1 change: 1 addition & 0 deletions annotation-tool/src/init_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def init_ui(data, state):
data["connected"] = False
data["connectionError"] = ""
data["inferenceError"] = ""
data["servingLink"] = ""
data["rollbackIds"] = []
data["ssOptions"] = {
"sessionTags": [
Expand Down
12 changes: 8 additions & 4 deletions annotation-tool/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pathlib
import sys
from collections import defaultdict
from requests.exceptions import HTTPError


import supervisely as sly
import yaml
Expand Down Expand Up @@ -342,10 +344,12 @@ def inference(api: sly.Api, task_id, context, state, app_logger):
"settings": str(data["settings"]),
},
)
# sly.logger.warn(
# f"Couldn't process annotation prediction for image: {image_info.name} (ID: {image_id}). Image remain unchanged. Error: {e}"
# )
set_error(api, task_id, e, "inference", log_error=False)
if isinstance(e, HTTPError):
error_msg = f"Error sending request to the serving application. Please, make sure that session you are trying to connect to is running."
set_error(api, task_id, error_msg, "inference", state["sessionId"], log_error=False)
else:
error_msg = f"Couldn't process annotation prediction for image: {image_info.name} (ID: {image_id}). Image remain unchanged. Error: {e}"
set_error(api, task_id, error_msg, "inference", log_error=False)
empty_ann_json = sly.Annotation(img_size=(image_info.height, image_info.width)).to_json()
ann_pred_json = {"annotation": empty_ann_json}

Expand Down
7 changes: 7 additions & 0 deletions shared_utils/ui2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def set_model_info(
{"field": "data.connected", "payload": True},
{"field": "data.connectionError", "payload": ""},
{"field": "data.inferenceError", "payload": ""},
{"field": "data.servingLink", "payload": ""},
{"field": "state.settings", "payload": inf_settings["settings"]},
{"field": "state.disabledSW", "payload": disabledSW},
]
Expand All @@ -36,6 +37,7 @@ def set_error(
task_id,
e: Union[Exception, str],
error_type: Literal["connection", "inference"] = "connection",
session_id: str = None,
log_error: bool = True,
):
err = e if isinstance(e, str) else repr(e)
Expand All @@ -48,13 +50,18 @@ def set_error(
]
if error_type == "connection":
fields.append({"field": "data.connected", "payload": False})
elif error_type == "inference" and session_id is not None:
serving_app_link = f"{api.server_address}/apps/sessions/{session_id}"
fields.append({"field": "data.servingLink", "payload": serving_app_link})

api.task.set_fields(task_id, fields)


def clean_error(api: sly.Api, task_id):
fields = [
{"field": "data.connectionError", "payload": ""},
{"field": "data.inferenceError", "payload": ""},
{"field": "data.servingLink", "payload": ""},
]
api.task.set_fields(task_id, fields)

Expand Down

0 comments on commit daa8c79

Please sign in to comment.