leavoigt commited on
Commit
33a80f5
verified
1 Parent(s): 276b7df

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +50 -6
app/main.py CHANGED
@@ -68,26 +68,70 @@ def format_whisp_statistics(df):
68
  def_after_2020_raw = get_value(df, "TMF_def_after_2020")
69
  def_before_2020_raw = get_value(df, "TMF_def_before_2020")
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  # Format for RAG context
72
- context = f"""=== AN脕LISIS GEOGR脕FICO WHISP API ===
 
 
 
 
 
73
 
74
- 馃搷 Detalles de la ubicaci贸n
75
 
76
  - Pa铆s: {country}
77
  - Regi贸n administrativa: {admin_level}
78
  - 脕rea total: {area_text}
79
 
80
- 鈿狅笍 Evaluaci贸n del riesgo de deforestaci贸n
81
  Los niveles de riesgo se basan en patrones hist贸ricos, factores ambientales y datos sobre el uso del suelo.
82
 
83
  - Cultivos permanentes (Caf茅, cacao, aceite de palma): {risk_pcrop}
84
  - Cultivos anuales (Soja, ma铆z, arroz): {risk_acrop}
85
  - Extracci贸n de madera: {risk_timber}
86
 
87
- 馃尦 Datos de deforestaci贸n:
88
 
89
- - Deforestaci贸n antes de 2020: {def_before_2020_raw} hect谩reas
90
- - Deforestaci贸n despu茅s de 2020: {def_after_2020_raw} hect谩reas
91
 
92
  Fuente: Forest Data Partnership (FDaP) WhispAPI
93
  Fecha de an谩lisis: {datetime.now().isoformat()}"""
 
68
  def_after_2020_raw = get_value(df, "TMF_def_after_2020")
69
  def_before_2020_raw = get_value(df, "TMF_def_before_2020")
70
 
71
+
72
+ # Helper function to format risk levels with colors/emojis
73
+ def format_risk(risk_val):
74
+ if not risk_val or risk_val in ["Not available", "not available"]:
75
+ return "**No disponible**"
76
+ elif isinstance(risk_val, str):
77
+ risk_lower = risk_val.lower().strip()
78
+ if risk_lower == "low":
79
+ return "*riesgo bajo*"
80
+ elif risk_lower == "medium":
81
+ return "*riesgo medio*"
82
+ elif risk_lower == "high":
83
+ return "*riesgo alto*"
84
+ elif risk_lower == "very high":
85
+ return "*riesgo muy alto*"
86
+ elif risk_lower == "more_info_needed":
87
+ return "*Se necesita m谩s informaci贸n.*"
88
+ else:
89
+ return f"鈩癸笍 **{risk_val.title()}**"
90
+ return str(risk_val)
91
+
92
+ # Format deforestation data
93
+ def format_deforestation(def_val):
94
+ if not def_val or def_val in ["Not available", "not available"]:
95
+ return "*No disponible*"
96
+ try:
97
+ def_num = float(def_val)
98
+ if def_num == 0:
99
+ return "* No se detect贸 deforestaci贸n.*"
100
+ elif def_num < 0.1:
101
+ return f"*{def_num:.3f} hect谩reas*"
102
+ else:
103
+ return f"*{def_num:.2f} hect谩reas*"
104
+ except:
105
+ return f"鈩癸笍 **{def_val}**"
106
+
107
+ deforestation_after_2020_formatted = format_deforestation(def_after_2020_raw)
108
+ deforestation_before_2020_formatted = format_deforestation(def_before_2020_raw)
109
+
110
  # Format for RAG context
111
+ context = f"""
112
+
113
+ **Respuesta generada mediante inteligencia artific铆al:** \n\n
114
+
115
+ **Resultados del an谩lisis geogr谩fico** \n\n
116
+ La siguiente informaci贸n ha sido generada por la [WhispAPI creada por Forest Data Partnership (FDaP)](https://openforis.org/solutions/whisp/).
117
 
118
+ 馃搷 **Detalles de la ubicaci贸n:**
119
 
120
  - Pa铆s: {country}
121
  - Regi贸n administrativa: {admin_level}
122
  - 脕rea total: {area_text}
123
 
124
+ 鈿狅笍 **Evaluaci贸n del riesgo de deforestaci贸n:**
125
  Los niveles de riesgo se basan en patrones hist贸ricos, factores ambientales y datos sobre el uso del suelo.
126
 
127
  - Cultivos permanentes (Caf茅, cacao, aceite de palma): {risk_pcrop}
128
  - Cultivos anuales (Soja, ma铆z, arroz): {risk_acrop}
129
  - Extracci贸n de madera: {risk_timber}
130
 
131
+ 馃尦 **Datos de deforestaci贸n:**
132
 
133
+ - Deforestaci贸n antes de 2020: {deforestation_before_2020_formatted}
134
+ - Deforestaci贸n despu茅s de 2020: {deforestation_after_2020_formatted}
135
 
136
  Fuente: Forest Data Partnership (FDaP) WhispAPI
137
  Fecha de an谩lisis: {datetime.now().isoformat()}"""