From cce5398dd68ad43b3050c2e387966421f36f9611 Mon Sep 17 00:00:00 2001 From: Matthew Tang Date: Thu, 30 Apr 2026 10:49:35 -0700 Subject: [PATCH] docs: Fix python docstrings for Image.from_file() to use kwargs PiperOrigin-RevId: 908262626 --- README.md | 2 +- google/genai/models.py | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1cc0961d5..1b3848d4f 100644 --- a/README.md +++ b/README.md @@ -1284,7 +1284,7 @@ video.show() from google.genai import types # Read local image (uses mimetypes.guess_type to infer mime type) -image = types.Image.from_file("local/path/file.png") +image = types.Image.from_file(location="local/path/file.png") # Create operation operation = client.models.generate_videos( diff --git a/google/genai/models.py b/google/genai/models.py index b2ea0a858..339248d0c 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -5318,8 +5318,10 @@ def recontext_image( virtual_try_on_response = client.models.recontext_image( model="virtual-try-on-001", source=types.RecontextImageSource( - person_image=types.Image.from_file(IMAGE1_FILE_PATH), - product_images=[types.ProductImage.from_file(IMAGE2_FILE_PATH)], + person_image=types.Image.from_file(location=IMAGE1_FILE_PATH), + product_images=[types.ProductImage(product_image= + types.Image.from_file(location=IMAGE2_FILE_PATH) + )], ), config=types.RecontextImageConfig( number_of_images=1, @@ -5424,7 +5426,7 @@ def segment_image( response = client.models.segment_image( model="image-segmentation-001", source=types.SegmentImageSource( - image=types.Image.from_file(IMAGE_FILE_PATH), + image=types.Image.from_file(location=IMAGE_FILE_PATH), ), ) @@ -6649,7 +6651,7 @@ def edit_image( raw_ref_image = RawReferenceImage( reference_id=1, - reference_image=types.Image.from_file(IMAGE_FILE_PATH), + reference_image=types.Image.from_file(location=IMAGE_FILE_PATH), ) mask_ref_image = MaskReferenceImage( @@ -6661,7 +6663,7 @@ def edit_image( ) response = client.models.edit_image( model='imagen-3.0-capability-001', - prompt='man with dog', + prompt='Man with dog', reference_images=[raw_ref_image, mask_ref_image], config=types.EditImageConfig( edit_mode= "EDIT_MODE_INPAINT_INSERTION", @@ -6704,7 +6706,7 @@ def upscale_image( IMAGE_FILE_PATH="my-image.png" response=client.models.upscale_image( model='imagen-3.0-generate-001', - image=types.Image.from_file(IMAGE_FILE_PATH), + image=types.Image.from_file(location=IMAGE_FILE_PATH), upscale_factor='x2', ) response.generated_images[0].image.show() @@ -7507,8 +7509,10 @@ async def recontext_image( virtual_try_on_response = await client.aio.models.recontext_image( model="virtual-try-on-001", source=types.RecontextImageSource( - person_image=types.Image.from_file(IMAGE1_FILE_PATH), - product_images=[types.ProductImage.from_file(IMAGE2_FILE_PATH)], + person_image=types.Image.from_file(location=IMAGE1_FILE_PATH), + product_images=[types.ProductImage(product_image= + types.Image.from_file(location=IMAGE2_FILE_PATH) + )], ), config=types.RecontextImageConfig( number_of_images=1, @@ -7610,10 +7614,10 @@ async def segment_image( Usage: ``` - response = client.models.segment_image( + response = await client.aio.models.segment_image( model="image-segmentation-001", source=types.SegmentImageSource( - image=types.Image.from_file(IMAGE_FILE_PATH), + image=types.Image.from_file(location=IMAGE_FILE_PATH), ), config=types.SegmentImageConfig( mode=types.SegmentMode.foreground, @@ -8707,7 +8711,7 @@ async def edit_image( raw_ref_image = RawReferenceImage( reference_id=1, - reference_image=types.Image.from_file(IMAGE_FILE_PATH), + reference_image=types.Image.from_file(location=IMAGE_FILE_PATH), ) mask_ref_image = MaskReferenceImage( @@ -8869,7 +8873,7 @@ async def upscale_image( IMAGE_FILE_PATH="my-image.png" response = await client.aio.models.upscale_image( model='imagen-3.0-generate-001', - image=types.Image.from_file(IMAGE_FILE_PATH), + image=types.Image.from_file(location=IMAGE_FILE_PATH), upscale_factor='x2', ) response.generated_images[0].image.show()