Skip to content

Commit

Permalink
Merge pull request #58 from mistralai/skip_cv_import_errors
Browse files Browse the repository at this point in the history
[cv2] Make sure broken environments don't lead to errors
  • Loading branch information
patrickvonplaten authored Sep 29, 2024
2 parents ce9ce79 + f66340b commit 21ee9f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mistral_common"
version = "1.4.3"
version = "1.4.4"
description = ""
authors = ["bam4d <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/mistral_common/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4.3"
__version__ = "1.4.4"
12 changes: 12 additions & 0 deletions src/mistral_common/tokens/tokenizers/multimodal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import logging
from dataclasses import dataclass
from io import BytesIO
from typing import Tuple, Union
Expand All @@ -14,13 +15,24 @@
SpecialImageIDs,
)

logger = logging.getLogger(__name__)


_cv2_installed: bool
try:
import cv2

_cv2_installed = True
except ImportError:
_cv2_installed = False
except Exception as e:
# cv2 has lots of import problems: https://github.com/opencv/opencv-python/issues/884
# for better UX, let's simply skip all errors that might arise from import for now
logger.warning(
f"Warning: Your installation of OpenCV appears to be broken: {e}."
"Please follow the instructions at https://github.com/opencv/opencv-python/issues/884 "
"to correct your environment. The import of cv2 has been skipped."
)


def is_cv2_installed() -> bool:
Expand Down

0 comments on commit 21ee9f6

Please sign in to comment.