Skip to content

Commit f34c586

Browse files
Add a readme.md for nano banana sample (#97)
1 parent b5597fc commit f34c586

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Gemini Image Chat Sample
2+
3+
This sample is part of the [AI Sample Catalog](../../). To build and run this sample, you should clone the entire repository.
4+
5+
## Description
6+
7+
This sample demonstrates a chat bot using `Gemini 2.5 Flash Image` (a.k.a [Nano Banana](https://developers.googleblog.com/en/introducing-gemini-2-5-flash-image/)) that can understand both text and images and generate images and text in return. Users can send a message that includes an image, and the generative model will respond based on the multimodal input. This showcases how to build powerful, interactive image generation chat experiences with the Gemini API.
8+
9+
<div style="text-align: center;">
10+
<img width="320" alt="Gemini Image chat in action" src="android_nano_banana.png" />
11+
</div>
12+
13+
## How it works
14+
15+
The application uses the Firebase AI SDK (see [How to run](../../#how-to-run)) for Android to interact with the `Gemini 2.5 Flash Image` model. The core logic is in the `GeminiImageChatViewModel.kt` file. When a user sends a message with an image, a `content` block is created that includes both the text and the `Bitmap` of the image. This multimodal content is then sent to the model.
16+
17+
Here is the key snippet of code that calls the generative model:
18+
19+
```kotlin
20+
val content = content {
21+
text(message)
22+
if (bitmap != null) {
23+
image(bitmap)
24+
}
25+
}
26+
val response = chat.sendMessage(content)
27+
```
28+
29+
Read more about [image generation with Gemini](https://developer.android.com/ai/gemini/developer-api#generate-images) in the Android Documentation.
1.35 MB
Loading

0 commit comments

Comments
 (0)