Spaces:
Sleeping
Sleeping
Update app.py
Browse filesswitch country iso-code to country name
app.py
CHANGED
@@ -4,6 +4,7 @@ from appStore.prep_data import process_giz_worldwide
|
|
4 |
from appStore.prep_utils import create_documents, get_client
|
5 |
from appStore.embed import hybrid_embed_chunks
|
6 |
from appStore.search import hybrid_search
|
|
|
7 |
from torch import cuda
|
8 |
import json
|
9 |
|
@@ -15,6 +16,10 @@ st.set_page_config(page_title="SEARCH IATI",layout='wide')
|
|
15 |
st.title("GIZ Project Database")
|
16 |
var = st.text_input("Enter Search Query")
|
17 |
|
|
|
|
|
|
|
|
|
18 |
#################### Create the embeddings collection and save ######################
|
19 |
# the steps below need to be performed only once and then commented out any unnecssary compute over-run
|
20 |
##### First we process and create the chunks for relvant data source
|
@@ -31,7 +36,7 @@ print(client.get_collections())
|
|
31 |
|
32 |
# Fetch unique country codes from the metadata for the dropdown
|
33 |
@st.cache_data
|
34 |
-
def
|
35 |
results = hybrid_search(_client, "", collection_name)
|
36 |
country_set = set()
|
37 |
for res in results[0] + results[1]:
|
@@ -41,9 +46,13 @@ def get_unique_countries(_client, collection_name):
|
|
41 |
country_set.update(country_list)
|
42 |
except json.JSONDecodeError:
|
43 |
pass
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
-
|
|
|
47 |
|
48 |
# Layout filters in columns
|
49 |
col1, col2, col3 = st.columns([1, 1, 4])
|
|
|
4 |
from appStore.prep_utils import create_documents, get_client
|
5 |
from appStore.embed import hybrid_embed_chunks
|
6 |
from appStore.search import hybrid_search
|
7 |
+
from appStore.region_utils import load_region_data, get_country_name
|
8 |
from torch import cuda
|
9 |
import json
|
10 |
|
|
|
16 |
st.title("GIZ Project Database")
|
17 |
var = st.text_input("Enter Search Query")
|
18 |
|
19 |
+
# Load the region lookup CSV
|
20 |
+
region_lookup_path = "docStore/regions_lookup.csv"
|
21 |
+
region_df = load_region_data(region_lookup_path)
|
22 |
+
|
23 |
#################### Create the embeddings collection and save ######################
|
24 |
# the steps below need to be performed only once and then commented out any unnecssary compute over-run
|
25 |
##### First we process and create the chunks for relvant data source
|
|
|
36 |
|
37 |
# Fetch unique country codes from the metadata for the dropdown
|
38 |
@st.cache_data
|
39 |
+
def get_unique_countries_with_names(_client, collection_name, region_df):
|
40 |
results = hybrid_search(_client, "", collection_name)
|
41 |
country_set = set()
|
42 |
for res in results[0] + results[1]:
|
|
|
46 |
country_set.update(country_list)
|
47 |
except json.JSONDecodeError:
|
48 |
pass
|
49 |
+
|
50 |
+
# Map ISO codes to country names
|
51 |
+
country_names = [get_country_name(code, region_df) for code in country_set]
|
52 |
+
return sorted(country_names)
|
53 |
|
54 |
+
client = get_client()
|
55 |
+
unique_countries = get_unique_countries_with_names(client, collection_name, region_df)
|
56 |
|
57 |
# Layout filters in columns
|
58 |
col1, col2, col3 = st.columns([1, 1, 4])
|