Skip to content

Commit cdcd4f5

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add enhance_input_image and image_preservation_factor fields for upscale_image
PiperOrigin-RevId: 775438709
1 parent 91e7246 commit cdcd4f5

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

google/genai/models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,6 +2862,20 @@ def _UpscaleImageAPIConfig_to_vertex(
28622862
getv(from_object, ['output_compression_quality']),
28632863
)
28642864

2865+
if getv(from_object, ['enhance_input_image']) is not None:
2866+
setv(
2867+
parent_object,
2868+
['parameters', 'upscaleConfig', 'enhanceInputImage'],
2869+
getv(from_object, ['enhance_input_image']),
2870+
)
2871+
2872+
if getv(from_object, ['image_preservation_factor']) is not None:
2873+
setv(
2874+
parent_object,
2875+
['parameters', 'upscaleConfig', 'imagePreservationFactor'],
2876+
getv(from_object, ['image_preservation_factor']),
2877+
)
2878+
28652879
if getv(from_object, ['number_of_images']) is not None:
28662880
setv(
28672881
parent_object,
@@ -6240,6 +6254,10 @@ def upscale_image(
62406254
output_compression_quality=config_dct.get(
62416255
'output_compression_quality', None
62426256
),
6257+
enhance_input_image=config_dct.get('enhance_input_image', None),
6258+
image_preservation_factor=config_dct.get(
6259+
'image_preservation_factor', None
6260+
),
62436261
) # pylint: disable=protected-access
62446262

62456263
# Provide default values through API config.
@@ -7832,6 +7850,10 @@ async def upscale_image(
78327850
output_compression_quality=config_dct.get(
78337851
'output_compression_quality', None
78347852
),
7853+
enhance_input_image=config_dct.get('enhance_input_image', None),
7854+
image_preservation_factor=config_dct.get(
7855+
'image_preservation_factor', None
7856+
),
78357857
) # pylint: disable=protected-access
78367858

78377859
# Provide default values through API config.

google/genai/tests/models/test_upscale_image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
'include_rai_reason': True,
5151
'output_mime_type': 'image/jpeg',
5252
'output_compression_quality': 80,
53+
'enhance_input_image': True,
54+
'image_preservation_factor': 0.6,
5355
},
5456
),
5557
),
@@ -94,6 +96,8 @@ async def test_upscale_async(client):
9496
'include_rai_reason': True,
9597
'output_mime_type': 'image/jpeg',
9698
'output_compression_quality': 80,
99+
'enhance_input_image': True,
100+
'image_preservation_factor': 0.6,
97101
},
98102
)
99103
assert response.generated_images[0].image.image_bytes

google/genai/types.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6282,6 +6282,19 @@ class _UpscaleImageAPIConfig(_common.BaseModel):
62826282
description="""The level of compression if the ``output_mime_type`` is
62836283
``image/jpeg``.""",
62846284
)
6285+
enhance_input_image: Optional[bool] = Field(
6286+
default=None,
6287+
description="""Whether to add an image enhancing step before upscaling.
6288+
It is expected to suppress the noise and JPEG compression artifacts
6289+
from the input image.""",
6290+
)
6291+
image_preservation_factor: Optional[float] = Field(
6292+
default=None,
6293+
description="""With a higher image preservation factor, the original image
6294+
pixels are more respected. With a lower image preservation factor, the
6295+
output image will have be more different from the input image, but
6296+
with finer details and less noise.""",
6297+
)
62856298
number_of_images: Optional[int] = Field(default=None, description="""""")
62866299
mode: Optional[str] = Field(default=None, description="""""")
62876300

@@ -6307,6 +6320,17 @@ class _UpscaleImageAPIConfigDict(TypedDict, total=False):
63076320
"""The level of compression if the ``output_mime_type`` is
63086321
``image/jpeg``."""
63096322

6323+
enhance_input_image: Optional[bool]
6324+
"""Whether to add an image enhancing step before upscaling.
6325+
It is expected to suppress the noise and JPEG compression artifacts
6326+
from the input image."""
6327+
6328+
image_preservation_factor: Optional[float]
6329+
"""With a higher image preservation factor, the original image
6330+
pixels are more respected. With a lower image preservation factor, the
6331+
output image will have be more different from the input image, but
6332+
with finer details and less noise."""
6333+
63106334
number_of_images: Optional[int]
63116335
""""""
63126336

@@ -10518,6 +10542,19 @@ class UpscaleImageConfig(_common.BaseModel):
1051810542
description="""The level of compression if the ``output_mime_type`` is
1051910543
``image/jpeg``.""",
1052010544
)
10545+
enhance_input_image: Optional[bool] = Field(
10546+
default=None,
10547+
description="""Whether to add an image enhancing step before upscaling.
10548+
It is expected to suppress the noise and JPEG compression artifacts
10549+
from the input image.""",
10550+
)
10551+
image_preservation_factor: Optional[float] = Field(
10552+
default=None,
10553+
description="""With a higher image preservation factor, the original image
10554+
pixels are more respected. With a lower image preservation factor, the
10555+
output image will have be more different from the input image, but
10556+
with finer details and less noise.""",
10557+
)
1052110558

1052210559

1052310560
class UpscaleImageConfigDict(TypedDict, total=False):
@@ -10542,6 +10579,17 @@ class UpscaleImageConfigDict(TypedDict, total=False):
1054210579
"""The level of compression if the ``output_mime_type`` is
1054310580
``image/jpeg``."""
1054410581

10582+
enhance_input_image: Optional[bool]
10583+
"""Whether to add an image enhancing step before upscaling.
10584+
It is expected to suppress the noise and JPEG compression artifacts
10585+
from the input image."""
10586+
10587+
image_preservation_factor: Optional[float]
10588+
"""With a higher image preservation factor, the original image
10589+
pixels are more respected. With a lower image preservation factor, the
10590+
output image will have be more different from the input image, but
10591+
with finer details and less noise."""
10592+
1054510593

1054610594
UpscaleImageConfigOrDict = Union[UpscaleImageConfig, UpscaleImageConfigDict]
1054710595

0 commit comments

Comments
 (0)