Source code for docarray.dataclasses.getter
from typing import TYPE_CHECKING
from docarray.dataclasses.enums import DocumentMetadata, ImageType
if TYPE_CHECKING: # pragma: no cover
from docarray import Document
[docs]def image_getter(doc: 'Document'):
if doc._metadata[DocumentMetadata.IMAGE_TYPE] == ImageType.URI:
return doc.uri
elif doc._metadata[DocumentMetadata.IMAGE_TYPE] == ImageType.PIL:
from PIL import Image
return Image.fromarray(doc.tensor)
elif doc._metadata[DocumentMetadata.IMAGE_TYPE] == ImageType.NDARRAY:
return doc.tensor