-
Notifications
You must be signed in to change notification settings - Fork 157
Add an option to create a Sticker of the Android #93
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
Still todo: Move segmentation to background thread to improve initial feedback.
# Conflicts: # feature/results/src/main/java/com/android/developers/androidify/customize/CustomizeExportScreen.kt # feature/results/src/main/java/com/android/developers/androidify/customize/CustomizeExportViewModel.kt # feature/results/src/main/java/com/android/developers/androidify/customize/CustomizeState.kt # feature/results/src/main/java/com/android/developers/androidify/customize/ImageRenderer.kt
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.
Summary of Changes
Hello @riggaroo, 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!
I've implemented a new feature that allows users to create 'stickers' of the Android character by intelligently removing the background from generated images. This involved integrating ML Kit's subject segmentation capabilities. Additionally, I've addressed an issue where exported images were being cropped, ensuring that all generated content is now correctly displayed and saved.
Highlights
- Sticker Creation Feature: I've introduced a new "Sticker" size option that leverages ML Kit Subject Segmentation to automatically remove the background from the generated Android image, creating a transparent sticker.
- ML Kit Integration: I've incorporated the
play-services-mlkit-subject-segmentation
library to enable on-device background removal, enhancing the app's image processing capabilities. - Improved Image Export: I've fixed a bug that caused exported images to be cropped, ensuring that the full generated image is correctly rendered and saved, especially for various aspect ratios.
- UI/UX Enhancements for Customization: I've updated the customization tools to include the new "Sticker" size option with a dedicated visual representation, and adjusted image rendering logic to properly display stickers with transparent backgrounds.
- Refactored Image Processing Logic: I've introduced a
LocalSegmentationDataSource
and integrated it into theImageGenerationRepository
to abstract and manage the background removal process.
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 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 or fill out our survey 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 a great new feature to create a sticker from the generated Android, which involves removing the image background using ML Kit's subject segmentation. The implementation looks solid, adding the necessary dependencies and data sources. Additionally, it fixes an issue with cropped exported images. I've provided a couple of suggestions to improve performance and code maintainability.
...work/src/main/java/com/android/developers/androidify/ondevice/LocalSegmentationDataSource.kt
Outdated
Show resolved
Hide resolved
...esults/src/main/java/com/android/developers/androidify/customize/CustomizeExportViewModel.kt
Outdated
Show resolved
Hide resolved
/gemini review |
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 a "Sticker" export option, which uses ML Kit's subject segmentation to remove the background from the generated Android character. The implementation is well-structured, adding new dependencies, DI modules, a data source for the on-device ML, and updating the ViewModel and UI to support this new feature. The code correctly handles checking for and installing the required ML module on-demand. My review includes a few suggestions to improve robustness, error handling, and code cleanliness. I've identified one high-severity issue that could lead to a hanging coroutine.
...work/src/main/java/com/android/developers/androidify/ondevice/LocalSegmentationDataSource.kt
Outdated
Show resolved
Hide resolved
...work/src/main/java/com/android/developers/androidify/ondevice/LocalSegmentationDataSource.kt
Outdated
Show resolved
Hide resolved
...work/src/main/java/com/android/developers/androidify/ondevice/LocalSegmentationDataSource.kt
Show resolved
Hide resolved
# Conflicts: # data/src/main/java/com/android/developers/androidify/data/ImageGenerationRepository.kt # feature/results/src/main/java/com/android/developers/androidify/customize/ImageRenderer.kt
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.
Awesome feature
class LocalSegmentationDataSourceImpl @Inject constructor( | ||
private val moduleInstallClient: ModuleInstallClient | ||
) : LocalSegmentationDataSource { | ||
private val segmenter by lazy { |
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 class is used as a singleton right? segmenter
has a close function if not that should probably be called if you are creating and destroying this class
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.
Its not closed off in the official sample for it - so i dont think we need to call it , also haven't seen any leaks from LeakCanary for it. https://github.com/googlesamples/mlkit/blob/80d6bc64a0b88e18666f26feee0219995f1a86b2/android/vision-quickstart/app/src/main/java/com/google/mlkit/vision/demo/kotlin/subjectsegmenter/SubjectSegmenterProcessor.kt
This adds a "Sticker" Export option to the Size options available on export screen. Internally it uses the Google Services ML Kit Subject segmentation to remove the background from the sticker.
The code checks if the module is available, if its not installed, it attempts to install it - and then use the tool to get a Foreground bitmap. Thats then returned and rendered to the user.
Screen_recording_20250812_081243.mp4