This commit is contained in:
stuart committed 2025-12-27 23:26:16 +01:00
commit 57f30b04c1
1 file changed
+8 -11
+8 -11
View File
@@ -11,22 +11,19 @@ import base64
class Symbol:
id: int
label: str
image: Tensor[np.ndarray[Any, Any], tuple, Literal["int32", "int64"]]
image: bytes
@classmethod
def from_dict(cls, data: dict) -> "Symbol":
# if isinstance(data["image"], str):
# # Decode from base64
# image_bytes = base64.b64decode(data["image"])
# image_array = np.frombuffer(image_bytes, dtype=np.uint8)
# else:
# # From list/array
# image_array = np.array(data["image"], dtype=np.int32)
image_data=data["image"].encode("utf-8")
if isinstance(data["image"], str):
image_bytes = base64.b64decode(data["image"])
else:
image_bytes = bytes(data["image"])
return cls(
id=data["id"],
label=data["label"],
image=image_data,
image=image_bytes,
)
@classmethod
@@ -46,7 +43,7 @@ class Symbol:
lambda x: {
"id": x.id,
"label": x.label,
"image": x.image.decode("utf-8"),
"image": base64.b64encode(x.image).decode("utf-8"),
},
when_used="json",
),