Spaces:
GIZ
/
Running on CPU Upgrade

Asistente_EUDR / utils /retriever.py
leavoigt's picture
make country selection non-optional
4b1c32c
raw
history blame
945 Bytes
import gradio as gr
from gradio_client import Client
def retrieve_paragraphs(query, country):
"""Connect to retriever and retrieve paragraphs"""
try:
# Metadata selection
# Call the API with the uploaded file
client = Client("https://giz-chatfed-retriever0-3.hf.space/")
# Only create filter_metadata if country has a value
filter_metadata = {'country': country} if country is not None else None
result = client.predict(
query=query,
collection_name= "EUDR",
filter_metadata = filter_metadata,
api_name="/retrieve"
)
return result
except Exception as e:
error_msg = f"Error retrieving paragraphs: {str(e)}"
return (
error_msg,
gr.update(visible=True), # upload_status
gr.update(visible=False) # results_table
)