Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9c68ddd
feat: add Translation sample
thatfiredev Mar 13, 2026
1a49b77
Update Audio summarization to use Gemini 3.1 Flash-Lite
thatfiredev Mar 13, 2026
47d5b7f
remove grounding from the document category
thatfiredev Mar 13, 2026
22198fe
val instead of var
thatfiredev Mar 13, 2026
d93fc7f
refactor: new categories :)
thatfiredev Mar 13, 2026
1e5d347
feat: add more Nano Banana samples
thatfiredev Mar 13, 2026
4366caf
reorder a few samples
thatfiredev Mar 13, 2026
0e387cb
Merge branch 'master' of github.com:firebase/quickstart-android into …
thatfiredev Mar 20, 2026
0c74ec6
Merge branch 'master' of github.com:firebase/quickstart-android into …
thatfiredev Apr 30, 2026
9054b2a
reorder some samples
thatfiredev Apr 30, 2026
5752f53
adjust main menu UI padding
thatfiredev Apr 30, 2026
e9a0c85
update README.md
thatfiredev Apr 30, 2026
db9fb03
Function --> function
thatfiredev Apr 30, 2026
b6cf3e8
more padding adjustments
thatfiredev Apr 30, 2026
254f9b7
remove text labels
thatfiredev Apr 30, 2026
bb925d6
more padding adjustments
thatfiredev Apr 30, 2026
48fab5c
Merge branch 'master' of github.com:firebase/quickstart-android into …
thatfiredev May 8, 2026
052f508
Merge branch 'master' of github.com:firebase/quickstart-android into …
thatfiredev May 19, 2026
857c64a
refactor(ai): use gemini-3.5-flash to generate SVGs
thatfiredev May 19, 2026
4678967
refactor(ai): remove gemini-2.5-flash example
thatfiredev May 19, 2026
665d57a
update screenshot
thatfiredev May 19, 2026
5b9ca07
fix SVG generation
thatfiredev May 19, 2026
7992c56
address gemini feedback
thatfiredev May 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions firebase-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ generative AI models (like Gemini) to build AI-powered features and applications

