Spaces:
GIZ
/
Running on CPU Upgrade

File size: 1,363 Bytes
56217e4
 
 
 
941faf0
 
 
 
 
 
 
 
 
 
 
 
 
56217e4
4b1c32c
 
56217e4
78c9684
4b1c32c
 
 
 
56217e4
 
78c9684
4b1c32c
56217e4
78c9684
b52ae58
5cfa298
56217e4
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
from gradio_client import Client


def retrieve_paragraphs(query:str, country:dict):
    """Connect to retriever and retrieve paragraphs, the collection param is fixed in qdrant-client call within code.
    
    Params
    ----------
    query: the query input by user
    country: collection 'EUDR' can filter the results based on country field. Past the values of country as str (single) or list
    
    Returns
    -----------
    Returns the top 10 retrieved>reranked results list of dict [{'answer':.....,'answer_metadata': {.....}}]

    """
    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
            )