1
1
package com.google.firebase.quickstart.ai
2
2
3
+ import android.content.Context
4
+ import android.content.res.Resources
3
5
import android.graphics.Bitmap
6
+ import android.graphics.BitmapFactory
4
7
import com.google.firebase.ai.ImagenModel
5
8
import com.google.firebase.ai.type.Dimensions
6
9
import com.google.firebase.ai.type.FunctionDeclaration
@@ -10,6 +13,9 @@ import com.google.firebase.ai.type.ImagenEditMode
10
13
import com.google.firebase.ai.type.ImagenEditingConfig
11
14
import com.google.firebase.ai.type.ImagenMaskReference
12
15
import com.google.firebase.ai.type.ImagenRawImage
16
+ import com.google.firebase.ai.type.ImagenStyleReference
17
+ import com.google.firebase.ai.type.ImagenSubjectReference
18
+ import com.google.firebase.ai.type.ImagenSubjectReferenceType
13
19
import com.google.firebase.ai.type.PublicPreviewAPI
14
20
import com.google.firebase.ai.type.ResponseModality
15
21
import com.google.firebase.ai.type.Schema
@@ -142,21 +148,24 @@ val FIREBASE_AI_SAMPLES = listOf(
142
148
text(
143
149
" A photo of a modern building with water in the background"
144
150
)
151
+ },
152
+ allowEmptyPrompt = false ,
153
+ generateImages = { model: ImagenModel , inputText: String , _: Bitmap ? ->
154
+ model.generateImages(
155
+ inputText
156
+ )
145
157
}
146
158
),
147
159
Sample (
148
160
title = " Imagen 3 - Inpainting" ,
149
161
description = " Replace the background of an image using Imagen 3" ,
150
- modelName= " imagen-3.0-capability-001" ,
162
+ modelName = " imagen-3.0-capability-001" ,
151
163
backend = GenerativeBackend .vertexAI(),
152
164
navRoute = " imagen" ,
153
165
categories = listOf (Category .IMAGE ),
154
- initialPrompt = content {
155
- text(
156
- " A sunny beach"
157
- )
158
- },
166
+ initialPrompt = content { text(" A sunny beach" ) },
159
167
includeAttach = true ,
168
+ allowEmptyPrompt = true ,
160
169
generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
161
170
model.editImage(
162
171
listOf (ImagenRawImage (bitmap!! .toImagenInlineImage()), ImagenBackgroundMask ()),
@@ -168,16 +177,13 @@ val FIREBASE_AI_SAMPLES = listOf(
168
177
Sample (
169
178
title = " Imagen 3 - Outpainting" ,
170
179
description = " Expand an image by drawing in more background" ,
171
- modelName= " imagen-3.0-capability-001" ,
180
+ modelName = " imagen-3.0-capability-001" ,
172
181
backend = GenerativeBackend .vertexAI(),
173
182
navRoute = " imagen" ,
174
183
categories = listOf (Category .IMAGE ),
175
- initialPrompt = content {
176
- text(
177
- " "
178
- )
179
- },
184
+ initialPrompt = content { text(" " ) },
180
185
includeAttach = true ,
186
+ allowEmptyPrompt = true ,
181
187
generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
182
188
val dimensions = Dimensions (bitmap!! .width * 2 , bitmap.height * 2 )
183
189
model.editImage(
@@ -187,6 +193,50 @@ val FIREBASE_AI_SAMPLES = listOf(
187
193
)
188
194
}
189
195
),
196
+ Sample (
197
+ title = " Imagen 3 - Subject Reference" ,
198
+ description = " generate an image using a referenced subject (must be an animal)" ,
199
+ modelName = " imagen-3.0-capability-001" ,
200
+ backend = GenerativeBackend .vertexAI(),
201
+ navRoute = " imagen" ,
202
+ categories = listOf (Category .IMAGE ),
203
+ initialPrompt = content { text(" <subject> flying through space" ) },
204
+ includeAttach = true ,
205
+ allowEmptyPrompt = false ,
206
+ generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
207
+ model.editImage(
208
+ listOf (
209
+ ImagenSubjectReference (
210
+ referenceId = 1 ,
211
+ image = bitmap!! .toImagenInlineImage(),
212
+ subjectType = ImagenSubjectReferenceType .ANIMAL ,
213
+ description = " An animal"
214
+ )
215
+ ),
216
+ " Create an image about An animal [1] to match the description: " +
217
+ inputText.replace(" <subject>" , " An animal [1]" ),
218
+ )
219
+ }
220
+ ),
221
+ Sample (
222
+ title = " Imagen 3 - Style Transfer" ,
223
+ description = " Change the art style of an cat picture using a reference" ,
224
+ modelName = " imagen-3.0-capability-001" ,
225
+ backend = GenerativeBackend .vertexAI(),
226
+ navRoute = " imagen" ,
227
+ categories = listOf (Category .IMAGE ),
228
+ initialPrompt = content { text(" A picture of a cat" ) },
229
+ includeAttach = true ,
230
+ allowEmptyPrompt = true ,
231
+ generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
232
+ model.editImage(
233
+ listOf (
234
+ ImagenRawImage (MainActivity .catImage.toImagenInlineImage()),
235
+ ImagenStyleReference (bitmap!! .toImagenInlineImage(), 1 , " an art style" )),
236
+ " Generate an image in an art style [1] based on the following caption: $inputText " ,
237
+ )
238
+ }
239
+ ),
190
240
Sample (
191
241
title = " Gemini 2.0 Flash - image generation" ,
192
242
description = " Generate and/or edit images using Gemini 2.0 Flash" ,
0 commit comments