diff --git a/google/generativeai/types/image_types/_image_types.py b/google/generativeai/types/image_types/_image_types.py index ddfea057f..f23c343aa 100644 --- a/google/generativeai/types/image_types/_image_types.py +++ b/google/generativeai/types/image_types/_image_types.py @@ -8,7 +8,6 @@ from typing import Any, Dict, Optional, Union from google.generativeai import protos -from google.generativeai import client # pylint: disable=g-import-not-at-top if typing.TYPE_CHECKING: @@ -38,7 +37,7 @@ ImageType = Union["Image", "PIL.Image.Image", "IPython.display.Image"] # pylint: enable=g-import-not-at-top -__all__ = ["Image", "GeneratedImage", "check_watermark", "CheckWatermarkResult", "ImageType"] +__all__ = ["Image", "GeneratedImage", "ImageType"] def _pil_to_blob(image: PIL.Image.Image) -> protos.Blob: @@ -121,48 +120,6 @@ def __bool__(self): raise ValueError(f"Unrecognized result: {decision}") -def check_watermark( - img: Union[pathlib.Path, ImageType], model_id: str = "models/image-verification-001" -) -> "CheckWatermarkResult": - """Checks if an image has a Google-AI watermark. - - Args: - img: can be a `pathlib.Path` or a `PIL.Image.Image`, `IPython.display.Image`, or `google.generativeai.Image`. - model_id: Which version of the image-verification model to send the image to. - - Returns: - - """ - if isinstance(img, Image): - pass - elif isinstance(img, pathlib.Path): - img = Image.load_from_file(img) - elif IPython.display is not None and isinstance(img, IPython.display.Image): - img = Image(image_bytes=img.data) - elif PIL.Image is not None and isinstance(img, PIL.Image.Image): - blob = _pil_to_blob(img) - img = Image(image_bytes=blob.data) - elif isinstance(img, protos.Blob): - img = Image(image_bytes=img.data) - else: - raise TypeError( - f"Not implemented: Could not convert a {type(img)} into `Image`\n {img=}" - ) - - prediction_client = client.get_default_prediction_client() - if not model_id.startswith("models/"): - model_id = f"models/{model_id}" - - instance = {"image": {"bytesBase64Encoded": base64.b64encode(img._loaded_bytes).decode()}} - parameters = {"watermarkVerification": True} - - response = prediction_client.predict( - model=model_id, instances=[instance], parameters=parameters - ) - - return CheckWatermarkResult(response.predictions) - - class Image: """Image.""" @@ -257,8 +214,6 @@ def _as_base64_string(self) -> str: def _repr_png_(self): return self._pil_image._repr_png_() # type:ignore - check_watermark = check_watermark - _EXIF_USER_COMMENT_TAG_IDX = 0x9286 _IMAGE_GENERATION_PARAMETERS_EXIF_KEY = ( diff --git a/google/generativeai/vision_models/__init__.py b/google/generativeai/vision_models/__init__.py index e1b62d39b..c0ab97b9c 100644 --- a/google/generativeai/vision_models/__init__.py +++ b/google/generativeai/vision_models/__init__.py @@ -14,7 +14,7 @@ # """Classes for working with vision models.""" -from google.generativeai.types.image_types import check_watermark, Image, GeneratedImage +from google.generativeai.types.image_types import Image, GeneratedImage from google.generativeai.vision_models._vision_models import ( ImageGenerationModel, @@ -22,7 +22,6 @@ ) __all__ = [ - "check_watermark", "Image", "GeneratedImage", "ImageGenerationModel",