Skip to content

Commit a35acd7

Browse files
authored
refactor(ai-logic): simplify samples categories (#2791)
* feat: add Translation sample * Update Audio summarization to use Gemini 3.1 Flash-Lite * remove grounding from the document category * val instead of var * refactor: new categories :) * feat: add more Nano Banana samples * reorder a few samples * reorder some samples * adjust main menu UI padding * update README.md * Function --> function * more padding adjustments * remove text labels Keeps it Simple :) * more padding adjustments * refactor(ai): use gemini-3.5-flash to generate SVGs * refactor(ai): remove gemini-2.5-flash example * update screenshot * fix SVG generation * address gemini feedback
1 parent 1647de8 commit a35acd7

9 files changed

Lines changed: 188 additions & 136 deletions

File tree

firebase-ai/README.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ generative AI models (like Gemini) to build AI-powered features and applications
55

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

8+
<img src="./docs/result.png" width="300" alt="Screenshot"/>
9+
810
## Setup & Configuration
911

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

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

28-
### Text / Chat
29-
- [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
30-
- [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.
31-
- [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.
32-
- [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.
33-
- [Thinking](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ThinkingChatViewModel.kt): Gemini 2.5 Flash with dynamic thinking
34-
- [Server Prompt Templates - Gemini](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ServerPromptTemplateViewModel.kt): Generate an invoice using server prompt templates.
30+
### Gemini 3
31+
- [Translate text](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/TranslationViewModel.kt): Use Gemini 3.1 Flash-Lite to translate text
32+
- [SVG Generator](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/SvgViewModel.kt): Use Gemini 3.5 Flash to create SVG illustrations
33+
- [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
34+
- [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
3535

36-
### Image analysis / generation
37-
- [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
38-
- [SVG Generator](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/SvgViewModel.kt): Use Gemini 3 Flash preview to create SVG illustrations
39-
- [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.
36+
### Nano Banana
37+
- [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
38+
- [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
39+
- [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)
4040

41-
### Audio analysis
42-
- [Audio Summarization](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/AudioSummarizationViewModel.kt): Summarize an audio file
41+
### Multimodal understanding
42+
- [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
43+
- [Summarize video](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoSummarizationViewModel.kt): Summarize a video and extract important dialogue.
4344
- [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
44-
45-
### Video analysis
45+
- [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.
46+
- [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.
4647
- [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
47-
- [Summarize video](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoSummarizationViewModel.kt): Summarize a video and extract important dialogue.
4848

49-
### Live API (Real-time bidrectional streaming)
50-
- [ForecastTalk](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamAudioViewModel.kt): Use bidirectional streaming to get information about weather conditions
51-
- [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
49+
### Tools and function calling
50+
- [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.
51+
- [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.
52+
- [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
53+
- [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
54+
55+
### Live API streaming
56+
- [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
57+
- [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
58+
59+
### Server prompt templates
60+
- [Server Prompt Templates - Gemini](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ServerPromptTemplateViewModel.kt): Generate an invoice using server prompt templates.
5261

53-
### Document (PDFs) analysis
54-
- [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.
62+
### Hybrid inference
63+
- [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.
5564

5665

5766
## All samples

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ThinkingChatViewModel.kt renamed to firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBanana2ViewModel.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,35 @@ import com.google.firebase.ai.Chat
77
import com.google.firebase.ai.ai
88
import com.google.firebase.ai.type.Content
99
import com.google.firebase.ai.type.GenerativeBackend
10+
import com.google.firebase.ai.type.ResponseModality
1011
import com.google.firebase.ai.type.generationConfig
11-
import com.google.firebase.ai.type.thinkingConfig
1212
import com.google.firebase.quickstart.ai.ui.UiChatMessage
1313

1414
@Serializable
15-
object ThinkingChatRoute
15+
object NanoBanana2Route
1616

17-
class ThinkingChatViewModel : ChatViewModel() {
17+
class NanoBanana2ViewModel : ChatViewModel() {
1818

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

2130
private val chat: Chat
2231

2332
init {
2433
val generativeModel = Firebase.ai(
2534
backend = GenerativeBackend.googleAI()
2635
).generativeModel(
27-
modelName = "gemini-2.5-flash",
36+
modelName = "gemini-3.1-flash-image-preview",
2837
generationConfig = generationConfig {
29-
thinkingConfig = thinkingConfig {
30-
includeThoughts = true
31-
thinkingBudget = -1 // Dynamic Thinking
32-
}
38+
responseModalities = listOf(ResponseModality.TEXT, ResponseModality.IMAGE)
3339
}
3440
)
3541
chat = generativeModel.startChat()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.google.firebase.quickstart.ai.feature.text
2+
3+
import kotlinx.serialization.Serializable
4+
5+
import com.google.firebase.Firebase
6+
import com.google.firebase.ai.Chat
7+
import com.google.firebase.ai.ai
8+
import com.google.firebase.ai.type.Content
9+
import com.google.firebase.ai.type.GenerativeBackend
10+
import com.google.firebase.ai.type.ResponseModality
11+
import com.google.firebase.ai.type.generationConfig
12+
import com.google.firebase.quickstart.ai.ui.UiChatMessage
13+
14+
@Serializable
15+
object NanoBananaProRoute
16+
17+
class NanoBananaProViewModel : ChatViewModel() {
18+
19+
override val initialPrompt: String = """
20+
Present a clear, 45° top-down isometric miniature 3D cartoon
21+
scene of London, featuring its most iconic landmarks and
22+
architectural elements. Use soft, refined textures with
23+
realistic PBR materials and gentle, lifelike lighting and shadows.
24+
Integrate the current weather conditions directly into the city
25+
environment to create an immersive atmospheric mood. Use a clean,
26+
minimalistic composition with a soft, solid-colored background.
27+
At the top-center, place the title "London" in large bold text,
28+
a prominent weather icon beneath it, then the date (small text)
29+
and temperature (medium text). All text must be centered with
30+
consistent spacing, and may subtly overlap the tops of the buildings.
31+
""".trimIndent()
32+
33+
private val chat: Chat
34+
35+
init {
36+
val generativeModel = Firebase.ai(
37+
backend = GenerativeBackend.googleAI()
38+
).generativeModel(
39+
modelName = "gemini-3-pro-image-preview",
40+
generationConfig = generationConfig {
41+
responseModalities = listOf(ResponseModality.TEXT, ResponseModality.IMAGE)
42+
}
43+
)
44+
chat = generativeModel.startChat()
45+
}
46+
47+
override suspend fun performSendMessage(prompt: Content, currentMessages: List<UiChatMessage>) {
48+
val response = chat.sendMessage(prompt)
49+
validateAndDisplayResponse(response, currentMessages)
50+
}
51+
}

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ImageGenerationViewModel.kt renamed to firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/NanoBananaViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import com.google.firebase.ai.type.generationConfig
1212
import com.google.firebase.quickstart.ai.ui.UiChatMessage
1313

1414
@Serializable
15-
object ImageGenerationRoute
15+
object NanoBananaRoute
1616

17-
class ImageGenerationViewModel : ChatViewModel() {
17+
class NanoBananaViewModel : ChatViewModel() {
1818

1919
override val initialPrompt: String = """
2020
Hi, can you create a 3d rendered image of a pig

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/SvgViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.google.firebase.Firebase
88
import com.google.firebase.ai.GenerativeModel
99
import com.google.firebase.ai.ai
1010
import com.google.firebase.ai.type.GenerativeBackend
11+
import com.google.firebase.ai.type.ThinkingLevel
1112
import com.google.firebase.ai.type.content
1213
import com.google.firebase.ai.type.generationConfig
1314
import com.google.firebase.ai.type.thinkingConfig
@@ -31,7 +32,7 @@ class SvgViewModel : ViewModel() {
3132
generativeModel = Firebase.ai(
3233
backend = GenerativeBackend.googleAI()
3334
).generativeModel(
34-
modelName = "gemini-3-flash-preview",
35+
modelName = "gemini-3.5-flash",
3536
systemInstruction = content {
3637
text(
3738
"""
@@ -45,7 +46,7 @@ class SvgViewModel : ViewModel() {
4546
},
4647
generationConfig = generationConfig {
4748
thinkingConfig {
48-
thinkingBudget = -1
49+
thinkingLevel = ThinkingLevel.HIGH
4950
}
5051
}
5152
)
@@ -58,6 +59,10 @@ class SvgViewModel : ViewModel() {
5859
try {
5960
val response = generativeModel.generateContent(prompt)
6061
val newSvg = response.text
62+
// Remove the ```xml [...] ``` around the svg
63+
?.removePrefix("```xml")
64+
?.removeSuffix("```")
65+
?.trimIndent()
6166
if (newSvg != null) {
6267
_uiState.value = SvgUiState.Success(listOf(newSvg) + currentSvgs)
6368
} else {

0 commit comments

Comments
 (0)