annikwag commited on
Commit
077a149
·
verified ·
1 Parent(s): 5c71cde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -4
app.py CHANGED
@@ -60,7 +60,7 @@ unique_country_names = sorted(country_name_mapping.keys()) # List of country na
60
  col1, col2, col3 = st.columns([1, 1, 4])
61
 
62
  with col1:
63
- country_filter = st.selectbox("Country", ["All"] + unique_country_names) # Display country names
64
  with col2:
65
  end_year_range = st.slider("Project End Year", min_value=2010, max_value=2030, value=(2010, 2030))
66
 
@@ -81,18 +81,20 @@ if button:
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)
94
  return filtered
95
 
 
96
  # Check user preference for exact matches
97
  if show_exact_matches:
98
  st.write(f"Showing **Top 10 Lexical Search results** for query: {var}")
@@ -103,6 +105,31 @@ if button:
103
  url = res.payload['metadata'].get('url', '#')
104
  st.markdown(f"#### [{project_name}]({url})")
105
  st.write(res.payload['page_content'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  st.divider()
107
  else:
108
  st.write(f"Showing **Top 10 Semantic Search results** for query: {var}")
@@ -113,6 +140,30 @@ if button:
113
  url = res.payload['metadata'].get('url', '#')
114
  st.markdown(f"#### [{project_name}]({url})")
115
  st.write(res.payload['page_content'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  st.divider()
117
 
118
 
 
60
  col1, col2, col3 = st.columns([1, 1, 4])
61
 
62
  with col1:
63
+ country_filter = st.selectbox("Country", ["All/Not allocated"] + unique_country_names) # Display country names
64
  with col2:
65
  end_year_range = st.slider("Project End Year", min_value=2010, max_value=2030, value=(2010, 2030))
66
 
 
81
  # Process countries string to a list
82
  try:
83
  country_list = json.loads(countries.replace("'", '"'))
84
+ # Normalize to uppercase and filter only 2-digit ISO codes
85
+ country_list = [code.upper() for code in country_list if len(code) == 2]
86
  except json.JSONDecodeError:
87
  country_list = []
88
 
89
+ # Translate selected country name back to 2-digit ISO code
90
  selected_iso_code = country_name_mapping.get(country_filter, None)
91
 
92
  # Apply country and year filters
93
+ if (country_filter == "All/Not allocated" or selected_iso_code in country_list) and (end_year_range[0] <= end_year <= end_year_range[1]):
94
  filtered.append(res)
95
  return filtered
96
 
97
+
98
  # Check user preference for exact matches
99
  if show_exact_matches:
100
  st.write(f"Showing **Top 10 Lexical Search results** for query: {var}")
 
105
  url = res.payload['metadata'].get('url', '#')
106
  st.markdown(f"#### [{project_name}]({url})")
107
  st.write(res.payload['page_content'])
108
+
109
+ # Additional text below the content
110
+ metadata = res.payload.get('metadata', {})
111
+ countries = metadata.get('countries', "[]")
112
+ client = metadata.get('client', 'Unknown Client')
113
+ start_year = metadata.get('start_year', None)
114
+ end_year = metadata.get('end_year', None)
115
+
116
+ # Process countries
117
+ try:
118
+ country_list = json.loads(countries.replace("'", '"'))
119
+ # Normalize to uppercase and map to country names
120
+ country_names = [get_country_name(code.upper(), region_df) for code in country_list if len(code) == 2]
121
+ country_names = country_names if country_names else country_list # Fallback if no names found
122
+ except json.JSONDecodeError:
123
+ country_names = countries
124
+
125
+ # Format start and end year
126
+ start_year = f"{int(round(float(start_year)))}" if start_year else "Unknown"
127
+ end_year = f"{int(round(float(end_year)))}" if end_year else "Unknown"
128
+
129
+ # Generate additional text
130
+ additional_text = f"{', '.join(country_names)}, commissioned by {client}, {start_year}-{end_year}"
131
+ st.write(additional_text)
132
+
133
  st.divider()
134
  else:
135
  st.write(f"Showing **Top 10 Semantic Search results** for query: {var}")
 
140
  url = res.payload['metadata'].get('url', '#')
141
  st.markdown(f"#### [{project_name}]({url})")
142
  st.write(res.payload['page_content'])
143
+
144
+ # Additional text below the content
145
+ metadata = res.payload.get('metadata', {})
146
+ countries = metadata.get('countries', "[]")
147
+ client = metadata.get('client', 'Unknown Client')
148
+ start_year = metadata.get('start_year', None)
149
+ end_year = metadata.get('end_year', None)
150
+
151
+ # Process countries
152
+ try:
153
+ country_list = json.loads(countries.replace("'", '"'))
154
+ country_names = [get_country_name(code.upper(), region_df) for code in country_list if len(code) == 2]
155
+ country_names = country_names if country_names else country_list
156
+ except json.JSONDecodeError:
157
+ country_names = countries
158
+
159
+ # Format start and end year
160
+ start_year = f"{int(round(float(start_year)))}" if start_year else "Unknown"
161
+ end_year = f"{int(round(float(end_year)))}" if end_year else "Unknown"
162
+
163
+ # Generate additional text
164
+ additional_text = f"{', '.join(country_names)}, commissioned by {client}, {start_year}-{end_year}"
165
+ st.write(additional_text)
166
+
167
  st.divider()
168
 
169