Spaces:
Sleeping
Sleeping
Commit ·
15baaaf
1
Parent(s): f11af9a
Fix: extract Sentinel-2 vegetation_indices_summary and SAR crop_health
Browse files- app.py +11 -10
- context_aggregator.py +10 -9
app.py
CHANGED
|
@@ -317,18 +317,19 @@ def build_llm_prompt(query: str, context: Dict, history: List[Dict] = None) -> s
|
|
| 317 |
vi_lines.append(f"- {name}: {mean:.4f}{change_str}" if isinstance(mean, float) else f"- {name}: {mean}")
|
| 318 |
context_parts.append("\n".join(vi_lines))
|
| 319 |
|
| 320 |
-
# SAR
|
| 321 |
if context.get("sar_bands"):
|
| 322 |
sar = context["sar_bands"]
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
context_parts.append(f"""## SAR
|
| 328 |
-
-
|
| 329 |
-
-
|
| 330 |
-
-
|
| 331 |
-
-
|
|
|
|
| 332 |
|
| 333 |
# Soil indicators
|
| 334 |
if context.get("soil_indicators"):
|
|
|
|
| 317 |
vi_lines.append(f"- {name}: {mean:.4f}{change_str}" if isinstance(mean, float) else f"- {name}: {mean}")
|
| 318 |
context_parts.append("\n".join(vi_lines))
|
| 319 |
|
| 320 |
+
# SAR Analysis (crop health from SAR data)
|
| 321 |
if context.get("sar_bands"):
|
| 322 |
sar = context["sar_bands"]
|
| 323 |
+
health = sar.get("crop_health", "unknown")
|
| 324 |
+
stress = sar.get("stress_score", 0)
|
| 325 |
+
summary = sar.get("summary", "")
|
| 326 |
+
recs = sar.get("recommendations", [])
|
| 327 |
+
context_parts.append(f"""## SAR Crop Health Analysis
|
| 328 |
+
- Overall Health: {health}
|
| 329 |
+
- Stress Score: {stress:.2f if isinstance(stress, float) else stress}
|
| 330 |
+
- Confidence: {sar.get('confidence', 0)}%
|
| 331 |
+
- Summary: {summary[:200] if summary else 'N/A'}
|
| 332 |
+
- Top Recommendation: {recs[0] if recs else 'No specific recommendations'}""")
|
| 333 |
|
| 334 |
# Soil indicators
|
| 335 |
if context.get("soil_indicators"):
|
context_aggregator.py
CHANGED
|
@@ -234,15 +234,15 @@ class ContextAggregator:
|
|
| 234 |
# =========================================================================
|
| 235 |
|
| 236 |
def _extract_sar_bands(self, data: Dict) -> Dict:
|
| 237 |
-
"""Extract SAR
|
| 238 |
-
|
| 239 |
return {
|
| 240 |
-
"
|
| 241 |
-
"
|
| 242 |
-
"
|
| 243 |
-
"
|
| 244 |
-
"
|
| 245 |
-
"
|
| 246 |
}
|
| 247 |
|
| 248 |
def _interpret_sar(self, vv: Optional[float], vh: Optional[float]) -> str:
|
|
@@ -260,7 +260,8 @@ class ContextAggregator:
|
|
| 260 |
|
| 261 |
def _extract_vegetation_indices(self, data: Dict) -> Dict:
|
| 262 |
"""Extract and structure vegetation indices."""
|
| 263 |
-
|
|
|
|
| 264 |
|
| 265 |
result = {}
|
| 266 |
for idx in ["ndvi", "evi", "ndre", "reci", "ndwi", "smi", "psri", "pri", "mcari"]:
|
|
|
|
| 234 |
# =========================================================================
|
| 235 |
|
| 236 |
def _extract_sar_bands(self, data: Dict) -> Dict:
|
| 237 |
+
"""Extract SAR analysis data."""
|
| 238 |
+
# SAR API returns: status, crop_health, health_summary, average_stress_score, etc.
|
| 239 |
return {
|
| 240 |
+
"crop_health": data.get("crop_health", "unknown"),
|
| 241 |
+
"confidence": data.get("confidence_score", 0),
|
| 242 |
+
"stress_score": data.get("average_stress_score", 0),
|
| 243 |
+
"summary": data.get("summary", ""),
|
| 244 |
+
"health_summary": data.get("health_summary", {}),
|
| 245 |
+
"recommendations": data.get("recommendations", [])
|
| 246 |
}
|
| 247 |
|
| 248 |
def _interpret_sar(self, vv: Optional[float], vh: Optional[float]) -> str:
|
|
|
|
| 260 |
|
| 261 |
def _extract_vegetation_indices(self, data: Dict) -> Dict:
|
| 262 |
"""Extract and structure vegetation indices."""
|
| 263 |
+
# Try both possible keys from API response
|
| 264 |
+
veg = data.get("vegetation_indices", {}) or data.get("vegetation_indices_summary", {})
|
| 265 |
|
| 266 |
result = {}
|
| 267 |
for idx in ["ndvi", "evi", "ndre", "reci", "ndwi", "smi", "psri", "pri", "mcari"]:
|