-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(genai): Add new samples for image editing #13408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Here is the summary of changes. You are about to add 5 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @katiemn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello team,
Gemini (gemini-code-assist) here to provide a summary of this pull request. This PR introduces new sample code demonstrating various image editing capabilities using the Imagen model via the Google GenAI SDK. Specifically, it adds examples for inpainting (both insertion and removal), mask-free editing, outpainting, and product background swapping. The changes include adding the new Python sample files and updating the existing test suite to include tests for these new samples.
Highlights
- New Image Editing Samples: Adds five new Python sample scripts showcasing different image editing modes available with the Imagen model.
- Inpainting Samples: Includes samples for inpainting, demonstrating how to insert new objects into an image and how to remove objects from an image using text prompts and masks.
- Outpainting Sample: Adds a sample for outpainting, showing how to expand an image beyond its original boundaries based on a text prompt and a mask.
- Mask-Free Editing Sample: Provides a sample for general mask-free image editing using a text prompt.
- Product Background Swap Sample: Includes a sample specifically for swapping the background of a product image using a text prompt and a background mask mode.
- Test Coverage: Updates the image generation test suite to include tests for the newly added image editing samples, ensuring their basic functionality.
Changelog
Click here to see the changelog
- genai/image_generation/imggen_inpainting_insert_with_txt_img.py
- New file added.
- Contains a sample function
edit_inpainting_insert
demonstrating image inpainting insertion usingEDIT_MODE_INPAINT_INSERTION
with raw and mask reference images. - Includes example usage in
if __name__ == "__main__":
block.
- genai/image_generation/imggen_inpainting_removal_with_txt_img.py
- New file added.
- Contains a sample function
edit_inpainting_removal
demonstrating image inpainting removal usingEDIT_MODE_INPAINT_REMOVAL
with raw and mask reference images. - Includes example usage in
if __name__ == "__main__":
block.
- genai/image_generation/imggen_mask_free_edit_with_txt_img.py
- New file added.
- Contains a sample function
edit_mask_free
demonstrating mask-free image editing usingEDIT_MODE_DEFAULT
with a raw reference image. - Includes example usage in
if __name__ == "__main__":
block.
- genai/image_generation/imggen_outpainting_with_txt_img.py
- New file added.
- Contains a sample function
edit_outpainting
demonstrating image outpainting usingEDIT_MODE_OUTPAINT
with raw and user-provided mask reference images. - Includes example usage in
if __name__ == "__main__":
block.
- genai/image_generation/imggen_product_background_with_txt_img.py
- New file added.
- Contains a sample function
edit_product_background
demonstrating product background swap usingEDIT_MODE_BGSWAP
with raw and background mask reference images. - Includes example usage in
if __name__ == "__main__":
block.
- genai/image_generation/test_image_generation.py
- Imports added for the new image editing sample files.
- Removed a global
OUTPUT_FILE
variable. - Added five new test functions (
test_img_edit_inpainting_insert
,test_img_edit_inpainting_removal
,test_img_edit_product_background
,test_img_edit_outpainting
,test_img_edit_mask_free
) to test the new samples. - Moved the
OUTPUT_FILE
variable definition inside thetest_img_generation
function.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces five new Python samples demonstrating various image editing capabilities with the Imagen API, along with corresponding tests. The new sample files are well-structured and clearly illustrate the usage of the google-genai
SDK for features like inpainting, outpainting, mask-free editing, and product background replacement. The code is generally clean and easy to understand.
The tests for these new samples have also been added. While the additions are mostly good, there's a minor improvement suggested for the test function signatures. Overall, a good contribution to the examples.
Summary of Findings
- Copyright Year: The copyright year in the new sample files (e.g.,
imggen_inpainting_insert_with_txt_img.py
) is set to 2025. This might be a placeholder or intended, but it's worth noting. This was not commented on directly due to review settings (severity: low). - Clarity of
output_file
TODO in Samples: In the new sample functions (e.g.,imggen_inpainting_insert_with_txt_img.py
line 26-27), theoutput_file
parameter is accepted by the function. However, there's aTODO(developer): Update and un-comment below line # output_file = "output-image.png"
. This could be slightly confusing as the function already uses the passed parameter. Consider clarifying or removing this TODO if the parameter is the primary way to set the output. This was not commented on directly due to review settings (severity: low). - Error Handling in Samples: The new sample files do not include explicit error handling for operations like
Image.from_file()
or API calls (e.g., usingtry-except
blocks). While this keeps the samples concise and is generally acceptable for example code, in production code, robust error handling would be necessary. This was not commented on directly due to review settings (severity: low). - Direct Access to
generated_images[0]
in Samples: The samples accessimage.generated_images[0].image
directly (e.g.,imggen_inpainting_insert_with_txt_img.py
line 49). This assumes the API call is successful and returns at least one image. For production code, checking thegenerated_images
list before accessing elements would be a good practice. This is generally acceptable for example code. This was not commented on directly due to review settings (severity: low).
Merge Readiness
The pull request adds valuable new samples for image editing. The code for the samples themselves is clear and well-implemented. There are a few medium-severity suggestions regarding unused parameters in the new test functions. Addressing these would improve the clarity and maintainability of the test suite. I recommend that these changes be made before merging. As a reviewer, I am not authorized to approve the pull request; please ensure it undergoes further review and approval as per your team's process.
Description
Add new samples for image editing with Imagen