-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
add Imagen screen to quickstart #2657
base: master
Are you sure you want to change the base?
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 @davidmotson, 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 adds a new Imagen screen to the quickstart application. This new screen allows users to generate images from a text prompt using the Vertex AI Imagen model. The changes include adding the necessary UI components, a view model to handle image generation, and integrating the new screen into the main navigation.
Highlights
- New Feature: Imagen Screen: Introduces a new screen that allows users to generate images from text prompts using the Vertex AI Imagen model.
- UI Implementation: Implements the UI for the Imagen screen, including a text field for entering prompts, a button to trigger image generation, and a display area for the generated image.
- ViewModel Integration: Integrates a new ImagenViewModel to handle the interaction with the Vertex AI Imagen model and manage the UI state.
- Navigation Integration: Adds the new Imagen screen to the main navigation of the application, making it accessible from the menu.
Changelog
Click here to see the changelog
- vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/GenerativeAiViewModelFactory.kt
- Added import statement for
ImagenViewModel
. - Added a case to the
when
statement to instantiateImagenViewModel
with theimagen-3.0-fast-generate-001
model.
- Added import statement for
- vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/MainActivity.kt
- Added import statement for
ImagenRoute
. - Added a new composable route for "images" that navigates to
ImagenRoute()
.
- Added import statement for
- vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/MenuScreen.kt
- Added a new
MenuItem
for the Imagen feature, including title and description resources.
- Added a new
- vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
- Created a new composable screen
ImagenScreen
that includes a text field for prompts, a button to generate images, and displays the generated image or an error message. - Created a new composable route
ImagenRoute
to connect theImagenScreen
with theImagenViewModel
.
- Created a new composable screen
- vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenUiState.kt
- Created a sealed interface
ImagenUiState
to represent the different states of the Imagen screen (Initial, Loading, Success, Error).
- Created a sealed interface
- vertexai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenViewModel.kt
- Created a
ImagenViewModel
to handle the interaction with the Vertex AI Imagen model and manage the UI state. - Implemented the
generateImage
function to generate images based on a text prompt and update the UI state accordingly.
- Created a
- vertexai/app/src/main/res/values/strings.xml
- Added new string resources for the Imagen feature, including labels and hints for the prompt text field, and title/description for the menu item.
- vertexai/build.gradle.kts
- Downgraded
com.android.application
version from "8.8.1" to "8.6.1".
- Downgraded
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.
Did you know?
The concept of generating images from text has roots in early AI research, but recent advancements in deep learning have significantly improved the quality and realism of generated images.
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
The pull request adds the Imagen screen to the quickstart app, allowing users to generate images from text prompts. The code is generally well-structured and easy to follow. I have provided some suggestions for improvement, focusing on naming conventions and string resource usage.
Summary of Findings
- ViewModel Naming: Consider renaming
ImagenViewModel
toImageViewModel
for better consistency and clarity, as it aligns more closely with the feature's purpose. - String Resource Usage: Ensure all hardcoded strings are extracted into string resources for better localization and maintainability.
Assessment
The pull request introduces the Imagen screen to the quickstart app, enabling users to generate images from text prompts. The implementation appears well-structured and follows common Android development practices. However, there are a few areas where improvements can be made to enhance code clarity and maintainability. Addressing these comments before merging is recommended. Users should have others review and approve this code before merging.
...ai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
Show resolved
Hide resolved
...ai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
Show resolved
Hide resolved
...ai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
Show resolved
Hide resolved
...ai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
Show resolved
Hide resolved
...ai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
Show resolved
Hide resolved
...ai/app/src/main/kotlin/com/google/firebase/quickstart/vertexai/feature/image/ImagenScreen.kt
Show resolved
Hide resolved
@@ -106,6 +107,12 @@ val GenerativeViewModelFactory = object : ViewModelProvider.Factory { | |||
AudioViewModel(generativeModel) | |||
} | |||
|
|||
isAssignableFrom(ImagenViewModel::class.java) -> { | |||
val imagenModel = Firebase.vertexAI.imagenModel( |
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.
What do you think about adding generationConfig
and safetySettings
? It's a good example for devs to know what kind of values they should send on each field.
@@ -0,0 +1,159 @@ | |||
/* | |||
* Copyright 2023 Google LLC |
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.
Can you update copyright to 2025? (Same for the other two new files)
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 looks good! Before merging it, let's make sure to:
- Solve all comments
- Update BoM version
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.
A few suggestions
FYI I also resolved the gemini code assist comments as none was high priorioty.
@@ -26,11 +26,17 @@ | |||
<string name="menu_chat_description">Sample app demonstrating a conversational UI</string> | |||
<string name="menu_audio_title">Generate text from text-and-audio input</string> | |||
<string name="menu_audio_description">Sample app for recording audio and generating text from it</string> | |||
<string name="menu_imagen_title">Generate images from a text prompt</string> |
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.
To match the title we used for text-to-text
<string name="menu_imagen_title">Generate images from a text prompt</string> | |
<string name="menu_imagen_title">Generate images from a text-only input</string> |
@@ -26,11 +26,17 @@ | |||
<string name="menu_chat_description">Sample app demonstrating a conversational UI</string> | |||
<string name="menu_audio_title">Generate text from text-and-audio input</string> | |||
<string name="menu_audio_description">Sample app for recording audio and generating text from it</string> | |||
<string name="menu_imagen_title">Generate images from a text prompt</string> | |||
<string name="menu_imagen_description">Sample app demonstrating Imagen</string> |
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.
<string name="menu_imagen_description">Sample app demonstrating Imagen</string> | |
<string name="menu_imagen_description">Sample app demonstrating how to use Imagen 3 for image generation</string> |
@@ -106,6 +107,12 @@ val GenerativeViewModelFactory = object : ViewModelProvider.Factory { | |||
AudioViewModel(generativeModel) | |||
} | |||
|
|||
isAssignableFrom(ImagenViewModel::class.java) -> { | |||
val imagenModel = Firebase.vertexAI.imagenModel( | |||
"imagen-3.0-fast-generate-001") |
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.
Shall we match the docs?
"imagen-3.0-fast-generate-001") | |
"imagen-3.0-generate-002") |
No description provided.