Skip to content

Commit cdecb91

Browse files
author
David Motsonashvili
committed
add documentation to Imagen Editing
1 parent dec0990 commit cdecb91

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ internal constructor(
8383
throw FirebaseAIException.from(e)
8484
}
8585

86+
/**
87+
* Generates an image, based on both a prompt, and input image, returning the result directly to
88+
* the caller.
89+
*
90+
* @param prompt The input(s) given to the model as a prompt.
91+
* @param config The editing config given to the model.
92+
*/
8693
public suspend fun editImage(
8794
prompt: String,
8895
config: ImagenEditingConfig
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.firebase.ai.type
218

19+
/** Represents the edit mode for this imagen editing config */
320
public class ImagenEditMode private constructor(internal val value: String) {
421

522
public companion object {
23+
/**
24+
* Inpainting insertion is an edit mode where you mask off an area of the image, and use the
25+
* prompt to add new elements to the image.
26+
*/
627
public val INPAINT_INSERTION: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_INSERTION")
28+
/**
29+
* Inpainting removal is an edit mode where you mask off an area of the image, and use the
30+
* prompt to remove elements from the image.
31+
*/
732
public val INPAINT_REMOVAL: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_REMOVAL")
33+
/**
34+
* Outpainting is an edit mode where your mask is larger than the image, and expands the
35+
* boundaries of the image by continuing the background. The prompt can guide this process.
36+
*/
837
public val OUTPAINT: ImagenEditMode = ImagenEditMode("EDIT_MODE_OUTPAINT")
938
}
1039
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.firebase.ai.type
218

319
import kotlinx.serialization.Serializable
420

21+
/**
22+
* Configuration parameters to use for imagen editing.
23+
* @property image the base image to be edited.
24+
* @property editMode specifies the edititing mode for this request.
25+
* @property mask the mask to specify which sections of the base image can be edited.
26+
* @property maskDilation a percentage by which to shrink the mask to allow some edge blending.
27+
* @property editSteps the number of intermediate steps for the edit to take.
28+
*/
529
@PublicPreviewAPI
630
public class ImagenEditingConfig(
731
public val image: ImagenInlineImage,
@@ -14,6 +38,18 @@ public class ImagenEditingConfig(
1438
public fun builder(): Builder = Builder()
1539
}
1640

41+
/**
42+
* Builder for creating a [ImagenEditingConfig].
43+
*
44+
* Mainly intended for Java interop. Kotlin consumers should use [imagenEditingConfig] for a more
45+
* idiomatic experience.
46+
*
47+
* @property image see [ImagenEditingConfig.image]
48+
* @property editMode see [ImagenEditingConfig.editMode]
49+
* @property mask see [ImagenEditingConfig.mask]
50+
* @property maskDilation see [ImagenEditingConfig.maskDilation]
51+
* @property editSteps see [ImagenEditingConfig.editSteps]
52+
*/
1753
public class Builder {
1854
@JvmField public var image: ImagenInlineImage? = null
1955
@JvmField public var editMode: ImagenEditMode? = null
@@ -33,6 +69,7 @@ public class ImagenEditingConfig(
3369

3470
public fun setEditSteps(editSteps: Int): Builder = apply { this.editSteps = editSteps }
3571

72+
/** Creates a new [ImagenEditingConfig] with the attached arguments */
3673
public fun build(): ImagenEditingConfig {
3774
if (image == null) {
3875
throw IllegalStateException("ImagenEditingConfig must contain an image")
@@ -60,6 +97,19 @@ public class ImagenEditingConfig(
6097
)
6198
}
6299

100+
/**
101+
* Helper method to construct a [ImagenEditingConfig] in a DSL-like manner.
102+
*
103+
* Example Usage:
104+
* ```
105+
* imagenEditingConfig {
106+
* image = baseImage
107+
* mask = imageMask
108+
* editMode = ImagenEditMode.INPAINTING_REMOVAL
109+
* maskDilation = 0.05
110+
* }
111+
* ```
112+
*/
63113
@PublicPreviewAPI
64114
public fun imagenEditingConfig(init: ImagenEditingConfig.Builder.() -> Unit): ImagenEditingConfig {
65115
val builder = ImagenEditingConfig.builder()

0 commit comments

Comments
 (0)