Skip to content

Commit

Permalink
feat: update generate image sample to 006 (#11411)
Browse files Browse the repository at this point in the history
* feat: update generate image sample to 006

* Trigger Build
  • Loading branch information
irataxy authored Apr 5, 2024
1 parent ec184fd commit cff4fe7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions generative_ai/imagen/generate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
--output_file <filepath> --prompt <text>
"""

# [START aiplatform_imagen_generate_image]
# [START generativeaionvertexai_imagen_generate_image]

import argparse

Expand All @@ -39,13 +39,26 @@ def generate_image(

vertexai.init(project=project_id, location=location)

model = ImageGenerationModel.from_pretrained("imagegeneration@005")
model = ImageGenerationModel.from_pretrained("imagegeneration@006")

images = model.generate_images(
prompt=prompt,
# Optional parameters
seed=1,
number_of_images=1,
language="en", # prompt language
# By default, a SynthID watermark is added to images, but you can
# disable it. You can't use a seed value and watermark at the same time.
# add_watermark=False,
# seed=100,
aspect_ratio="1:1", # "9:16" "16:9" "4:3" "3:4"
# Adds a filter level to Safety filtering: "block_most" (most strict blocking),
# "block_some" (default), "block_few", or "block_fewest" (available to
# allowlisted users only).
safety_filter_level="block_some",
# Allows generation of people by the model: "dont_allow" (block
# all people), "allow_adult" (default; allow adults but not children),
# "allow_all" (available to allowlisted users only; allow adults and children)
person_generation="allow_adult",
)

images[0].save(location=output_file, include_generation_parameters=True)
Expand All @@ -58,7 +71,7 @@ def generate_image(
return images


# [END aiplatform_imagen_generate_image]
# [END generativeaionvertexai_imagen_generate_image]

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand Down

0 comments on commit cff4fe7

Please sign in to comment.