-
Notifications
You must be signed in to change notification settings - Fork 145
Firebase AI Logic and Imagen update #41
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ Browse the samples inside the `/samples` folder: | |
| - More to come... | ||
|
|
||
| > **Requires Firebase setup** the samples relying on Google Cloud models (Gemini Pro, Gemini Flash, etc...) | ||
| > require setting up a Firebase project and connecting the app to Firebase (read more [here](https://firebase.google.com/docs/vertex-ai/get-started?platform=android#set-up-firebase)). | ||
| > require setting up a Firebase project and connecting the app to Firebase (read more [here](https://firebase.google.com/docs/ai-logic/get-started?platform=android&api=dev#set-up-firebase)). | ||
|
|
||
| > 🚧 **Work-in-Progress:** we are working on bringing more samples into the application. | ||
|
|
||
|
|
@@ -33,7 +33,7 @@ Browse the samples inside the `/samples` folder: | |
| 1. Clone the repository | ||
| 2. Open the whole project in Android Studio. | ||
| 3. Set up a Firebase project and connect your app to Firebase by adding your Firebase configuration | ||
| file (google-services.json) to the app. Read more [here](https://firebase.google.com/docs/vertex-ai/get-started?platform=android#set-up-firebase). | ||
| file (google-services.json) to the app. Read more [here](https://firebase.google.com/docs/ai-logic/get-started?platform=android&api=dev#set-up-firebase). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 3. Sync & Run `app` configuration | ||
|
|
||
| The app will open with the samples list screen that allows you to navigate throughout the different | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,7 @@ dependencies { | |
| implementation(libs.hilt.android) | ||
| implementation(libs.hilt.navigation.compose) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ksp(libs.hilt.compiler) | ||
|
|
||
| implementation(project(":samples:gemini-multimodal")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| [versions] | ||
| agp = "8.8.0" | ||
| coilCompose = "3.1.0" | ||
| firebaseBom = "33.12.0" | ||
| firebaseBom = "33.14.0" | ||
| mlkitGenAi = "1.0.0-beta1" | ||
| kotlin = "2.1.0" | ||
| coreKtx = "1.15.0" | ||
|
|
@@ -23,15 +23,14 @@ ksp = "2.1.0-1.0.29" | |
| runtimeLivedata = "1.7.6" | ||
| material3Android = "1.3.1" | ||
| media3 = "1.6.1" | ||
| material3AndroidVersion = "1.3.2" | ||
| firebaseCommonKtx = "21.0.0" | ||
| uiToolingPreviewAndroid = "1.8.1" | ||
|
|
||
| [libraries] | ||
| androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } | ||
| coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coilCompose" } | ||
| firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebaseBom" } | ||
| firebase-vertexai = { group = "com.google.firebase", name = "firebase-vertexai" } | ||
| firebase-ai = { group = "com.google.firebase", name = "firebase-ai" } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| firebase-common-ktx = { group = "com.google.firebase", name = "firebase-common-ktx", version.ref = "firebaseCommonKtx" } | ||
| genai-image-description = { module = "com.google.mlkit:genai-image-description", version.ref = "mlkitGenAi" } | ||
| genai-proofreading = { module = "com.google.mlkit:genai-proofreading", version.ref = "mlkitGenAi" } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ dependencies { | |
| implementation(platform(libs.androidx.compose.bom)) | ||
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| implementation(libs.hilt.android) | ||
| implementation(libs.hilt.navigation.compose) | ||
| implementation(libs.androidx.runtime.livedata) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,7 @@ dependencies { | |
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| implementation(libs.hilt.android) | ||
| implementation(libs.hilt.navigation.compose) | ||
| implementation(libs.androidx.runtime.livedata) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ dependencies { | |
| implementation(libs.androidx.ui.tooling.preview.android) | ||
| ksp(libs.hilt.compiler) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // Media3 ExoPlayer | ||
| implementation(libs.androidx.media3.exoplayer) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ dependencies { | |
| implementation(platform(libs.androidx.compose.bom)) | ||
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| implementation(libs.hilt.android) | ||
| implementation(libs.hilt.navigation.compose) | ||
| implementation(libs.androidx.runtime.livedata) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,12 @@ import androidx.lifecycle.MutableLiveData | |
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.google.firebase.Firebase | ||
| import com.google.firebase.vertexai.type.ImagenAspectRatio | ||
| import com.google.firebase.vertexai.type.ImagenGenerationConfig | ||
| import com.google.firebase.vertexai.type.ImagenImageFormat | ||
| import com.google.firebase.vertexai.type.PublicPreviewAPI | ||
| import com.google.firebase.vertexai.vertexAI | ||
| import com.google.firebase.ai.ai | ||
| import com.google.firebase.ai.type.GenerativeBackend | ||
| import com.google.firebase.ai.type.ImagenAspectRatio | ||
| import com.google.firebase.ai.type.ImagenGenerationConfig | ||
| import com.google.firebase.ai.type.ImagenImageFormat | ||
| import com.google.firebase.ai.type.PublicPreviewAPI | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
@@ -41,13 +42,12 @@ class ImagenViewModel @Inject constructor(): ViewModel() { | |
| val isGenerating: LiveData<Boolean> = _isGenerating | ||
|
|
||
| @OptIn(PublicPreviewAPI::class) | ||
| private val imagenModel = Firebase.vertexAI.imagenModel( | ||
| modelName = "imagen-3.0-generate-002", | ||
| private val imagenModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel( | ||
| modelName = "imagen-4.0-generate-preview-05-20", | ||
|
Comment on lines
+45
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| generationConfig = ImagenGenerationConfig( | ||
| numberOfImages = 1, | ||
| aspectRatio = ImagenAspectRatio.SQUARE_1x1, | ||
| imageFormat = ImagenImageFormat.jpeg(compressionQuality = 75), | ||
| addWatermark = true | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ dependencies { | |
| implementation(platform(libs.androidx.compose.bom)) | ||
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| implementation(libs.hilt.android) | ||
| implementation(libs.hilt.navigation.compose) | ||
| implementation(libs.androidx.runtime.livedata) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,12 @@ import androidx.lifecycle.MutableLiveData | |
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.google.firebase.Firebase | ||
| import com.google.firebase.vertexai.type.ImagenAspectRatio | ||
| import com.google.firebase.vertexai.type.ImagenGenerationConfig | ||
| import com.google.firebase.vertexai.type.ImagenImageFormat | ||
| import com.google.firebase.vertexai.type.PublicPreviewAPI | ||
| import com.google.firebase.vertexai.vertexAI | ||
| import com.google.firebase.ai.ai | ||
| import com.google.firebase.ai.type.GenerativeBackend | ||
| import com.google.firebase.ai.type.ImagenAspectRatio | ||
| import com.google.firebase.ai.type.ImagenGenerationConfig | ||
| import com.google.firebase.ai.type.ImagenImageFormat | ||
| import com.google.firebase.ai.type.PublicPreviewAPI | ||
| import com.google.mlkit.vision.common.InputImage | ||
| import com.google.mlkit.vision.segmentation.subject.SubjectSegmentation | ||
| import com.google.mlkit.vision.segmentation.subject.SubjectSegmenterOptions | ||
|
|
@@ -48,13 +49,12 @@ class MagicSelfieViewModel @Inject constructor(): ViewModel() { | |
| private val _progress = MutableLiveData<String?>(null) | ||
| val progress: LiveData<String?> = _progress | ||
|
|
||
| private val imagenModel = Firebase.vertexAI.imagenModel( | ||
| modelName = "imagen-3.0-generate-002", | ||
| private val imagenModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel( | ||
| modelName = "imagen-4.0-generate-preview-05-20", | ||
|
Comment on lines
+52
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| generationConfig = ImagenGenerationConfig( | ||
| numberOfImages = 1, | ||
| aspectRatio = ImagenAspectRatio.PORTRAIT_3x4, | ||
| imageFormat = ImagenImageFormat.jpeg(compressionQuality = 75), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| addWatermark = true | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
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 link in the README is updated to point to the Firebase AI Logic documentation, which is great. However, consider adding a brief explanation of what Firebase AI Logic is and why it's being used in this project. This would provide more context for users who are new to the project.