11package com.google.firebase.quickstart.ai
22
3+ import android.content.Context
4+ import android.content.res.Resources
35import android.graphics.Bitmap
6+ import android.graphics.BitmapFactory
47import com.google.firebase.ai.ImagenModel
58import com.google.firebase.ai.type.Dimensions
69import com.google.firebase.ai.type.FunctionDeclaration
@@ -10,6 +13,9 @@ import com.google.firebase.ai.type.ImagenEditMode
1013import com.google.firebase.ai.type.ImagenEditingConfig
1114import com.google.firebase.ai.type.ImagenMaskReference
1215import 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
1319import com.google.firebase.ai.type.PublicPreviewAPI
1420import com.google.firebase.ai.type.ResponseModality
1521import com.google.firebase.ai.type.Schema
@@ -142,21 +148,24 @@ val FIREBASE_AI_SAMPLES = listOf(
142148 text(
143149 " A photo of a modern building with water in the background"
144150 )
151+ },
152+ allowEmptyPrompt = false ,
153+ generateImages = { model: ImagenModel , inputText: String , _: Bitmap ? ->
154+ model.generateImages(
155+ inputText
156+ )
145157 }
146158 ),
147159 Sample (
148160 title = " Imagen 3 - Inpainting" ,
149161 description = " Replace the background of an image using Imagen 3" ,
150- modelName= " imagen-3.0-capability-001" ,
162+ modelName = " imagen-3.0-capability-001" ,
151163 backend = GenerativeBackend .vertexAI(),
152164 navRoute = " imagen" ,
153165 categories = listOf (Category .IMAGE ),
154- initialPrompt = content {
155- text(
156- " A sunny beach"
157- )
158- },
166+ initialPrompt = content { text(" A sunny beach" ) },
159167 includeAttach = true ,
168+ allowEmptyPrompt = true ,
160169 generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
161170 model.editImage(
162171 listOf (ImagenRawImage (bitmap!! .toImagenInlineImage()), ImagenBackgroundMask ()),
@@ -168,16 +177,13 @@ val FIREBASE_AI_SAMPLES = listOf(
168177 Sample (
169178 title = " Imagen 3 - Outpainting" ,
170179 description = " Expand an image by drawing in more background" ,
171- modelName= " imagen-3.0-capability-001" ,
180+ modelName = " imagen-3.0-capability-001" ,
172181 backend = GenerativeBackend .vertexAI(),
173182 navRoute = " imagen" ,
174183 categories = listOf (Category .IMAGE ),
175- initialPrompt = content {
176- text(
177- " "
178- )
179- },
184+ initialPrompt = content { text(" " ) },
180185 includeAttach = true ,
186+ allowEmptyPrompt = true ,
181187 generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
182188 val dimensions = Dimensions (bitmap!! .width * 2 , bitmap.height * 2 )
183189 model.editImage(
@@ -187,6 +193,50 @@ val FIREBASE_AI_SAMPLES = listOf(
187193 )
188194 }
189195 ),
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+ ),
190240 Sample (
191241 title = " Gemini 2.0 Flash - image generation" ,
192242 description = " Generate and/or edit images using Gemini 2.0 Flash" ,
0 commit comments