Skip to content

Commit dd6cc0d

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add safety_filter_level and person_generation for Imagen upscaling
PiperOrigin-RevId: 819915543
1 parent ac2bc42 commit dd6cc0d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

google/genai/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,6 +3516,20 @@ def _UpscaleImageAPIConfig_to_vertex(
35163516
getv(from_object, ['output_gcs_uri']),
35173517
)
35183518

3519+
if getv(from_object, ['safety_filter_level']) is not None:
3520+
setv(
3521+
parent_object,
3522+
['parameters', 'safetySetting'],
3523+
getv(from_object, ['safety_filter_level']),
3524+
)
3525+
3526+
if getv(from_object, ['person_generation']) is not None:
3527+
setv(
3528+
parent_object,
3529+
['parameters', 'personGeneration'],
3530+
getv(from_object, ['person_generation']),
3531+
)
3532+
35193533
if getv(from_object, ['include_rai_reason']) is not None:
35203534
setv(
35213535
parent_object,
@@ -5376,6 +5390,8 @@ def upscale_image(
53765390
api_config = types._UpscaleImageAPIConfigDict(
53775391
http_options=config_dct.get('http_options', None),
53785392
output_gcs_uri=config_dct.get('output_gcs_uri', None),
5393+
safety_filter_level=config_dct.get('safety_filter_level', None),
5394+
person_generation=config_dct.get('person_generation', None),
53795395
include_rai_reason=config_dct.get('include_rai_reason', None),
53805396
output_mime_type=config_dct.get('output_mime_type', None),
53815397
output_compression_quality=config_dct.get(
@@ -7198,6 +7214,8 @@ async def upscale_image(
71987214
api_config = types._UpscaleImageAPIConfigDict(
71997215
http_options=config_dct.get('http_options', None),
72007216
output_gcs_uri=config_dct.get('output_gcs_uri', None),
7217+
safety_filter_level=config_dct.get('safety_filter_level', None),
7218+
person_generation=config_dct.get('person_generation', None),
72017219
include_rai_reason=config_dct.get('include_rai_reason', None),
72027220
output_mime_type=config_dct.get('output_mime_type', None),
72037221
output_compression_quality=config_dct.get(

google/genai/tests/models/test_upscale_image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
upscale_factor='x2',
5050
config=types.UpscaleImageConfig(
5151
include_rai_reason=True,
52+
person_generation=types.PersonGeneration.ALLOW_ADULT,
53+
safety_filter_level=types.SafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
5254
output_mime_type='image/jpeg',
5355
output_compression_quality=80,
5456
enhance_input_image=True,
@@ -107,6 +109,8 @@ async def test_upscale_async(client):
107109
image=types.Image.from_file(location=IMAGE_FILE_PATH),
108110
upscale_factor='x2',
109111
config=types.UpscaleImageConfig(
112+
person_generation=types.PersonGeneration.ALLOW_ADULT,
113+
safety_filter_level=types.SafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
110114
include_rai_reason=True,
111115
output_mime_type='image/jpeg',
112116
output_compression_quality=80,

google/genai/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7283,6 +7283,12 @@ class _UpscaleImageAPIConfig(_common.BaseModel):
72837283
default=None,
72847284
description="""Cloud Storage URI used to store the generated images.""",
72857285
)
7286+
safety_filter_level: Optional[SafetyFilterLevel] = Field(
7287+
default=None, description="""Filter level for safety filtering."""
7288+
)
7289+
person_generation: Optional[PersonGeneration] = Field(
7290+
default=None, description="""Allows generation of people by the model."""
7291+
)
72867292
include_rai_reason: Optional[bool] = Field(
72877293
default=None,
72887294
description="""Whether to include a reason for filtered-out images in the
@@ -7331,6 +7337,12 @@ class _UpscaleImageAPIConfigDict(TypedDict, total=False):
73317337
output_gcs_uri: Optional[str]
73327338
"""Cloud Storage URI used to store the generated images."""
73337339

7340+
safety_filter_level: Optional[SafetyFilterLevel]
7341+
"""Filter level for safety filtering."""
7342+
7343+
person_generation: Optional[PersonGeneration]
7344+
"""Allows generation of people by the model."""
7345+
73347346
include_rai_reason: Optional[bool]
73357347
"""Whether to include a reason for filtered-out images in the
73367348
response."""
@@ -13247,6 +13259,12 @@ class UpscaleImageConfig(_common.BaseModel):
1324713259
default=None,
1324813260
description="""Cloud Storage URI used to store the generated images.""",
1324913261
)
13262+
safety_filter_level: Optional[SafetyFilterLevel] = Field(
13263+
default=None, description="""Filter level for safety filtering."""
13264+
)
13265+
person_generation: Optional[PersonGeneration] = Field(
13266+
default=None, description="""Allows generation of people by the model."""
13267+
)
1325013268
include_rai_reason: Optional[bool] = Field(
1325113269
default=None,
1325213270
description="""Whether to include a reason for filtered-out images in the
@@ -13294,6 +13312,12 @@ class UpscaleImageConfigDict(TypedDict, total=False):
1329413312
output_gcs_uri: Optional[str]
1329513313
"""Cloud Storage URI used to store the generated images."""
1329613314

13315+
safety_filter_level: Optional[SafetyFilterLevel]
13316+
"""Filter level for safety filtering."""
13317+
13318+
person_generation: Optional[PersonGeneration]
13319+
"""Allows generation of people by the model."""
13320+
1329713321
include_rai_reason: Optional[bool]
1329813322
"""Whether to include a reason for filtered-out images in the
1329913323
response."""

0 commit comments

Comments
 (0)