|
8 | 8 | from typing import Any, Dict, Optional, Union
|
9 | 9 |
|
10 | 10 | from google.generativeai import protos
|
11 |
| -from google.generativeai import client |
12 | 11 |
|
13 | 12 | # pylint: disable=g-import-not-at-top
|
14 | 13 | if typing.TYPE_CHECKING:
|
|
38 | 37 | ImageType = Union["Image", "PIL.Image.Image", "IPython.display.Image"]
|
39 | 38 | # pylint: enable=g-import-not-at-top
|
40 | 39 |
|
41 |
| -__all__ = ["Image", "GeneratedImage", "check_watermark", "CheckWatermarkResult", "ImageType"] |
| 40 | +__all__ = ["Image", "GeneratedImage", "ImageType"] |
42 | 41 |
|
43 | 42 |
|
44 | 43 | def _pil_to_blob(image: PIL.Image.Image) -> protos.Blob:
|
@@ -121,46 +120,6 @@ def __bool__(self):
|
121 | 120 | raise ValueError(f"Unrecognized result: {decision}")
|
122 | 121 |
|
123 | 122 |
|
124 |
| -def check_watermark( |
125 |
| - img: Union[pathlib.Path, ImageType], model_id: str = "models/image-verification-001" |
126 |
| -) -> "CheckWatermarkResult": |
127 |
| - """Checks if an image has a Google-AI watermark. |
128 |
| -
|
129 |
| - Args: |
130 |
| - img: can be a `pathlib.Path` or a `PIL.Image.Image`, `IPython.display.Image`, or `google.generativeai.Image`. |
131 |
| - model_id: Which version of the image-verification model to send the image to. |
132 |
| -
|
133 |
| - Returns: |
134 |
| -
|
135 |
| - """ |
136 |
| - if isinstance(img, Image): |
137 |
| - pass |
138 |
| - elif isinstance(img, pathlib.Path): |
139 |
| - img = Image.load_from_file(img) |
140 |
| - elif IPython.display is not None and isinstance(img, IPython.display.Image): |
141 |
| - img = Image(image_bytes=img.data) |
142 |
| - elif PIL.Image is not None and isinstance(img, PIL.Image.Image): |
143 |
| - blob = _pil_to_blob(img) |
144 |
| - img = Image(image_bytes=blob.data) |
145 |
| - elif isinstance(img, protos.Blob): |
146 |
| - img = Image(image_bytes=img.data) |
147 |
| - else: |
148 |
| - raise TypeError( |
149 |
| - f"Not implemented: Could not convert a {type(img)} into `Image`\n {img=}" |
150 |
| - ) |
151 |
| - |
152 |
| - prediction_client = client.get_default_prediction_client() |
153 |
| - if not model_id.startswith("models/"): |
154 |
| - model_id = f"models/{model_id}" |
155 |
| - |
156 |
| - instance = {"image": {"bytesBase64Encoded": base64.b64encode(img._loaded_bytes).decode()}} |
157 |
| - parameters = {"watermarkVerification": True} |
158 |
| - |
159 |
| - response = prediction_client.predict( |
160 |
| - model=model_id, instances=[instance], parameters=parameters |
161 |
| - ) |
162 |
| - |
163 |
| - return CheckWatermarkResult(response.predictions) |
164 | 123 |
|
165 | 124 |
|
166 | 125 | class Image:
|
|
0 commit comments