mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 07:06:32 +00:00
fc57d677b4
- Updated various Cython files to explicitly cast types, enhancing type safety and readability. - Adjusted the `engine_name` property in `InferenceEngine` and its subclasses to be set directly in the constructor. - Modified the `request` method in `_SessionWithBase` to accept `*args` for better flexibility. - Ensured proper type casting for return values in methods across multiple classes, including `Inference`, `CoreMLEngine`, and `TensorRTEngine`. These changes aim to streamline the codebase and improve maintainability by enforcing consistent type usage.
45 lines
1.4 KiB
Cython
45 lines
1.4 KiB
Cython
cimport cython
|
|
cimport constants_inf
|
|
import msgpack
|
|
|
|
AIStatus2Text = {
|
|
AIAvailabilityEnum.NONE: "None",
|
|
AIAvailabilityEnum.DOWNLOADING: "Downloading",
|
|
AIAvailabilityEnum.CONVERTING: "Converting",
|
|
AIAvailabilityEnum.UPLOADING: "Uploading",
|
|
AIAvailabilityEnum.ENABLED: "Enabled",
|
|
AIAvailabilityEnum.WARNING: "Warning",
|
|
AIAvailabilityEnum.ERROR: "Error",
|
|
}
|
|
|
|
cdef class AIAvailabilityStatus:
|
|
def __init__(self):
|
|
self.status = AIAvailabilityEnum.NONE
|
|
self.error_message = ""
|
|
|
|
def __str__(self):
|
|
with self._lock:
|
|
status_text = AIStatus2Text.get(self.status, "Unknown")
|
|
error_text = self.error_message if self.error_message else ""
|
|
return f"{status_text} {error_text}"
|
|
|
|
cdef bytes serialize(self):
|
|
with self._lock:
|
|
return <bytes>msgpack.packb({
|
|
"s": self.status,
|
|
"m": self.error_message
|
|
})
|
|
|
|
cdef set_status(self, int status, str error_message=""):
|
|
log_message = ""
|
|
with self._lock:
|
|
self.status = status
|
|
self.error_message = error_message
|
|
status_text = AIStatus2Text.get(self.status, "Unknown")
|
|
error_text = self.error_message if self.error_message else ""
|
|
log_message = f"{status_text} {error_text}"
|
|
|
|
if error_message:
|
|
constants_inf.logerror(<str>error_message)
|
|
else:
|
|
constants_inf.log(<str>log_message) |