Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 2 commits into from
May 20, 2025

Conversation

katiemn
Copy link
Contributor

@katiemn katiemn commented May 20, 2025

Description

Update Imagen image generation sample to save locally, update model version

@katiemn katiemn requested review from a team as code owners May 20, 2025 17:57
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label May 20, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 older imagen-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 return Image.
    • Changed the model name in the generate_images call to imagen-4.0-generate-preview-05-20.
    • Removed the config parameter and the GenerateImagesConfig object from the generate_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.
  • genai/image_generation/test_image_generation.py
    • Added constants RESOURCES and OUTPUT_FILE for the local test output path.
    • Updated the test_img_generation function to call imggen_with_txt.generate_images with the new OUTPUT_FILE constant.
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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 potential IndexError or IOError, which could lead to ungraceful failures. (Severity: high, commented)
  • Configuration Clarity: The removal of GenerateImagesConfig in imggen_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] in imggen_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 variable image holds the API response, while image.generated_images[0].image is the actual image data. Renaming the initial image variable to something like api_response or generation_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 in imggen_with_txt.py should be updated to reflect the changes in its parameters (output_file instead of output_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.

genai/image_generation/imggen_with_txt.py Show resolved Hide resolved
genai/image_generation/imggen_with_txt.py Show resolved Hide resolved
genai/image_generation/imggen_with_txt.py Show resolved Hide resolved
@holtskinner holtskinner merged commit a019a79 into GoogleCloudPlatform:main May 20, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.