|
16 | 16 | """Classes for working with vision models."""
|
17 | 17 |
|
18 | 18 | import base64
|
19 |
| -import collections |
20 | 19 | import dataclasses
|
21 |
| -import io |
22 |
| -import json |
23 |
| -import os |
24 |
| -import pathlib |
25 | 20 | import typing
|
26 |
| -from typing import Any, Dict, List, Literal, Optional, Union |
| 21 | +from typing import List, Literal, Optional |
27 | 22 |
|
28 | 23 | from google.generativeai import client
|
29 | 24 | 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 |
| - |
51 | 25 |
|
52 | 26 | AspectRatio = Literal["1:1", "9:16", "16:9", "4:3", "3:4"]
|
53 | 27 | ASPECT_RATIOS = AspectRatio.__args__ # type: ignore
|
@@ -206,7 +180,7 @@ def _generate_images(
|
206 | 180 | model=self.model_name, instances=[instance], parameters=parameters
|
207 | 181 | )
|
208 | 182 |
|
209 |
| - generated_images: List["GeneratedImage"] = [] |
| 183 | + generated_images: List[image_types.GeneratedImage] = [] |
210 | 184 | for idx, prediction in enumerate(response.predictions):
|
211 | 185 | generation_parameters = dict(shared_generation_parameters)
|
212 | 186 | generation_parameters["index_of_image_in_batch"] = idx
|
@@ -288,13 +262,12 @@ class ImageGenerationResponse:
|
288 | 262 |
|
289 | 263 | __module__ = "vertexai.preview.vision_models"
|
290 | 264 |
|
291 |
| - images: List["GeneratedImage"] |
| 265 | + images: List[image_types.GeneratedImage] |
292 | 266 |
|
293 |
| - def __iter__(self) -> typing.Iterator["GeneratedImage"]: |
| 267 | + def __iter__(self) -> typing.Iterator[image_types.GeneratedImage]: |
294 | 268 | """Iterates through the generated images."""
|
295 | 269 | yield from self.images
|
296 | 270 |
|
297 |
| - def __getitem__(self, idx: int) -> "GeneratedImage": |
| 271 | + def __getitem__(self, idx: int) -> image_types.GeneratedImage: |
298 | 272 | """Gets the generated image by index."""
|
299 | 273 | return self.images[idx]
|
300 |
| - |
0 commit comments