-
Notifications
You must be signed in to change notification settings - Fork 97
[✨ Enhanced Sample] Implement Generative Expand (OutPainting) with Imagen 3.0 #113
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @madebymozart, 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! This pull request introduces the "Generative Expand" feature, which empowers users to creatively extend the boundaries of existing images using Imagen 3.0's outpainting capabilities. The core objective is to transform standard-sized generations into larger, more comprehensive scenes by intelligently filling in new areas while maintaining contextual consistency. This functionality is supported by backend integration with Imagen 3.0 and includes resolution safeguards to ensure optimal performance and user experience. Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
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 successfully introduces the Generative Expand (outpainting) feature using Imagen 3.0. The implementation is well-structured and integrates cleanly with the existing architecture. My review focuses on improving the robustness and maintainability of the new functionality. I've identified a potential user experience issue with the validation logic for the 'Expand' button, and I've also provided suggestions to address magic numbers, hardcoded strings, and minor stylistic improvements to align with best practices.
onClick = { | ||
onOutpaintClick(promptTextField) | ||
}, | ||
enabled = enabled && bitmap.width < 4096 && bitmap.height < 4096, |
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.
This enabled
check is not robust enough. It allows the user to click 'Expand' on an image that will become too large after the operation (which doubles the dimensions), leading to a failed request and a poor user experience.
The validation should be predictive, ensuring the resulting dimensions are valid. For example, it should check if bitmap.width * 2 < 4096
.
Additionally, the 4096
limit is a magic number and should be a shared constant.
enabled = enabled && bitmap.width < 4096 && bitmap.height < 4096, | |
enabled = enabled && (bitmap.width * 2) < 4096 && (bitmap.height * 2) < 4096, |
} | ||
|
||
fun outpaintImage(sourceImage: Bitmap, dimensions: Dimensions, prompt: String) { | ||
if (dimensions.width > 4096 || dimensions.height > 4096) { |
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.
fun outpaintImage(sourceImage: Bitmap, dimensions: Dimensions, prompt: String) { | ||
if (dimensions.width > 4096 || dimensions.height > 4096) { | ||
_uiState.value = ImagenEditingUIState.Error("Dimensions are too large. Maximum dimensions are 4096x4096") | ||
return; |
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.
contentDescription = "Outpainted image based on prompt: $prompt", | ||
) | ||
} catch (e: Exception) { | ||
_uiState.value = ImagenEditingUIState.Error(e.localizedMessage ?: "An unknown error occurred during outpainting") |
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.
This fallback error message is hardcoded. It's recommended to move user-facing strings to res/values/strings.xml
to support localization.
Additionally, for better debugging, consider logging the full exception e
before setting the error state, as e.localizedMessage
can sometimes be null
or lack detail.
Let's wait until the redesign is done before we add new samples. |
Description
This pull request introduces the Generative Expand feature, a powerful implementation of outpainting that leverages the advanced capabilities of the Imagen 3.0 model. This new functionality empowers users to creatively extend the canvas of a generated image, seamlessly adding new content that is contextually consistent with the original.
The core objective is to allow users to transform a standard-sized generation into a larger, more comprehensive scene—whether it's widening a landscape, adding more context to a character portrait, or simply exploring what lies beyond the original frame.
Changes Introduced
Technical Details & Implementation
The outpainting process works by sending the original image along with the desired new canvas dimensions to the model. The original image acts as a contextual prompt, and Imagen 3.0 generates the pixels for the new, empty regions.
A key implementation detail is the introduction of a resolution cap.
4096x4096
pixels.How to Test 🧪
3000x3000
).4096x4096
.Screenshots
| Before Expansion | After Expansion |