Skip to content

Commit c0fbec1

Browse files
committed
address review feedback
1 parent 03dff58 commit c0fbec1

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/hybrid/HybridInferenceViewModel.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class HybridInferenceViewModel : ViewModel() {
3939
val uiState: StateFlow<HybridInferenceUiState> = _uiState.asStateFlow()
4040

4141
private val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
42-
modelName = "gemini-3.1-flash-lite-preview",
43-
onDeviceConfig = OnDeviceConfig(mode = InferenceMode.PREFER_ON_DEVICE)
44-
)
42+
modelName = "gemini-3.1-flash-lite-preview",
43+
onDeviceConfig = OnDeviceConfig(mode = InferenceMode.PREFER_ON_DEVICE)
44+
)
4545

4646
init {
4747
checkAndDownloadModel()
@@ -103,7 +103,13 @@ class HybridInferenceViewModel : ViewModel() {
103103
try {
104104
val prompt = content {
105105
image(bitmap)
106-
text("Extract the store name and the total price from this receipt. Output only in CSV format like 'Store,Price'. Example: 'Starbucks,5.50'")
106+
text(
107+
"""
108+
Extract the store name and the total price from this receipt.
109+
Output only in CSV format like 'Store:Price'.
110+
Example: 'Starbucks:5.50'"
111+
""".trimIndent()
112+
)
107113
}
108114

109115
val response = model.generateContent(prompt)
@@ -127,7 +133,7 @@ class HybridInferenceViewModel : ViewModel() {
127133
// Simple parsing: "Store, Price"
128134
val parts = text
129135
// Sometimes the output contains single quotes
130-
.replace("'", "").split(",", limit = 2)
136+
.replace("'", "").split(":", limit = 2)
131137
if (parts.size >= 2) {
132138
val name = parts[0].trim()
133139
val priceStr = parts[1].trim().replace("$", "").replace(",", "")

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/ui/HybridInferenceScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ fun HybridInferenceScreen(
5252
val launcher = rememberLauncherForActivityResult(
5353
contract = ActivityResultContracts.PickVisualMedia(),
5454
onResult = { uri ->
55-
uri?.let {
55+
uri?.let { imageUri ->
5656
try {
57-
context.contentResolver.openInputStream(it)?.use { stream ->
57+
context.contentResolver.openInputStream(imageUri)?.use { stream ->
5858
val bitmap = BitmapFactory.decodeStream(stream)
5959
bitmap?.let { viewModel.scanReceipt(it) }
6060
}
6161
} catch (e: Exception) {
6262
// Handle error
63+
e.printStackTrace()
6364
}
6465
}
6566
}

0 commit comments

Comments
 (0)