Skip to content

Commit 0e5ff92

Browse files
Gemini Image chat sample (#87)
Co-authored-by: lethargicpanda <[email protected]>
1 parent ddfec12 commit 0e5ff92

File tree

13 files changed

+654
-0
lines changed

13 files changed

+654
-0
lines changed

ai-catalog/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ dependencies {
9090
implementation(project(":samples:gemini-video-summarization"))
9191
implementation(project(":samples:gemini-live-todo"))
9292
implementation(project(":samples:gemini-video-metadata-creation"))
93+
implementation(project(":samples:gemini-image-chat"))
9394

9495
testImplementation(libs.junit)
9596
androidTestImplementation(libs.androidx.junit)

ai-catalog/app/src/main/java/com/android/ai/catalog/ui/domain/SampleCatalog.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable
2020
import androidx.compose.ui.graphics.Color
2121
import com.android.ai.catalog.R
2222
import com.android.ai.samples.geminichatbot.GeminiChatbotScreen
23+
import com.android.ai.samples.geminiimagechat.GeminiImageChatScreen
2324
import com.android.ai.samples.geminilivetodo.ui.TodoScreen
2425
import com.android.ai.samples.geminimultimodal.ui.GeminiMultimodalScreen
2526
import com.android.ai.samples.geminivideometadatacreation.VideoMetadataCreationScreen
@@ -32,6 +33,14 @@ import com.android.ai.samples.magicselfie.ui.MagicSelfieScreen
3233

3334
@androidx.annotation.RequiresPermission(android.Manifest.permission.RECORD_AUDIO)
3435
val sampleCatalog = listOf(
36+
SampleCatalogItem(
37+
title = R.string.gemini_image_chat,
38+
description = R.string.gemini_image_chat_description,
39+
route = "GeminiImageChatScreen",
40+
sampleEntryScreen = { GeminiImageChatScreen() },
41+
tags = listOf(SampleTags.GEMINI_FLASH, SampleTags.FIREBASE),
42+
needsFirebase = true,
43+
),
3544
SampleCatalogItem(
3645
title = R.string.gemini_multimodal_sample_title,
3746
description = R.string.gemini_multimodal_sample_description,

ai-catalog/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<string name="gemini_video_metadata_creation_sample_description">"Generate metadata of a video (from a cloud URL or Youtube) with Gemini API powered by Firebase"</string>
2323
<string name="gemini_live_todo_title">Gemini Live Todo</string>
2424
<string name="gemini_live_todo_description">"Simple Todo app using the Gemini Live API to interact with the items in the list"</string>
25+
<string name="gemini_image_chat">Gemini Image Chat</string>
26+
<string name="gemini_image_chat_description">Conversational Image generation with Gemini</string>
2527
<string name="firebase_required">Firebase Required</string>
2628
<string name="firebase_required_description">This feature requires Firebase to be initialized.</string>
2729
<string name="close">Close</string>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
alias(libs.plugins.android.library)
19+
alias(libs.plugins.jetbrains.kotlin.android)
20+
alias(libs.plugins.ksp)
21+
alias(libs.plugins.compose.compiler)
22+
}
23+
24+
android {
25+
namespace = "com.android.ai.samples.geminiimagechat"
26+
compileSdk = 35
27+
28+
buildFeatures {
29+
compose = true
30+
}
31+
32+
defaultConfig {
33+
minSdk = 24
34+
35+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
36+
consumerProguardFiles("consumer-rules.pro")
37+
}
38+
39+
buildTypes {
40+
release {
41+
isMinifyEnabled = false
42+
proguardFiles(
43+
getDefaultProguardFile("proguard-android-optimize.txt"),
44+
"proguard-rules.pro",
45+
)
46+
}
47+
}
48+
compileOptions {
49+
sourceCompatibility = JavaVersion.VERSION_17
50+
targetCompatibility = JavaVersion.VERSION_17
51+
}
52+
kotlinOptions {
53+
jvmTarget = "17"
54+
}
55+
}
56+
57+
dependencies {
58+
59+
implementation(libs.androidx.core.ktx)
60+
implementation(libs.androidx.appcompat)
61+
implementation(platform(libs.androidx.compose.bom))
62+
implementation(libs.androidx.material.icons.extended)
63+
implementation(platform(libs.firebase.bom))
64+
implementation(libs.firebase.ai)
65+
implementation(libs.hilt.android)
66+
implementation(libs.hilt.navigation.compose)
67+
implementation(libs.androidx.lifecycle.runtime.compose)
68+
implementation(libs.androidx.material3.android)
69+
implementation(libs.coil.compose)
70+
ksp(libs.hilt.compiler)
71+
72+
testImplementation(libs.junit)
73+
androidTestImplementation(libs.androidx.junit)
74+
androidTestImplementation(libs.androidx.espresso.core)
75+
}

ai-catalog/samples/gemini-image-chat/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.android.ai.samples.geminiimagechat
17+
18+
import android.graphics.Bitmap
19+
import android.net.Uri
20+
21+
data class ChatMessage(
22+
val text: String,
23+
val timestamp: Long,
24+
val isIncoming: Boolean = false,
25+
val senderIconUrl: Uri? = null,
26+
val image: Bitmap? = null,
27+
)

0 commit comments

Comments
 (0)