Spaces:
GIZ
/
Running on CPU Upgrade

File size: 1,079 Bytes
f9f731c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from gradio_client import Client
import logging

def retrieve_paragraphs(query, category = None):
    """Connect to retriever and retrieve paragraphs"""
    try:   
        # Call the API with the uploaded file
        client = Client("https://giz-chatfed-retriever0-3.hf.space/")
        print("calling retriever at https://giz-chatfed-retriever0-3.hf.space/", flush=True)
        logging.info("calling retriever at https://giz-chatfed-retriever0-3.hf.space")
        filter_metadata = None
        if category:
            filter_metadata = {'category': category}
        result = client.predict(
                query=query,
                collection_name= "Humboldt",
                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
            )