Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
added whisp api
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import time
|
|
|
3 |
from uuid import uuid4
|
|
|
4 |
|
5 |
# Sample questions for examples
|
6 |
SAMPLE_QUESTIONS = {
|
@@ -22,11 +24,40 @@ SAMPLE_QUESTIONS = {
|
|
22 |
}
|
23 |
|
24 |
def handle_geojson_upload(file):
|
25 |
-
"""Handle GeoJSON file upload"""
|
26 |
if file is not None:
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
else:
|
29 |
-
return
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def start_chat(query, history):
|
32 |
"""Start a new chat interaction"""
|
@@ -166,8 +197,15 @@ with gr.Blocks(title="EUDR Q&A", theme=theme, css="style.css") as demo:
|
|
166 |
file_types=[".geojson", ".json"],
|
167 |
file_count="single"
|
168 |
)
|
169 |
-
submit_file_btn = gr.Button("Submit GeoJSON", variant="primary")
|
170 |
upload_status = gr.Markdown("", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
# Talk to Reports Section
|
173 |
with gr.Group(visible=False) as reports_section:
|
@@ -228,7 +266,7 @@ with gr.Blocks(title="EUDR Q&A", theme=theme, css="style.css") as demo:
|
|
228 |
|
229 |
## 🔍 Using Data Sources
|
230 |
|
231 |
-
**Upload GeoJSON:** Upload your geographic data files for
|
232 |
**Talk to Reports:** Select Ecuador or Guatemala for country-specific EUDR analysis
|
233 |
|
234 |
## ⭐ Best Practices
|
@@ -249,7 +287,7 @@ with gr.Blocks(title="EUDR Q&A", theme=theme, css="style.css") as demo:
|
|
249 |
|
250 |
This AI-powered tool helps stakeholders:
|
251 |
- Understand EUDR compliance requirements
|
252 |
-
- Analyze geographic deforestation data
|
253 |
- Assess supply chain risks
|
254 |
- Navigate complex regulatory landscapes
|
255 |
|
@@ -257,7 +295,7 @@ with gr.Blocks(title="EUDR Q&A", theme=theme, css="style.css") as demo:
|
|
257 |
through advanced AI and geographic data processing capabilities.
|
258 |
|
259 |
### Key Features:
|
260 |
-
-
|
261 |
- Country-specific EUDR compliance guidance
|
262 |
- Real-time question answering with source citations
|
263 |
- User-friendly interface for complex regulatory information
|
@@ -274,9 +312,9 @@ with gr.Blocks(title="EUDR Q&A", theme=theme, css="style.css") as demo:
|
|
274 |
- Always consult qualified professionals for official compliance decisions
|
275 |
|
276 |
⚠️ **Data & Privacy:**
|
277 |
-
- Uploaded GeoJSON files are processed
|
278 |
- We collect usage statistics to improve the tool
|
279 |
-
-
|
280 |
|
281 |
⚠️ **AI Limitations:**
|
282 |
- Responses are AI-generated and may contain inaccuracies
|
@@ -298,11 +336,11 @@ with gr.Blocks(title="EUDR Q&A", theme=theme, css="style.css") as demo:
|
|
298 |
outputs=[geojson_section, reports_section, dropdown_country]
|
299 |
)
|
300 |
|
301 |
-
# File upload
|
302 |
-
|
303 |
fn=handle_geojson_upload,
|
304 |
inputs=[uploaded_file],
|
305 |
-
outputs=[upload_status, upload_status]
|
306 |
)
|
307 |
|
308 |
# Chat functionality
|
|
|
1 |
import gradio as gr
|
2 |
import time
|
3 |
+
import pandas as pd
|
4 |
from uuid import uuid4
|
5 |
+
from gradio_client import Client, handle_file
|
6 |
|
7 |
# Sample questions for examples
|
8 |
SAMPLE_QUESTIONS = {
|
|
|
24 |
}
|
25 |
|
26 |
def handle_geojson_upload(file):
|
27 |
+
"""Handle GeoJSON file upload and call WHISP API"""
|
28 |
if file is not None:
|
29 |
+
try:
|
30 |
+
# Initialize WHISP API client
|
31 |
+
client = Client("https://giz-chatfed-whisp.hf.space/")
|
32 |
+
|
33 |
+
# Call the API with the uploaded file
|
34 |
+
result = client.predict(
|
35 |
+
file=handle_file(file.name),
|
36 |
+
api_name="/get_statistics"
|
37 |
+
)
|
38 |
+
|
39 |
+
# Convert result to DataFrame
|
40 |
+
df = pd.DataFrame(result['data'], columns=result['headers'])
|
41 |
+
|
42 |
+
return (
|
43 |
+
"✅ GeoJSON file processed successfully! Analysis results are displayed below.",
|
44 |
+
gr.update(visible=True), # upload_status
|
45 |
+
gr.update(value=df, visible=True) # results_table
|
46 |
+
)
|
47 |
+
|
48 |
+
except Exception as e:
|
49 |
+
error_msg = f"❌ Error processing GeoJSON file: {str(e)}"
|
50 |
+
return (
|
51 |
+
error_msg,
|
52 |
+
gr.update(visible=True), # upload_status
|
53 |
+
gr.update(visible=False) # results_table
|
54 |
+
)
|
55 |
else:
|
56 |
+
return (
|
57 |
+
"",
|
58 |
+
gr.update(visible=False), # upload_status
|
59 |
+
gr.update(visible=False) # results_table
|
60 |
+
)
|
61 |
|
62 |
def start_chat(query, history):
|
63 |
"""Start a new chat interaction"""
|
|
|
197 |
file_types=[".geojson", ".json"],
|
198 |
file_count="single"
|
199 |
)
|
|
|
200 |
upload_status = gr.Markdown("", visible=False)
|
201 |
+
|
202 |
+
# Results table for WHISP API response
|
203 |
+
results_table = gr.DataFrame(
|
204 |
+
label="Analysis Results",
|
205 |
+
visible=False,
|
206 |
+
interactive=False,
|
207 |
+
wrap=True
|
208 |
+
)
|
209 |
|
210 |
# Talk to Reports Section
|
211 |
with gr.Group(visible=False) as reports_section:
|
|
|
266 |
|
267 |
## 🔍 Using Data Sources
|
268 |
|
269 |
+
**Upload GeoJSON:** Upload your geographic data files for automatic analysis via WHISP API
|
270 |
**Talk to Reports:** Select Ecuador or Guatemala for country-specific EUDR analysis
|
271 |
|
272 |
## ⭐ Best Practices
|
|
|
287 |
|
288 |
This AI-powered tool helps stakeholders:
|
289 |
- Understand EUDR compliance requirements
|
290 |
+
- Analyze geographic deforestation data using WHISP API
|
291 |
- Assess supply chain risks
|
292 |
- Navigate complex regulatory landscapes
|
293 |
|
|
|
295 |
through advanced AI and geographic data processing capabilities.
|
296 |
|
297 |
### Key Features:
|
298 |
+
- Automatic analysis of uploaded GeoJSON files via WHISP API
|
299 |
- Country-specific EUDR compliance guidance
|
300 |
- Real-time question answering with source citations
|
301 |
- User-friendly interface for complex regulatory information
|
|
|
312 |
- Always consult qualified professionals for official compliance decisions
|
313 |
|
314 |
⚠️ **Data & Privacy:**
|
315 |
+
- Uploaded GeoJSON files are processed via external WHISP API for analysis
|
316 |
- We collect usage statistics to improve the tool
|
317 |
+
- Files are processed temporarily and not permanently stored
|
318 |
|
319 |
⚠️ **AI Limitations:**
|
320 |
- Responses are AI-generated and may contain inaccuracies
|
|
|
336 |
outputs=[geojson_section, reports_section, dropdown_country]
|
337 |
)
|
338 |
|
339 |
+
# File upload - automatically process when file is uploaded
|
340 |
+
uploaded_file.change(
|
341 |
fn=handle_geojson_upload,
|
342 |
inputs=[uploaded_file],
|
343 |
+
outputs=[upload_status, upload_status, results_table]
|
344 |
)
|
345 |
|
346 |
# Chat functionality
|