Skip to content

Commit 170df6a

Browse files
committed
types + formatting
Change-Id: I0cac4ba1de764d3c02c5eab7556d8324aeda1f93
1 parent 8b2f214 commit 170df6a

File tree

2 files changed

+8
-35
lines changed

2 files changed

+8
-35
lines changed

google/generativeai/vision_models/_vision_models.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,12 @@
1616
"""Classes for working with vision models."""
1717

1818
import base64
19-
import collections
2019
import dataclasses
21-
import io
22-
import json
23-
import os
24-
import pathlib
2520
import typing
26-
from typing import Any, Dict, List, Literal, Optional, Union
21+
from typing import List, Literal, Optional
2722

2823
from google.generativeai import client
2924
from google.generativeai.types import image_types
30-
from google.generativeai import protos
31-
from google.generativeai.types import content_types
32-
33-
34-
# pylint: disable=g-import-not-at-top
35-
if typing.TYPE_CHECKING:
36-
from IPython import display as IPython_display
37-
else:
38-
try:
39-
from IPython import display as IPython_display
40-
except ImportError:
41-
IPython_display = None
42-
43-
if typing.TYPE_CHECKING:
44-
import PIL.Image as PIL_Image
45-
else:
46-
try:
47-
from PIL import Image as PIL_Image
48-
except ImportError:
49-
PIL_Image = None
50-
5125

5226
AspectRatio = Literal["1:1", "9:16", "16:9", "4:3", "3:4"]
5327
ASPECT_RATIOS = AspectRatio.__args__ # type: ignore
@@ -206,7 +180,7 @@ def _generate_images(
206180
model=self.model_name, instances=[instance], parameters=parameters
207181
)
208182

209-
generated_images: List["GeneratedImage"] = []
183+
generated_images: List[image_types.GeneratedImage] = []
210184
for idx, prediction in enumerate(response.predictions):
211185
generation_parameters = dict(shared_generation_parameters)
212186
generation_parameters["index_of_image_in_batch"] = idx
@@ -288,13 +262,12 @@ class ImageGenerationResponse:
288262

289263
__module__ = "vertexai.preview.vision_models"
290264

291-
images: List["GeneratedImage"]
265+
images: List[image_types.GeneratedImage]
292266

293-
def __iter__(self) -> typing.Iterator["GeneratedImage"]:
267+
def __iter__(self) -> typing.Iterator[image_types.GeneratedImage]:
294268
"""Iterates through the generated images."""
295269
yield from self.images
296270

297-
def __getitem__(self, idx: int) -> "GeneratedImage":
271+
def __getitem__(self, idx: int) -> image_types.GeneratedImage:
298272
"""Gets the generated image by index."""
299273
return self.images[idx]
300-

tests/test_content.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_numpy_to_blob(self, image):
100100
@parameterized.named_parameters(
101101
["PIL", PIL.Image.open(TEST_PNG_PATH)],
102102
["IPython", IPython.display.Image(filename=TEST_PNG_PATH)],
103-
["image_types.Image", image_types.Image.load_from_file(TEST_PNG_PATH)]
103+
["image_types.Image", image_types.Image.load_from_file(TEST_PNG_PATH)],
104104
)
105105
def test_png_to_blob(self, image):
106106
blob = _image_types.image_to_blob(image)
@@ -111,7 +111,7 @@ def test_png_to_blob(self, image):
111111
@parameterized.named_parameters(
112112
["PIL", PIL.Image.open(TEST_JPG_PATH)],
113113
["IPython", IPython.display.Image(filename=TEST_JPG_PATH)],
114-
["image_types.Image", image_types.Image.load_from_file(TEST_JPG_PATH)]
114+
["image_types.Image", image_types.Image.load_from_file(TEST_JPG_PATH)],
115115
)
116116
def test_jpg_to_blob(self, image):
117117
blob = _image_types.image_to_blob(image)
@@ -122,7 +122,7 @@ def test_jpg_to_blob(self, image):
122122
@parameterized.named_parameters(
123123
["PIL", PIL.Image.open(TEST_GIF_PATH)],
124124
["IPython", IPython.display.Image(filename=TEST_GIF_PATH)],
125-
["image_types.Image", image_types.Image.load_from_file(TEST_GIF_PATH)]
125+
["image_types.Image", image_types.Image.load_from_file(TEST_GIF_PATH)],
126126
)
127127
def test_gif_to_blob(self, image):
128128
blob = _image_types.image_to_blob(image)

0 commit comments

Comments
 (0)