Skip to content

Commit

Permalink
Merge pull request #1284 from neptune-ai/aw/fix_jpeg_reco
Browse files Browse the repository at this point in the history
fix image recognition
  • Loading branch information
AleksanderWWW committed Mar 3, 2023
2 parents c547756 + 1a8cb8a commit af86b1e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/neptune/attributes/series/file_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
__all__ = ["FileSeries"]

import imghdr
import io
import os
import pathlib
from typing import (
Expand All @@ -24,6 +24,11 @@
Optional,
)

from PIL import (
Image,
UnidentifiedImageError,
)

from neptune.attributes.series.series import Series
from neptune.exceptions import (
FileNotFound,
Expand Down Expand Up @@ -77,8 +82,10 @@ def _get_base64_image_content(file: File) -> str:
else:
file_content = file.content

ext = imghdr.what("", h=file_content)
if not ext:
try:
with Image.open(io.BytesIO(file_content)):
...
except UnidentifiedImageError:
raise OperationNotSupported(
"FileSeries supports only image files for now. Other file types will be implemented in future."
)
Expand Down

0 comments on commit af86b1e

Please sign in to comment.