diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt index 6e7d9cd6f35..f1e898c3d9a 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt @@ -83,6 +83,13 @@ internal constructor( throw FirebaseAIException.from(e) } + /** + * Generates an image, based on both a prompt, and input image, returning the result directly to + * the caller. + * + * @param prompt The input(s) given to the model as a prompt. + * @param config The editing config given to the model. + */ public suspend fun editImage( prompt: String, config: ImagenEditingConfig diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt index 339ac440ea1..9c9ba0447f1 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt @@ -1,10 +1,39 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.ai.type +/** Represents the edit mode for this imagen editing config */ public class ImagenEditMode private constructor(internal val value: String) { public companion object { + /** + * Inpainting insertion is an edit mode where you mask off an area of the image, and use the + * prompt to add new elements to the image. + */ public val INPAINT_INSERTION: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_INSERTION") + /** + * Inpainting removal is an edit mode where you mask off an area of the image, and use the + * prompt to remove elements from the image. + */ public val INPAINT_REMOVAL: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_REMOVAL") + /** + * Outpainting is an edit mode where your mask is larger than the image, and expands the + * boundaries of the image by continuing the background. The prompt can guide this process. + */ public val OUTPAINT: ImagenEditMode = ImagenEditMode("EDIT_MODE_OUTPAINT") } } diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt index 507d0d85704..94ca487b2e3 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt @@ -1,7 +1,31 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.ai.type import kotlinx.serialization.Serializable +/** + * Configuration parameters to use for imagen editing. + * @property image the base image to be edited. + * @property editMode specifies the edititing mode for this request. + * @property mask the mask to specify which sections of the base image can be edited. + * @property maskDilation a percentage by which to shrink the mask to allow some edge blending. + * @property editSteps the number of intermediate steps for the edit to take. + */ @PublicPreviewAPI public class ImagenEditingConfig( internal val image: ImagenInlineImage, @@ -14,6 +38,18 @@ public class ImagenEditingConfig( public fun builder(): Builder = Builder() } + /** + * Builder for creating a [ImagenEditingConfig]. + * + * Mainly intended for Java interop. Kotlin consumers should use [imagenEditingConfig] for a more + * idiomatic experience. + * + * @property image see [ImagenEditingConfig.image] + * @property editMode see [ImagenEditingConfig.editMode] + * @property mask see [ImagenEditingConfig.mask] + * @property maskDilation see [ImagenEditingConfig.maskDilation] + * @property editSteps see [ImagenEditingConfig.editSteps] + */ public class Builder { @JvmField public var image: ImagenInlineImage? = null @JvmField public var editMode: ImagenEditMode? = null @@ -33,6 +69,7 @@ public class ImagenEditingConfig( public fun setEditSteps(editSteps: Int): Builder = apply { this.editSteps = editSteps } + /** Creates a new [ImagenEditingConfig] with the attached arguments */ public fun build(): ImagenEditingConfig { if (image == null) { throw IllegalStateException("ImagenEditingConfig must contain an image") @@ -60,6 +97,19 @@ public class ImagenEditingConfig( ) } +/** + * Helper method to construct a [ImagenEditingConfig] in a DSL-like manner. + * + * Example Usage: + * ``` + * imagenEditingConfig { + * image = baseImage + * mask = imageMask + * editMode = ImagenEditMode.INPAINTING_REMOVAL + * maskDilation = 0.05 + * } + * ``` + */ @PublicPreviewAPI public fun imagenEditingConfig(init: ImagenEditingConfig.Builder.() -> Unit): ImagenEditingConfig { val builder = ImagenEditingConfig.builder()