antes do ollama

This commit is contained in:
2026-06-18 11:15:49 +01:00
parent 04ce7ece4f
commit 55560a1bfb
4 changed files with 21 additions and 13 deletions

View File

@@ -47,7 +47,7 @@ public class InvoiceScannerHelper {
}
GenerativeModel gm = new GenerativeModel(
"gemini-2.5-flash",
"gemini-1.5-flash",
API_KEY
);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
@@ -65,13 +65,19 @@ public class InvoiceScannerHelper {
try {
String textResponse = result.getText();
if (textResponse != null) {
textResponse = textResponse.replace("```json", "").replace("```", "").trim();
JSONObject json = new JSONObject(textResponse);
double valor = json.optDouble("valor", 0.0);
String descricao = json.optString("descricao", "");
String categoria = json.optString("categoria", "Outros");
String data = json.optString("data", "");
callback.onSuccess(valor, descricao, categoria, data);
int start = textResponse.indexOf("{");
int end = textResponse.lastIndexOf("}");
if (start != -1 && end != -1 && end > start) {
String jsonContent = textResponse.substring(start, end + 1);
JSONObject json = new JSONObject(jsonContent);
double valor = json.optDouble("valor", 0.0);
String descricao = json.optString("descricao", "");
String categoria = json.optString("categoria", "Outros");
String data = json.optString("data", "");
callback.onSuccess(valor, descricao, categoria, data);
} else {
callback.onError("Não foi possível extrair os dados formatados em JSON.");
}
} else {
callback.onError("Resposta vazia da IA.");
}

View File

@@ -7,7 +7,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/adicionarCardView"
android:layout_width="364dp"
android:layout_width="391dp"
android:layout_height="match_parent"
android:layout_marginTop="544dp"
android:background="@drawable/cardview_background"

View File

@@ -54,18 +54,19 @@
tools:text="Criptomoedas" />
<!-- Quantity and Purchase Price -->
<!-- Delete Button -->
<TextView
android:id="@+id/tvInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginTop="12dp"
android:textColor="#6b7280"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/tvNome"
app:layout_constraintTop_toBottomOf="@id/tvTipo"
tools:text="12 unidades x 16.10€" />
<!-- Delete Button -->
<ImageView
android:id="@+id/btnDelete"
android:layout_width="28dp"
@@ -111,6 +112,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:textColor="#16a34a"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"