annikwag commited on
Commit
0f39553
·
verified ·
1 Parent(s): 7b37585

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -12
app.py CHANGED
@@ -168,43 +168,31 @@ collection_name = "giz_worldwide"
168
  ################### Hybrid Search #####################################################
169
  client = get_client()
170
  print(client.get_collections())
171
-
172
- # Get the maximum end_year across the entire collection
173
  max_end_year = get_max_end_year(client, collection_name)
174
-
175
- # Get all unique sub-regions
176
  _, unique_sub_regions = get_regions(region_df)
177
 
178
- # Fetch unique country codes and map to country names
179
  @st.cache_data
180
  def get_country_name_and_region_mapping(_client, collection_name, region_df):
181
  results = hybrid_search(_client, "", collection_name)
182
  country_set = set()
183
-
184
  for res in results[0] + results[1]:
185
  countries = res.payload.get('metadata', {}).get('countries', "[]")
186
  try:
187
  country_list = json.loads(countries.replace("'", '"'))
188
- # Only add codes of length 2
189
  two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
190
  country_set.update(two_digit_codes)
191
  except json.JSONDecodeError:
192
  pass
193
-
194
- # Create a mapping of {CountryName -> ISO2Code} and {ISO2Code -> SubRegion}
195
  country_name_to_code = {}
196
  iso_code_to_sub_region = {}
197
-
198
  for code in country_set:
199
  name = get_country_name(code, region_df)
200
  sub_region_row = region_df[region_df['alpha-2'] == code]
201
  sub_region = sub_region_row['sub-region'].values[0] if not sub_region_row.empty else "Not allocated"
202
  country_name_to_code[name] = code
203
  iso_code_to_sub_region[code] = sub_region
204
-
205
  return country_name_to_code, iso_code_to_sub_region
206
 
207
- # Get country name and region mappings
208
  client = get_client()
209
  country_name_mapping, iso_code_to_sub_region = get_country_name_and_region_mapping(client, collection_name, region_df)
210
  unique_country_names = sorted(country_name_mapping.keys()) # List of country names
 
168
  ################### Hybrid Search #####################################################
169
  client = get_client()
170
  print(client.get_collections())
 
 
171
  max_end_year = get_max_end_year(client, collection_name)
 
 
172
  _, unique_sub_regions = get_regions(region_df)
173
 
 
174
  @st.cache_data
175
  def get_country_name_and_region_mapping(_client, collection_name, region_df):
176
  results = hybrid_search(_client, "", collection_name)
177
  country_set = set()
 
178
  for res in results[0] + results[1]:
179
  countries = res.payload.get('metadata', {}).get('countries', "[]")
180
  try:
181
  country_list = json.loads(countries.replace("'", '"'))
 
182
  two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
183
  country_set.update(two_digit_codes)
184
  except json.JSONDecodeError:
185
  pass
 
 
186
  country_name_to_code = {}
187
  iso_code_to_sub_region = {}
 
188
  for code in country_set:
189
  name = get_country_name(code, region_df)
190
  sub_region_row = region_df[region_df['alpha-2'] == code]
191
  sub_region = sub_region_row['sub-region'].values[0] if not sub_region_row.empty else "Not allocated"
192
  country_name_to_code[name] = code
193
  iso_code_to_sub_region[code] = sub_region
 
194
  return country_name_to_code, iso_code_to_sub_region
195
 
 
196
  client = get_client()
197
  country_name_mapping, iso_code_to_sub_region = get_country_name_and_region_mapping(client, collection_name, region_df)
198
  unique_country_names = sorted(country_name_mapping.keys()) # List of country names