-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 generation example to VertexAI Sample #14545
Conversation
This commit adds a new Imagen sample to the Vertex AI sample app. The new sample demonstrates how to use the Imagen API to generate images based on a text prompt. It includes a new screen, , and a new view model, , that handles the API interactions and displays the generated image. The file has also been updated to include the new "Imagen" sample in the list.
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 @paulb777, 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 an image generation example to the VertexAI Sample app. It introduces two new files, ImagenScreen.swift
and ImagenViewModel.swift
, which implement the UI and logic for generating images using the Vertex AI's Imagen model. The changes also include modifications to the project's pbxproj
file to incorporate these new files and updates to the CHANGELOG.md
and ContentView.swift
to reflect the new feature.
Highlights
- New Feature: Image Generation: Introduces an image generation feature to the VertexAI Sample app using the Imagen model.
- UI Implementation: Implements the UI for the image generation feature using SwiftUI in
ImagenScreen.swift
, including a text field for prompts, a button to trigger generation, and image display. - ViewModel Logic: Creates a
ImagenViewModel.swift
to handle the logic for interacting with the Vertex AI service, configuring the Imagen model, and generating images based on user input. - Project Configuration: Updates the
project.pbxproj
file to include the newImagenScreen.swift
andImagenViewModel.swift
files in the project.
Changelog
Click here to see the changelog
- FirebaseVertexAI/CHANGELOG.md
- Added a changelog entry noting the addition of the image generation example to the Vertex AI Sample App.
- FirebaseVertexAI/Sample/ImagenScreen/ImagenScreen.swift
- Created a new SwiftUI view
ImagenScreen
that provides a user interface for entering a text prompt and displaying generated images. - Includes a TextField for user input, a Generate button, and an Image view to display the generated images.
- Uses
@FocusState
to manage focus on the text field. - Uses a
ImagenViewModel
to handle the image generation logic.
- Created a new SwiftUI view
- FirebaseVertexAI/Sample/ImagenScreen/ImagenViewModel.swift
- Created a new
ImagenViewModel
class to manage the interaction with the Vertex AI Imagen model. - Initializes the Vertex AI service and configures the Imagen model with specific settings (model name, safety settings, generation config).
- Implements the
generateImage
function to call the Imagen model and convert the response toUIImage
for display. - Handles error cases and filtering reasons for generated images.
- Created a new
- FirebaseVertexAI/Sample/VertexAISample.xcodeproj/project.pbxproj
- Modified the project file to include the new
ImagenScreen.swift
andImagenViewModel.swift
files. - Added a new group for
ImagenScreen
containing the view and view model files.
- Modified the project file to include the new
- FirebaseVertexAI/Sample/VertexAISample/ContentView.swift
- Added a
NavigationLink
to theContentView
to navigate to the newImagenScreen
.
- Added a
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.
Trivia time!
What company developed the Swift programming language?
Click here for the answer
Swift was developed by Apple Inc.
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 adds an image generation example to the VertexAI Sample app. The changes include adding new files for the ImagenScreen and ImagenViewModel, updating the ContentView to include a navigation link to the ImagenScreen, and modifying the project file to include the new files. Overall, the code is well-structured and easy to understand. However, there are a few areas that could be improved.
Summary of Findings
- Error Handling: The error handling in the
generateImage
function ofImagenViewModel
only prints the error to the console. It would be better to display the error in the UI to inform the user about what went wrong. - Copyright Year: The copyright year in the license header is set to 2025. Please confirm that this is the correct year.
- Missing Documentation: There is no documentation for the new files and classes. It would be helpful to add some documentation to explain the purpose of each file and class.
Merge Readiness
The pull request introduces a new feature and the code seems functional. However, addressing the error handling and copyright year issues is recommended before merging. Additionally, adding documentation would improve the maintainability of the code. I am unable to directly approve this pull request, and users should have others review and approve this code before merging.
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.
The placeholder view mentioned by gemini would be nice to have but is not a blocker for merge.
Thanks. Do you have a good reference pointer to an example? Or a suggestion of what it should look like? |
Hi @paulb777, regarding the placeholder view, I don't have a specific reference implementation in mind, but I can offer some general suggestions for what it could look like:
The best approach depends on the desired level of visual sophistication and the overall design of your app. Since it's not a blocker, a simple text placeholder or progress indicator would be a good starting point. |
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.
LGTM, thanks!
No description provided.