Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
move retriever functions
Browse files- app.py +1 -29
- utils/__pycache__/retriever.cpython-310.pyc +0 -0
- utils/retriever.py +31 -0
app.py
CHANGED
@@ -5,6 +5,7 @@ import asyncio
|
|
5 |
from uuid import uuid4
|
6 |
from gradio_client import Client, handle_file
|
7 |
from utils.whisp_api import handle_geojson_upload
|
|
|
8 |
|
9 |
# Sample questions for examples
|
10 |
SAMPLE_QUESTIONS = {
|
@@ -26,35 +27,6 @@ SAMPLE_QUESTIONS = {
|
|
26 |
}
|
27 |
|
28 |
|
29 |
-
|
30 |
-
def retrieve_paragraphs(query):
|
31 |
-
"""Connect to retriever and retrieve paragraphs"""
|
32 |
-
try:
|
33 |
-
# Call the API with the uploaded file
|
34 |
-
client = Client("https://giz-eudr-retriever.hf.space/")
|
35 |
-
result = client.predict(
|
36 |
-
query=query,
|
37 |
-
reports_filter="",
|
38 |
-
sources_filter="",
|
39 |
-
subtype_filter="",
|
40 |
-
year_filter="",
|
41 |
-
api_name="/retrieve"
|
42 |
-
)
|
43 |
-
print(result)
|
44 |
-
return (
|
45 |
-
result,
|
46 |
-
gr.update(visible=True), # Keep status visible
|
47 |
-
gr.update(visible=False) # Always hide results table
|
48 |
-
)
|
49 |
-
|
50 |
-
except Exception as e:
|
51 |
-
error_msg = f"Error retrieving paragraphs: {str(e)}"
|
52 |
-
return (
|
53 |
-
error_msg,
|
54 |
-
gr.update(visible=True), # upload_status
|
55 |
-
gr.update(visible=False) # results_table
|
56 |
-
)
|
57 |
-
|
58 |
def start_chat(query, history):
|
59 |
"""Start a new chat interaction"""
|
60 |
history = history + [(query, None)]
|
|
|
5 |
from uuid import uuid4
|
6 |
from gradio_client import Client, handle_file
|
7 |
from utils.whisp_api import handle_geojson_upload
|
8 |
+
from utils.retriever import retrieve_paragraphs
|
9 |
|
10 |
# Sample questions for examples
|
11 |
SAMPLE_QUESTIONS = {
|
|
|
27 |
}
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def start_chat(query, history):
|
31 |
"""Start a new chat interaction"""
|
32 |
history = history + [(query, None)]
|
utils/__pycache__/retriever.cpython-310.pyc
ADDED
Binary file (790 Bytes). View file
|
|
utils/retriever.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
|
5 |
+
def retrieve_paragraphs(query):
|
6 |
+
"""Connect to retriever and retrieve paragraphs"""
|
7 |
+
try:
|
8 |
+
# Call the API with the uploaded file
|
9 |
+
client = Client("https://giz-eudr-retriever.hf.space/")
|
10 |
+
result = client.predict(
|
11 |
+
query=query,
|
12 |
+
reports_filter="",
|
13 |
+
sources_filter="",
|
14 |
+
subtype_filter="",
|
15 |
+
year_filter="",
|
16 |
+
api_name="/retrieve"
|
17 |
+
)
|
18 |
+
print(result)
|
19 |
+
return (
|
20 |
+
result,
|
21 |
+
gr.update(visible=True), # Keep status visible
|
22 |
+
gr.update(visible=False) # Always hide results table
|
23 |
+
)
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
error_msg = f"Error retrieving paragraphs: {str(e)}"
|
27 |
+
return (
|
28 |
+
error_msg,
|
29 |
+
gr.update(visible=True), # upload_status
|
30 |
+
gr.update(visible=False) # results_table
|
31 |
+
)
|