For more information about Firebase AI Logic, visit the [documentation](http://firebase.google.com/docs/ai-logic).

<img src="./docs/result.png" width="300" alt="Screenshot"/>

## Setup & Configuration

### Prerequisites
Expand All @@ -25,33 +27,40 @@ To try out this sample app, you need to use latest stable version of Android Stu

You can find the implementation for each feature by clicking on the links below:

### Text / Chat
- [Travel tips](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/TravelTipsViewModel.kt): The user wants the model to help a new traveler with travel tips
- [Chatbot recommendations for courses](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/CourseRecommendationsViewModel.kt): A chatbot suggests courses for a performing arts program.
- [Weather Chat](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/WeatherChatViewModel.kt): Use function calling to get the weather conditions for a specific US city on a specific date.
- [Grounding with Google Search](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/GoogleSearchGroundingViewModel.kt): Use Grounding with Google Search to get responses based on up-to-date information from the web.
- [Thinking](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ThinkingChatViewModel.kt): Gemini 2.5 Flash with dynamic thinking
- [Server Prompt Templates - Gemini](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ServerPromptTemplateViewModel.kt): Generate an invoice using server prompt templates.
### Gemini 3
- [Translate text](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/TranslationViewModel.kt): Use Gemini 3.1 Flash-Lite to translate text
- [SVG Generator](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/SvgViewModel.kt): Use Gemini 3.5 Flash to create SVG illustrations
- [Gemini 3.1 Flash Image (Nano Banana 2)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBanana2ViewModel.kt): Generate and/or edit images using Nano Banana 2 preview
- [Gemini 3 Pro Image (Nano Banana Pro)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBananaProViewModel.kt): Generate and/or edit images using Nano Banana Pro preview

### Image analysis / generation
- [Gemini 2.5 Flash Image (aka nanobanana)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ImageGenerationViewModel.kt): Generate and/or edit images using Gemini 2.5 Flash Image aka nanobanana
- [SVG Generator](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/SvgViewModel.kt): Use Gemini 3 Flash preview to create SVG illustrations
- [Blog post creator (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ImageBlogCreatorViewModel.kt): Create a blog post from an image file stored in Cloud Storage.
### Nano Banana
- [Gemini 3.1 Flash Image (Nano Banana 2)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBanana2ViewModel.kt): Generate and/or edit images using Nano Banana 2 preview
- [Gemini 3 Pro Image (Nano Banana Pro)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBananaProViewModel.kt): Generate and/or edit images using Nano Banana Pro preview
- [Gemini 2.5 Flash Image (Nano Banana)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBananaViewModel.kt): Generate and/or edit images using Nano Banana (GA)

### Audio analysis
- [Audio Summarization](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/AudioSummarizationViewModel.kt): Summarize an audio file
### Multimodal understanding
- [Audio Summarization](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/AudioSummarizationViewModel.kt): Use Gemini 3.1 Flash Lite to summarize an audio file
- [Summarize video](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoSummarizationViewModel.kt): Summarize a video and extract important dialogue.
- [Translation from audio (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/AudioTranslationViewModel.kt): Translate an audio file stored in Cloud Storage

### Video analysis
- [Blog post creator (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ImageBlogCreatorViewModel.kt): Create a blog post from an image file stored in Cloud Storage.
- [Document comparison (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/DocumentComparisonViewModel.kt): Compare the contents of 2 documents stored in Cloud Storage.
- [Hashtags for a video (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoHashtagGeneratorViewModel.kt): Generate hashtags for a video ad stored in Cloud Storage
- [Summarize video](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoSummarizationViewModel.kt): Summarize a video and extract important dialogue.

### Live API (Real-time bidrectional streaming)
- [ForecastTalk](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamAudioViewModel.kt): Use bidirectional streaming to get information about weather conditions
- [Gemini Live (Video input)](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamVideoViewModel.kt): Use bidirectional streaming to chat with Gemini using your phone's camera
### Tools and function calling
- [Grounding with Google Search](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/GoogleSearchGroundingViewModel.kt): Use Grounding with Google Search to get responses based on up-to-date information from the web.
- [Weather Chat](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/WeatherChatViewModel.kt): Use function calling to get the weather conditions for a specific US city on a specific date.
- [Gemini Live (audio input)](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamAudioViewModel.kt): Use bidirectional streaming to get information about weather conditions for a specific US city on a specific date
- [Gemini Live (video input)](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamVideoViewModel.kt): Use bidirectional streaming to chat with Gemini using your phone's camera

### Live API streaming
- [Gemini Live (audio input)](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamAudioViewModel.kt): Use bidirectional streaming to get information about weather conditions for a specific US city on a specific date
- [Gemini Live (video input)](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamVideoViewModel.kt): Use bidirectional streaming to chat with Gemini using your phone's camera

### Server prompt templates
- [Server Prompt Templates - Gemini](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ServerPromptTemplateViewModel.kt): Generate an invoice using server prompt templates.

### Document (PDFs) analysis
- [Document comparison (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/DocumentComparisonViewModel.kt): Compare the contents of 2 documents in Cloud Storage.
### Hybrid inference
- [Hybrid Receipt Scanner](app/src/main/java/com/google/firebase/quickstart/ai/feature/hybrid/HybridInferenceViewModel.kt): Use hybrid inference to scan receipts and extract expense data on-device whenever possible.


## All samples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,35 @@ import com.google.firebase.ai.Chat
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.Content
import com.google.firebase.ai.type.GenerativeBackend
import com.google.firebase.ai.type.ResponseModality
import com.google.firebase.ai.type.generationConfig
import com.google.firebase.ai.type.thinkingConfig
import com.google.firebase.quickstart.ai.ui.UiChatMessage

@Serializable
object ThinkingChatRoute
object NanoBanana2Route

class ThinkingChatViewModel : ChatViewModel() {
class NanoBanana2ViewModel : ChatViewModel() {

override val initialPrompt: String = "Analogize photosynthesis and growing up."
override val initialPrompt: String = """
A photo of a glossy magazine cover, the minimal blue cover
has the large bold words Nano Banana. The text is in a serif
font and fills the view. No other text. In front of the text
there is a portrait of a person in a sleek and minimal dress.
She is playfully holding the number 2, which is the focal point.
Put the issue number and "Feb 2026" date in the corner along with
a barcode. The magazine is on a shelf against an orange plastered
wall, within a designer store.
""".trimIndent()

private val chat: Chat

init {
val generativeModel = Firebase.ai(
backend = GenerativeBackend.googleAI()
).generativeModel(
modelName = "gemini-2.5-flash",
modelName = "gemini-3.1-flash-image-preview",
generationConfig = generationConfig {
thinkingConfig = thinkingConfig {
includeThoughts = true
thinkingBudget = -1 // Dynamic Thinking
}
responseModalities = listOf(ResponseModality.TEXT, ResponseModality.IMAGE)
}
)
chat = generativeModel.startChat()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.google.firebase.quickstart.ai.feature.text

import kotlinx.serialization.Serializable

import com.google.firebase.Firebase
import com.google.firebase.ai.Chat
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.Content
import com.google.firebase.ai.type.GenerativeBackend
import com.google.firebase.ai.type.ResponseModality
import com.google.firebase.ai.type.generationConfig
import com.google.firebase.quickstart.ai.ui.UiChatMessage

@Serializable
object NanoBananaProRoute

class NanoBananaProViewModel : ChatViewModel() {

override val initialPrompt: String = """
Present a clear, 45° top-down isometric miniature 3D cartoon
scene of London, featuring its most iconic landmarks and
architectural elements. Use soft, refined textures with
realistic PBR materials and gentle, lifelike lighting and shadows.
Integrate the current weather conditions directly into the city
environment to create an immersive atmospheric mood. Use a clean,
minimalistic composition with a soft, solid-colored background.
At the top-center, place the title "London" in large bold text,
a prominent weather icon beneath it, then the date (small text)
and temperature (medium text). All text must be centered with
consistent spacing, and may subtly overlap the tops of the buildings.
""".trimIndent()

private val chat: Chat

init {
val generativeModel = Firebase.ai(
backend = GenerativeBackend.googleAI()
).generativeModel(
modelName = "gemini-3-pro-image-preview",
generationConfig = generationConfig {
responseModalities = listOf(ResponseModality.TEXT, ResponseModality.IMAGE)
}
)
chat = generativeModel.startChat()
}

override suspend fun performSendMessage(prompt: Content, currentMessages: List<UiChatMessage>) {
val response = chat.sendMessage(prompt)
validateAndDisplayResponse(response, currentMessages)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import com.google.firebase.ai.type.generationConfig
import com.google.firebase.quickstart.ai.ui.UiChatMessage

@Serializable
object ImageGenerationRoute
object NanoBananaRoute

class ImageGenerationViewModel : ChatViewModel() {
class NanoBananaViewModel : ChatViewModel() {

override val initialPrompt: String = """
Hi, can you create a 3d rendered image of a pig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.google.firebase.Firebase
import com.google.firebase.ai.GenerativeModel
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.GenerativeBackend
import com.google.firebase.ai.type.ThinkingLevel
import com.google.firebase.ai.type.content
import com.google.firebase.ai.type.generationConfig
import com.google.firebase.ai.type.thinkingConfig
Expand All @@ -31,7 +32,7 @@ class SvgViewModel : ViewModel() {
generativeModel = Firebase.ai(
backend = GenerativeBackend.googleAI()
).generativeModel(
modelName = "gemini-3-flash-preview",
modelName = "gemini-3.5-flash",
systemInstruction = content {
text(
"""
Expand All @@ -45,7 +46,7 @@ class SvgViewModel : ViewModel() {
},
generationConfig = generationConfig {
thinkingConfig {
thinkingBudget = -1
thinkingLevel = ThinkingLevel.HIGH
}
}
)
Expand All @@ -58,6 +59,10 @@ class SvgViewModel : ViewModel() {
try {
val response = generativeModel.generateContent(prompt)
val newSvg = response.text
// Remove the ```xml [...] ``` around the svg
?.removePrefix("```xml")
?.removeSuffix("```")
?.trimIndent()
if (newSvg != null) {
_uiState.value = SvgUiState.Success(listOf(newSvg) + currentSvgs)
} else {
Expand Down
Loading
Loading