annikwag commited on
Commit
5c71cde
·
verified ·
1 Parent(s): 0a53bf5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -43,7 +43,7 @@ def get_country_name_mapping(_client, collection_name, region_df):
43
  countries = res.payload.get('metadata', {}).get('countries', "[]")
44
  try:
45
  country_list = json.loads(countries.replace("'", '"'))
46
- country_set.update(country_list)
47
  except json.JSONDecodeError:
48
  pass
49
 
@@ -71,23 +71,23 @@ button = st.button("Search")
71
  if button:
72
  results = hybrid_search(client, var, collection_name)
73
 
74
- # Filter results based on the user's input
75
  def filter_results(results, country_filter, end_year_range):
76
  filtered = []
77
  for res in results:
78
  metadata = res.payload.get('metadata', {})
79
  countries = metadata.get('countries', "[]")
80
  end_year = float(metadata.get('end_year', 0))
81
-
82
  # Process countries string to a list
83
  try:
84
  country_list = json.loads(countries.replace("'", '"'))
 
85
  except json.JSONDecodeError:
86
  country_list = []
87
-
88
  # Translate selected country name back to ISO code
89
  selected_iso_code = country_name_mapping.get(country_filter, None)
90
-
91
  # Apply country and year filters
92
  if (country_filter == "All" or selected_iso_code in country_list) and (end_year_range[0] <= end_year <= end_year_range[1]):
93
  filtered.append(res)
 
43
  countries = res.payload.get('metadata', {}).get('countries', "[]")
44
  try:
45
  country_list = json.loads(countries.replace("'", '"'))
46
+ country_set.update([code.upper() for code in country_list]) # Normalize to uppercase
47
  except json.JSONDecodeError:
48
  pass
49
 
 
71
  if button:
72
  results = hybrid_search(client, var, collection_name)
73
 
 
74
  def filter_results(results, country_filter, end_year_range):
75
  filtered = []
76
  for res in results:
77
  metadata = res.payload.get('metadata', {})
78
  countries = metadata.get('countries', "[]")
79
  end_year = float(metadata.get('end_year', 0))
80
+
81
  # Process countries string to a list
82
  try:
83
  country_list = json.loads(countries.replace("'", '"'))
84
+ country_list = [code.upper() for code in country_list] # Convert to uppercase
85
  except json.JSONDecodeError:
86
  country_list = []
87
+
88
  # Translate selected country name back to ISO code
89
  selected_iso_code = country_name_mapping.get(country_filter, None)
90
+
91
  # Apply country and year filters
92
  if (country_filter == "All" or selected_iso_code in country_list) and (end_year_range[0] <= end_year <= end_year_range[1]):
93
  filtered.append(res)