-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: new image model sample update #13382
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
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-code-assist here with a summary of this pull request. This PR updates the existing image generation sample (imggen_with_txt.py
) to use a newer version of the Imagen model (imagen-4.0-generate-preview-05-20
). A significant change is that the sample now saves the generated image directly to a local file path instead of uploading it to a Google Cloud Storage (GCS) URI. The associated test file (test_image_generation.py
) has also been updated to reflect this change, passing a local file path to the sample function.
Highlights
- Model Version Update: The image generation sample has been updated to use the
imagen-4.0-generate-preview-05-20
model, replacing the olderimagen-3.0-generate-002
model. - Local File Output: The sample now saves the generated image to a specified local file path using the
.save()
method on the image object, rather than outputting to a GCS URI. - Simplified API Call: The
GenerateImagesConfig
object, previously used to specify parameters like aspect ratio, number of images, safety filters, and GCS output, has been removed from the sample call. - Test Update: The corresponding test file has been modified to pass a local file path to the updated sample function.
Changelog
- genai/image_generation/imggen_with_txt.py
- Updated the function signature to accept
output_file: str
and returnImage
. - Changed the model name in the
generate_images
call toimagen-4.0-generate-preview-05-20
. - Removed the
config
parameter and theGenerateImagesConfig
object from thegenerate_images
call. - Added code to save the generated image to the specified local file path.
- Updated the print statement and return value to reflect local file saving.
- Modified the
if __name__ == "__main__":
block to call the function with a local file path.
- Updated the function signature to accept
- genai/image_generation/test_image_generation.py
- Added constants
RESOURCES
andOUTPUT_FILE
for the local test output path. - Updated the
test_img_generation
function to callimggen_with_txt.generate_images
with the newOUTPUT_FILE
constant.
- Added constants
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.
Words into sight,
Imagen paints the digital,
Pixel dreams unfold.
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 updates the Imagen image generation sample to save images locally instead of to GCS and upgrades the model version used. The changes are a good step forward for the sample.
My review focuses on enhancing robustness through error handling, improving clarity regarding configuration changes, and strengthening the test suite. No specific style guide was provided; feedback adheres to general Python best practices (like those outlined in PEP 8), and the code is generally well-formatted. The comments below highlight areas for potential improvement.
Summary of Findings
- Error Handling: The core image generation and saving logic in
imggen_with_txt.py
lacks explicit error handling for potentialIndexError
orIOError
, which could lead to ungraceful failures. (Severity: high, commented) - Configuration Clarity: The removal of
GenerateImagesConfig
inimggen_with_txt.py
could benefit from clarification on how previous configurations (e.g., aspect ratio, number of images) are handled by the new model or if they can still be set. (Severity: medium, commented) - Image Access Assumption: Consistently accessing
generated_images[0]
inimggen_with_txt.py
assumes the new model/API call always returns at least one image and that the first is always the desired one. This assumption could be clarified. (Severity: medium, commented) - Test Suite Enhancements: The test suite in
test_image_generation.py
can be improved by removing an unused test parameter, strengthening assertions to check for file creation, and implementing cleanup for generated test files. (Severity: medium, commented) - Variable Naming Clarity (Low Severity): In
imggen_with_txt.py
(line 27 RIGHT), the variableimage
holds the API response, whileimage.generated_images[0].image
is the actual image data. Renaming the initialimage
variable to something likeapi_response
orgeneration_result
could improve clarity. (Not commented due to review settings focusing on medium+ severity). - Docstring Update (Low Severity): The docstring for the
generate_images
function inimggen_with_txt.py
should be updated to reflect the changes in its parameters (output_file
instead ofoutput_gcs_uri
) and return type (Image
object instead of GCS URI string). (Not commented due to review settings focusing on medium+ severity).
Merge Readiness
The pull request makes good progress in updating the image generation sample. However, there are several areas that could be improved for robustness, clarity, and test quality, including a high-severity issue regarding error handling.
I recommend addressing the high
and medium
severity comments before merging this PR to ensure the sample is robust and easy to understand. As a reviewer, I am not authorized to approve pull requests; please ensure further review and approval from authorized maintainers after addressing the feedback.
Description
Update Imagen image generation sample to save locally, update model version