Constructing AI first Android Experiences with Gemini utilizing Jetpack Compose and Firebase

0
8
Constructing AI first Android Experiences with Gemini utilizing Jetpack Compose and Firebase



Constructing AI first Android Experiences with Gemini utilizing Jetpack Compose and Firebase

Posted by Rebecca Franks – Developer Relations Engineer, Tracy Agyemang – Product Marketer, and Avneet Singh – Product Supervisor

Androidify is our new app that allows you to construct your very personal Android bot, utilizing a selfie and AI. We walked you thru a few of the elements earlier this yr, and beginning right this moment it’s out there on the net or as an app on Google Play. Within the new Androidify, you possibly can add a selfie or write a immediate of what you’re searching for, add some equipment, and watch as AI builds your distinctive bot. When you’ve had an opportunity to strive it, come again right here to be taught extra in regards to the AI APIs and Android instruments we used to create the app. Let’s dive in!

Key technical integrations

The Androidify app combines highly effective applied sciences to ship a seamless and interesting person expertise. Here is a breakdown of the core elements and their roles:

AI with Gemini and Firebase

Androidify leverages the Firebase AI Logic SDK to entry Google’s highly effective Gemini and Imagen* fashions. That is essential for a number of key options:

  • Picture validation: The app first makes use of Gemini 2.5 Flash to validate the person’s picture. This contains checking that the picture incorporates a transparent, targeted individual and meets security requirements earlier than any additional processing. This can be a crucial first step to make sure high-quality and secure outputs.
  • Picture captioning: As soon as validated, the mannequin generates an in depth caption of the person’s picture. That is completed utilizing structured output, which suggests the mannequin returns a selected JSON format, making it simpler for the app to parse the knowledge. This detailed description helps create a extra correct and inventive closing consequence.
  • Android Bot Technology: The generated caption is then used to complement the immediate for the ultimate picture era. A particularly fine-tuned model of the Imagen 3 mannequin is then referred to as to generate the customized Android bot avatar primarily based on the enriched immediate. This practice fine-tuning ensures the outcomes are distinctive and align with the app’s playful and stylized aesthetic.
  • The Androidify app additionally has a “Assist me write” characteristic which makes use of Gemini 2.5 Flash to create a random description for a bot’s clothes and coiffure, including a little bit of a enjoyable “I am feeling fortunate” component.

    gif showcasing the help me write button

    UI with Jetpack Compose and CameraX

    The app’s person interface is constructed completely with Jetpack Compose, enabling a declarative and responsive design throughout type elements. The app makes use of the most recent Materials 3 Expressive design, which offers pleasant and interesting UI parts like new shapes, movement schemes, and customized animations.

    For digital camera performance, CameraX is used together with the ML Package Pose Detection API. This clever integration permits the app to routinely detect when an individual is within the digital camera’s view, enabling the seize button and including visible guides for the person. It additionally makes the app’s digital camera options aware of completely different system varieties, together with foldables in tabletop mode.

    Androidify additionally makes intensive use of the most recent Compose options, akin to:

  • Adaptive layouts: It is designed to look nice on varied display screen sizes, from telephones to foldables and tablets, by leveraging WindowSizeClass and reusable composables.
  • Shared component transitions: The app makes use of the brand new Jetpack Navigation 3 library to create clean and pleasant display screen transitions, together with morphing form animations that add a cultured really feel to the person expertise.
  • Auto-sizing textual content: With Compose 1.8, the app makes use of a brand new parameter that routinely adjusts font measurement to suit the container’s out there measurement, which is used for the app’s major “Customise your personal Android Bot” textual content.
  • chart illustrating the behavior of Androidify app flow

    Determine 1. Androidify Circulate

    Newest updates

    Within the newest model of Androidify, we’ve added some new highly effective AI pushed options.

    Background vibe era with Gemini Picture enhancing

    Utilizing the newest Gemini 2.5 Flash Picture mannequin, we mix the Android bot with a preset background “vibe” to deliver the Android bots to life.

    a three-part image showing an Android bot on the left, text prompt in the middle reads A vibrant 3D illustration of a vibrant outdoor garden with fun plants. the flowers in thisscene have an alien-like qulaity to them and are brightly colored. the entire scene is rendered with a meticulous mixture of rounded, toy-like objects, creating a clean, minimalist aesthetic..., and image on the right is the Android bot from the first image stanging in a toy like garen scene surrounded by brightly colored flowers. A whitre picket fence is in the background, and a red watering can sits on the ground next to the driod bot

    Determine 2. Combining the Android bot with a background vibe description to generate your new Android Bot in a scene

    That is achieved by utilizing Firebase AI Logic – passing a immediate for the background vibe, and the enter picture bitmap of the bot, with directions to Gemini on mix the 2 collectively.

    override droop enjoyable generateImageWithEdit(
            picture: Bitmap,
            backgroundPrompt: String = "Add the enter picture android bot as the primary topic to the consequence... with the background that has the next vibe...",
        ): Bitmap {
            val mannequin = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
                modelName = "gemini-2.5-flash-image-preview",
                generationConfig = generationConfig {
                    responseModalities = listOf(
                        ResponseModality.TEXT,
                        ResponseModality.IMAGE,
                    )
                },
            )
    	  // We mix the backgroundPrompt with the enter picture which is the Android Bot, to supply the brand new bot with a background
            val immediate = content material {
                textual content(backgroundPrompt)
                picture(picture)
            }
            val response = mannequin.generateContent(immediate)
            val picture = response.candidates.firstOrNull()
                ?.content material?.components?.firstNotNullOfOrNull { it.asImageOrNull() }
            return picture ?: throw IllegalStateException("Couldn't extract picture from mannequin response")
        }

    Sticker mode with ML Package Topic Segmentation

    The app additionally features a “Sticker mode” possibility, which integrates the ML Package Topic Segmentation library to take away the background on the bot. You should use “Sticker mode” in apps that help stickers.

    backgroud removal

    Determine 3. White background elimination of Android Bot to create a PNG that can be utilized with apps that help stickers

    The code for the sticker implementation first checks if the Topic Segmentation mannequin has been downloaded and put in, if it has not – it requests that and waits for its completion. If the mannequin is put in already, the app passes within the unique Android Bot picture into the segmenter, and calls course of on it to take away the background. The foregroundBitmap object is then returned for exporting.

    override droop enjoyable generateImageWithEdit(
            picture: Bitmap,
            backgroundPrompt: String = "Add the enter picture android bot as the primary topic to the consequence... with the background that has the next vibe...",
        ): Bitmap {
            val mannequin = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
                modelName = "gemini-2.5-flash-image-preview",
                generationConfig = generationConfig {
                    responseModalities = listOf(
                        ResponseModality.TEXT,
                        ResponseModality.IMAGE,
                    )
                },
            )
    	  // We mix the backgroundPrompt with the enter picture which is the Android Bot, to supply the brand new bot with a background
            val immediate = content material {
                textual content(backgroundPrompt)
                picture(picture)
            }
            val response = mannequin.generateContent(immediate)
            val picture = response.candidates.firstOrNull()
                ?.content material?.components?.firstNotNullOfOrNull { it.asImageOrNull() }
            return picture ?: throw IllegalStateException("Couldn't extract picture from mannequin response")
        }

    See the LocalSegmentationDataSource for the total supply implementation

    Study extra

    To be taught extra about Androidify behind the scenes, check out the brand new options walkthrough, examine the code or check out the expertise for your self at androidify.com or obtain the app on Google Play.

    Constructing AI first Android Experiences with Gemini utilizing Jetpack Compose and Firebase

    *Examine responses. Compatibility and availability varies. 18+.

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here