|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +from google.genai.types import Image |
15 | 16 |
|
16 |
| -def generate_images(output_gcs_uri: str) -> str: |
| 17 | + |
| 18 | +def generate_images(output_file: str) -> Image: |
17 | 19 | # [START googlegenaisdk_imggen_with_txt]
|
18 | 20 | from google import genai
|
19 |
| - from google.genai.types import GenerateImagesConfig |
20 | 21 |
|
21 | 22 | client = genai.Client()
|
22 | 23 |
|
23 | 24 | # TODO(developer): Update and un-comment below line
|
24 |
| - # output_gcs_uri = "gs://your-bucket/your-prefix" |
| 25 | + # output_file = "output-image.png" |
25 | 26 |
|
26 | 27 | image = client.models.generate_images(
|
27 |
| - model="imagen-3.0-generate-002", |
| 28 | + model="imagen-4.0-generate-preview-05-20", |
28 | 29 | prompt="A dog reading a newspaper",
|
29 |
| - config=GenerateImagesConfig( |
30 |
| - aspect_ratio="1:1", |
31 |
| - number_of_images=1, |
32 |
| - safety_filter_level="BLOCK_MEDIUM_AND_ABOVE", |
33 |
| - person_generation="DONT_ADULT", |
34 |
| - output_gcs_uri=output_gcs_uri, |
35 |
| - ), |
36 | 30 | )
|
37 | 31 |
|
| 32 | + image.generated_images[0].image.save(output_file) |
| 33 | + |
| 34 | + print(f"Created output image using {len(image.generated_images[0].image.image_bytes)} bytes") |
38 | 35 | # Example response:
|
39 |
| - # gs://your-bucket/your-prefix |
40 |
| - print(image.generated_images[0].image.gcs_uri) |
| 36 | + # Created output image using 1234567 bytes |
| 37 | + |
41 | 38 | # [END googlegenaisdk_imggen_with_txt]
|
42 |
| - return image.generated_images[0].image.gcs_uri |
| 39 | + return image.generated_images[0].image |
43 | 40 |
|
44 | 41 |
|
45 | 42 | if __name__ == "__main__":
|
46 |
| - generate_images(output_gcs_uri="gs://your-bucket/your-prefix") |
| 43 | + generate_images(output_file="test_resources/dog_newspaper.png") |
0 commit comments