Skip to content

Commit 4d179dc

Browse files
committed
Fix JSON parsing, cleanup TTS text, add fellow farmers, change apply button
1 parent a5e3007 commit 4d179dc

6 files changed

Lines changed: 39 additions & 6 deletions

File tree

app/src/main/java/com/example/ChatScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ fun ChatBubble(msg: ChatMessage, tts: android.speech.tts.TextToSpeech?) {
334334
.clip(RoundedCornerShape(8.dp))
335335
.background(NuKropAccent.copy(alpha = 0.15f))
336336
.clickable {
337-
tts?.speak(msg.text, android.speech.tts.TextToSpeech.QUEUE_FLUSH, null, null)
337+
val cleanText = msg.text.replace(Regex("[*#~_]"), "").replace("-", " ")
338+
tts?.speak(cleanText, android.speech.tts.TextToSpeech.QUEUE_FLUSH, null, null)
338339
}
339340
.padding(horizontal = 8.dp, vertical = 4.dp)
340341
) {

app/src/main/java/com/example/DiseaseScannerScreen.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ data class SoilScanData(
6464
)
6565

6666
fun parseCropJson(raw: String): CropScanData? = runCatching {
67-
val start = raw.indexOf('{'); val end = raw.lastIndexOf('}'); if (start == -1 || end == -1) throw Exception("No JSON found")
68-
val j = org.json.JSONObject(raw.substring(start, end + 1))
67+
val cleanRaw = raw.replace(Regex("<think>.*?</think>", RegexOption.DOT_MATCHES_ALL), "").trim()
68+
val start = cleanRaw.indexOf('{'); val end = cleanRaw.lastIndexOf('}'); if (start == -1 || end == -1) throw Exception("No JSON found")
69+
val j = org.json.JSONObject(cleanRaw.substring(start, end + 1))
6970
val prods = j.optJSONArray("products")?.let { arr ->
7071
(0 until arr.length()).mapNotNull { i ->
7172
val obj = arr.optJSONObject(i) ?: return@mapNotNull null
@@ -85,8 +86,9 @@ fun parseCropJson(raw: String): CropScanData? = runCatching {
8586
}.getOrNull()
8687

8788
fun parseSoilJson(raw: String): SoilScanData? = runCatching {
88-
val start = raw.indexOf('{'); val end = raw.lastIndexOf('}'); if (start == -1 || end == -1) throw Exception("No JSON found")
89-
val j = org.json.JSONObject(raw.substring(start, end + 1))
89+
val cleanRaw = raw.replace(Regex("<think>.*?</think>", RegexOption.DOT_MATCHES_ALL), "").trim()
90+
val start = cleanRaw.indexOf('{'); val end = cleanRaw.lastIndexOf('}'); if (start == -1 || end == -1) throw Exception("No JSON found")
91+
val j = org.json.JSONObject(cleanRaw.substring(start, end + 1))
9092
val defs = j.optJSONArray("likelyDeficiencies")?.let { arr -> (0 until arr.length()).map { i -> arr.optString(i) } } ?: emptyList()
9193
val crops = j.optJSONArray("suitableCrops")?.let { arr -> (0 until arr.length()).map { i -> arr.optString(i) } } ?: emptyList()
9294
val ferts = j.optJSONArray("fertilizers")?.let { arr ->

app/src/main/java/com/example/GeminiVisionService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ object GeminiVisionService {
7171
val body = """
7272
{
7373
"model": "$model",
74+
"response_format": {"type": "json_object"},
7475
"messages": [
7576
{
7677
"role": "user",

app/src/main/java/com/example/HomeScreen.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,35 @@ fun HomeScreen(
219219
}
220220
}
221221

222+
Spacer(Modifier.height(32.dp))
223+
224+
// Fellow Farmers Near You
225+
Row(Modifier.padding(horizontal = 16.dp), verticalAlignment = Alignment.CenterVertically) {
226+
Icon(Icons.Filled.Group, contentDescription = null, tint = NuKropAccent, modifier = Modifier.size(16.dp))
227+
Spacer(Modifier.width(8.dp))
228+
Text("Fellow Farmers Near You", color = NuKropText, fontSize = 16.sp, fontWeight = FontWeight.Bold)
229+
}
230+
Spacer(Modifier.height(12.dp))
231+
Box(Modifier.padding(horizontal = 16.dp).fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(NuKropCard).border(1.dp, NuKropBadgeGreen.copy(alpha=0.3f), RoundedCornerShape(16.dp)).padding(16.dp)) {
232+
Column {
233+
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
234+
Row(verticalAlignment = Alignment.CenterVertically) {
235+
Box(modifier = Modifier.size(36.dp).clip(androidx.compose.foundation.shape.CircleShape).background(NuKropAccent.copy(alpha=0.2f)), contentAlignment = Alignment.Center) {
236+
Text("R", color = NuKropAccent, fontWeight = FontWeight.Bold)
237+
}
238+
Spacer(Modifier.width(12.dp))
239+
Column {
240+
Text("Ramesh Singh", color = NuKropText, fontSize = 14.sp, fontWeight = FontWeight.Bold)
241+
Text("Growing Wheat • 2.5 km away", color = NuKropTextMuted, fontSize = 11.sp)
242+
}
243+
}
244+
Button(onClick = {}, colors = ButtonDefaults.buttonColors(containerColor = NuKropAccent.copy(alpha=0.15f)), contentPadding = PaddingValues(0.dp), modifier = Modifier.size(70.dp, 30.dp), shape = RoundedCornerShape(8.dp)) {
245+
Text("Connect", color = NuKropAccent, fontSize = 11.sp, fontWeight = FontWeight.Bold)
246+
}
247+
}
248+
}
249+
}
250+
222251
Spacer(Modifier.height(40.dp))
223252
}
224253
}

app/src/main/java/com/example/LoanScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fun SchemeCard(title: String, amount: String, desc: String, accent: Color) {
165165
) {
166166
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
167167
Icon(Icons.Default.Edit, null, tint = accent, modifier = Modifier.size(16.dp))
168-
Text("Auto-Fill Application", color = accent, fontSize = 12.sp, fontWeight = FontWeight.Bold)
168+
Text("Apply Now", color = accent, fontSize = 12.sp, fontWeight = FontWeight.Bold)
169169
}
170170
}
171171
}

web/public/NuKropAI_v1.0.apk

8.18 KB
Binary file not shown.

0 commit comments

Comments
 (0)