Skip to content

feat(genai): Add new image generation samples #13320

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 10 commits into from
Apr 25, 2025

Conversation

katiemn
Copy link
Contributor

@katiemn katiemn commented Apr 24, 2025

Description

Add new code samples for Imagen Customization using the Google Gen AI SDK for Python

@katiemn katiemn requested review from a team as code owners April 24, 2025 00:22
Copy link

snippet-bot bot commented Apr 24, 2025

Here is the summary of changes.

You are about to add 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 24, 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

This pull request introduces new code samples for Imagen Customization using the Google Gen AI SDK for Python. It includes examples for canny edge detection, scribble customization, style customization, style transfer, and subject customization. Each sample demonstrates how to use the edit_image method with different configurations to achieve various image editing effects.

Highlights

  • New Samples: Adds five new code samples demonstrating different Imagen customization techniques: canny edge, scribble, style, style transfer, and subject customization.
  • Image Editing: Each sample uses the edit_image method of the Google Gen AI SDK to modify images based on prompts and reference images.
  • Configuration: The samples utilize various configuration options such as EditImageConfig, ControlReferenceConfig, StyleReferenceConfig, and SubjectReferenceConfig to control the image editing process.

Changelog

Click here to see the changelog
  • genai/image_generation/img_customization_canny_edge.py
    • Introduces a new sample demonstrating image customization using canny edge detection.
    • Uses ControlReferenceImage and ControlReferenceConfig to specify the canny edge control type.
    • The sample takes an image of a car with canny edges and generates a watercolor painting of a red car driving on a road, using the canny edges as a guide.
  • genai/image_generation/img_customization_scribble.py
    • Introduces a new sample demonstrating image customization using scribble.
    • Uses ControlReferenceImage and ControlReferenceConfig to specify the scribble control type.
    • The sample takes an image of a car with scribbles and generates an oil painting showing the side of a red car, using the scribbles as a guide.
  • genai/image_generation/img_customization_style.py
    • Introduces a new sample demonstrating image customization using style reference.
    • Uses StyleReferenceImage and StyleReferenceConfig to specify the style description.
    • The sample takes an image of a neon sign and generates an image of a neon sign with the words 'have a great day', using the style of the reference image.
  • genai/image_generation/img_customization_style_transfer.py
    • Introduces a new sample demonstrating image customization using style transfer.
    • Uses RawReferenceImage to specify the style image.
    • The sample takes an image of a teacup and transforms it so that the teacup is made entirely out of chocolate, using the style of the reference image.
  • genai/image_generation/img_customization_subject.py
    • Introduces a new sample demonstrating image customization using subject reference and face mesh control.
    • Uses SubjectReferenceImage, SubjectReferenceConfig, ControlReferenceImage, and ControlReferenceConfig to specify the subject and control type.
    • The sample takes a headshot of a woman and generates a portrait of a woman in the pose of the control image in a watercolor style.
  • genai/image_generation/noxfile_config.py
    • Adds a default TEST_CONFIG_OVERRIDE for python repos.
    • Specifies ignored Python versions and enforces type hints.
  • genai/image_generation/requirements-test.txt
    • Adds pytest as a test dependency.
  • genai/image_generation/requirements.txt
    • Adds google-genai as a dependency.
  • genai/image_generation/test_img_customization.py
    • Introduces new tests for the image customization samples.
    • Sets environment variables for using Vertex AI.
    • Each test asserts that the length of the generated image bytes is greater than 1000.
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.


With Imagen's artful hand,
Images transform at command.
From scribble's trace,
A new image we embrace,
AI's magic, across the land.

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 introduces new code samples for Imagen Customization using the Google Gen AI SDK for Python. The samples cover various customization techniques like Canny edge, scribble, style, style transfer, and subject customization. Overall, the code is well-structured and easy to understand. However, there are a few areas that could be improved for better clarity and maintainability.

Summary of Findings

  • Missing Error Handling: The code samples lack explicit error handling. It's crucial to handle potential exceptions, such as network errors or API failures, to ensure the robustness of the samples.
  • Inconsistent Variable Naming: There are some inconsistencies in variable naming across the different code samples. Maintaining a consistent naming convention improves readability and reduces cognitive load.
  • Hardcoded Values: The code uses hardcoded values for parameters like model name and GCS URIs. Consider making these configurable or using constants to improve flexibility and maintainability.

Merge Readiness

The pull request introduces valuable code samples for Imagen Customization. However, addressing the identified issues, particularly the missing error handling, is crucial before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

@holtskinner holtskinner assigned msampathkumar and unassigned iennae Apr 24, 2025
Copy link
Contributor

@holtskinner holtskinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, deferring to @msampathkumar on Sample Region Tags/File names

@msampathkumar msampathkumar changed the title feat: genai samples for imagen customization feat(genai): Add new image generation samples Apr 24, 2025
Copy link
Member

@msampathkumar msampathkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @katiemn 👍

@katiemn katiemn merged commit 189a057 into GoogleCloudPlatform:main Apr 25, 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.

4 participants