Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
removed complaince text and added disclaimer
Browse files
app.py
CHANGED
@@ -27,6 +27,9 @@ SAMPLE_QUESTIONS = {
|
|
27 |
]
|
28 |
}
|
29 |
|
|
|
|
|
|
|
30 |
# Global variable to cache API results and prevent double calls
|
31 |
geojson_analysis_cache = {}
|
32 |
|
@@ -88,10 +91,14 @@ async def chat_response(query, history, method, country, uploaded_file):
|
|
88 |
|
89 |
except Exception as e:
|
90 |
response = f"Error retrieving information: {str(e)}"
|
|
|
|
|
|
|
91 |
|
|
|
92 |
displayed_response = ""
|
93 |
|
94 |
-
for i, char in enumerate(
|
95 |
displayed_response += char
|
96 |
history[-1] = (query, displayed_response)
|
97 |
yield history, "**Sources:** Sample source documents would appear here..."
|
@@ -100,13 +107,6 @@ async def chat_response(query, history, method, country, uploaded_file):
|
|
100 |
await asyncio.sleep(0.02)
|
101 |
|
102 |
|
103 |
-
# # Stream response word by word into the chat
|
104 |
-
# words = response.split()
|
105 |
-
|
106 |
-
# for i in range(len(words)):
|
107 |
-
# history[-1] = (query, " ".join(words[:i+1]))
|
108 |
-
# yield history, "**Sources:** Sample source documents would appear here..."
|
109 |
-
# await asyncio.sleep(0.05)
|
110 |
|
111 |
def auto_analyze_file(file, history):
|
112 |
"""Automatically analyze uploaded GeoJSON file and add results to chat"""
|
@@ -122,11 +122,11 @@ def auto_analyze_file(file, history):
|
|
122 |
|
123 |
# Add analysis results directly to chat (no intermediate message)
|
124 |
analysis_query = "📄 Análisis del GeoJSON cargado"
|
125 |
-
cached_result = geojson_analysis_cache[file_key]
|
126 |
|
127 |
# Add both query and response to history
|
128 |
history = history + [(analysis_query, cached_result)]
|
129 |
-
return history, "**Sources:** WhispAPI Analysis Results"
|
130 |
|
131 |
except Exception as e:
|
132 |
error_msg = f"❌ Error processing GeoJSON file: {str(e)}"
|
|
|
27 |
]
|
28 |
}
|
29 |
|
30 |
+
# Spanish disclaimer text
|
31 |
+
DISCLAIMER_TEXT = "\n\n---\n ⚠️ **Descargo de responsabilidad:** El chatbot EUDR puede cometer errores. Verifique la información importante con fuentes oficiales. \n"
|
32 |
+
|
33 |
# Global variable to cache API results and prevent double calls
|
34 |
geojson_analysis_cache = {}
|
35 |
|
|
|
91 |
|
92 |
except Exception as e:
|
93 |
response = f"Error retrieving information: {str(e)}"
|
94 |
+
|
95 |
+
# Add disclaimer to the response
|
96 |
+
response_with_disclaimer = response + DISCLAIMER_TEXT
|
97 |
|
98 |
+
|
99 |
displayed_response = ""
|
100 |
|
101 |
+
for i, char in enumerate(response_with_disclaimer):
|
102 |
displayed_response += char
|
103 |
history[-1] = (query, displayed_response)
|
104 |
yield history, "**Sources:** Sample source documents would appear here..."
|
|
|
107 |
await asyncio.sleep(0.02)
|
108 |
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
def auto_analyze_file(file, history):
|
112 |
"""Automatically analyze uploaded GeoJSON file and add results to chat"""
|
|
|
122 |
|
123 |
# Add analysis results directly to chat (no intermediate message)
|
124 |
analysis_query = "📄 Análisis del GeoJSON cargado"
|
125 |
+
cached_result = geojson_analysis_cache[file_key] + DISCLAIMER_TEXT
|
126 |
|
127 |
# Add both query and response to history
|
128 |
history = history + [(analysis_query, cached_result)]
|
129 |
+
return history, "**Sources:** WhispAPI Analysis Results"
|
130 |
|
131 |
except Exception as e:
|
132 |
error_msg = f"❌ Error processing GeoJSON file: {str(e)}"
|
utils/__pycache__/generator.cpython-310.pyc
CHANGED
Binary files a/utils/__pycache__/generator.cpython-310.pyc and b/utils/__pycache__/generator.cpython-310.pyc differ
|
|
utils/__pycache__/retriever.cpython-310.pyc
CHANGED
Binary files a/utils/__pycache__/retriever.cpython-310.pyc and b/utils/__pycache__/retriever.cpython-310.pyc differ
|
|
utils/__pycache__/whisp_api.cpython-310.pyc
CHANGED
Binary files a/utils/__pycache__/whisp_api.cpython-310.pyc and b/utils/__pycache__/whisp_api.cpython-310.pyc differ
|
|
utils/whisp_api.py
CHANGED
@@ -109,7 +109,7 @@ def format_whisp_statistics(df):
|
|
109 |
⚠️ **Deforestation Risk Assessment**
|
110 |
*Risk levels are based on historical patterns, environmental factors, and land use data* \n\n
|
111 |
|
112 |
-
-
|
113 |
- **Permanent Crops** : {format_risk(risk_pcrop)} \n\n
|
114 |
*Coffee, cocoa, palm oil, fruit trees* \n\n
|
115 |
- **Annual Crops**: {format_risk(risk_acrop)} \n\n
|
@@ -117,16 +117,11 @@ def format_whisp_statistics(df):
|
|
117 |
- **Timber Extraction**: {format_risk(risk_timber)} \n\n
|
118 |
*Logging and wood harvesting* \n\n
|
119 |
|
120 |
-
🌳 **
|
121 |
-
*Based on Tropical Moist Forest satellite monitoring* \n\n
|
122 |
-
|
123 |
-
**Recent Deforestation (2020-Present):** {deforestation_formatted} \n\n
|
124 |
-
|
125 |
-
**EUDR Compliance Status:** {compliance_status} \n\n
|
126 |
|
127 |
---
|
128 |
-
💡 **Key Insights**
|
129 |
-
\t
|
130 |
\t **Risk Factors**: Focus on {', '.join([t.split('*')[1].strip('*') for t in [risk_pcrop, risk_acrop, risk_timber] if 'High' in format_risk(t)])} if any high-risk activities detected \n\n
|
131 |
\t **Next Steps**: {"Conduct additional due diligence if recent deforestation is detected" if "ATTENTION" in compliance_status else "Continue monitoring and maintain documentation"} \n\n
|
132 |
"""
|
|
|
109 |
⚠️ **Deforestation Risk Assessment**
|
110 |
*Risk levels are based on historical patterns, environmental factors, and land use data* \n\n
|
111 |
|
112 |
+
- Overall Risk**: {format_risk(risk_level)} \n\n
|
113 |
- **Permanent Crops** : {format_risk(risk_pcrop)} \n\n
|
114 |
*Coffee, cocoa, palm oil, fruit trees* \n\n
|
115 |
- **Annual Crops**: {format_risk(risk_acrop)} \n\n
|
|
|
117 |
- **Timber Extraction**: {format_risk(risk_timber)} \n\n
|
118 |
*Logging and wood harvesting* \n\n
|
119 |
|
120 |
+
🌳 **Recent Deforestation (2020-Present):** {deforestation_formatted} \n\n
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
---
|
123 |
+
💡 **Key Insights**
|
124 |
+
\t
|
125 |
\t **Risk Factors**: Focus on {', '.join([t.split('*')[1].strip('*') for t in [risk_pcrop, risk_acrop, risk_timber] if 'High' in format_risk(t)])} if any high-risk activities detected \n\n
|
126 |
\t **Next Steps**: {"Conduct additional due diligence if recent deforestation is detected" if "ATTENTION" in compliance_status else "Continue monitoring and maintain documentation"} \n\n
|
127 |
"""
|