Skip to content

Commit b1d5007

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Vision Models - Add new safety filter levels to Vertex AI Image Generation API.
The new levels are: * block_low_and_above * block_medium_and_above * block_only_high * block_none The new levels are functionally equivalent to the older supported levels with roughly this mapping * block_most == block_low_and_above * block_some == block_medium_and_above * block_few == block_only_high * block_fewest == block_none PiperOrigin-RevId: 683768231
1 parent 1e49799 commit b1d5007

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

tests/unit/aiplatform/test_vision_models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,18 @@ def test_generate_images_requests_add_watermark(self):
649649
assert actual_parameters["addWatermark"]
650650

651651
def test_generate_images_requests_safety_filter_level(self):
652-
"""Tests that the model class applies safety filter levels"""
652+
"""Tests that the model class applies safety filter levels."""
653653
model = self._get_image_generation_model()
654654

655655
safety_filter_levels = [
656656
"block_most",
657657
"block_some",
658658
"block_few",
659659
"block_fewest",
660+
"block_low_and_above",
661+
"block_medium_and_above",
662+
"block_only_high",
663+
"block_none",
660664
]
661665

662666
for level in safety_filter_levels:

vertexai/vision_models/_vision_models.py

+38-14
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,16 @@ def _generate_images(
383383
output_gcs_uri: Optional[str] = None,
384384
add_watermark: Optional[bool] = None,
385385
safety_filter_level: Optional[
386-
Literal["block_most", "block_some", "block_few", "block_fewest"]
386+
Literal[
387+
"block_most",
388+
"block_some",
389+
"block_few",
390+
"block_fewest",
391+
"block_low_and_above",
392+
"block_medium_and_above",
393+
"block_only_high",
394+
"block_none",
395+
]
387396
] = None,
388397
person_generation: Optional[
389398
Literal["dont_allow", "allow_adult", "allow_all"]
@@ -411,11 +420,13 @@ def _generate_images(
411420
base_image: Base image to use for the image generation.
412421
mask: Mask for the base image.
413422
edit_mode: Describes the editing mode for the request. Supported values
414-
are - * inpainting-insert: fills the mask area based on the text
415-
prompt (requires mask and text) * inpainting-remove: removes the
416-
object(s) in the mask area. (requires mask)
423+
are -
424+
* inpainting-insert: fills the mask area based on the text
425+
prompt (requires mask and text)
426+
* inpainting-remove: removes the object(s) in the mask area. (requires mask)
417427
* outpainting: extend the image based on the mask area. (Requires
418-
mask) * product-image: Changes the background for the predominant
428+
mask)
429+
* product-image: Changes the background for the predominant
419430
product or subject in the image
420431
mask_mode: Solicits generation of the mask (v/s providing mask as an
421432
input). Supported values are:
@@ -433,8 +444,9 @@ class ID
433444
* fixed: Fixed position
434445
* reposition: Can be moved (default)
435446
output_mime_type: Which image format should the output be saved as.
436-
Supported values: * image/png: Save as a PNG image * image/jpeg: Save
437-
as a JPEG image
447+
Supported values:
448+
* image/png: Save as a PNG image
449+
* image/jpeg: Save as a JPEG image
438450
compression_quality: Level of compression if the output mime type is
439451
selected to be image/jpeg. Float between 0 to 100
440452
language: Language of the text prompt for the image. Default: None.
@@ -444,14 +456,26 @@ class ID
444456
output_gcs_uri: Google Cloud Storage uri to store the generated images.
445457
add_watermark: Add a watermark to the generated image
446458
safety_filter_level: Adds a filter level to Safety filtering. Supported
447-
values are: * "block_most" : Strongest filtering level, most strict
448-
blocking * "block_some" : Block some problematic prompts and responses
449-
* "block_few" : Block fewer problematic prompts and responses *
450-
"block_fewest" : Block very few problematic prompts and responses
459+
values are:
460+
* block_most : Strongest filtering level, most strict
461+
blocking
462+
* block_some : Block some problematic prompts and responses
463+
* block_few : Block fewer problematic prompts and responses
464+
* block_fewest : Block very few problematic prompts and
465+
responses
466+
For Imagen 3.0 and Imagen 2.0 Editing (model_name:
467+
`imagen-3.0-generate-001`, `imagen-3.0-fast-generate-001`,
468+
`imagen-2.0-edit-preview-0627` and `imagegeneration@006`), the
469+
following safety filter levels are supported:
470+
* block_low_and_above : Block low and above safety scores
471+
* block_medium_and_above : Block medium and above safety scores
472+
* block_only_high : Block only high safety scores
473+
* block_none : Block nothing
451474
person_generation: Allow generation of people by the model Supported
452-
values are: * "dont_allow" : Block generation of people *
453-
"allow_adult" : Generate adults, but not children * "allow_all" :
454-
Generate adults and children
475+
values are:
476+
* dont_allow : Block generation of people
477+
* allow_adult : Generate adults, but not children
478+
* allow_all : Generate adults and children
455479
456480
Returns:
457481
An `ImageGenerationResponse` object.

0 commit comments

Comments
 (0)