Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ from appStore.rag_utils import (
|
|
27 |
highlight_query,
|
28 |
get_rag_answer,
|
29 |
compute_title,
|
30 |
-
format_project_id #
|
31 |
)
|
32 |
from appStore.filter_utils import (
|
33 |
parse_budget,
|
@@ -145,8 +145,10 @@ def reset_filters():
|
|
145 |
col1, col2, col3, col4, col5 = st.columns([1, 1, 1, 1, 1])
|
146 |
|
147 |
with col1:
|
148 |
-
region_filter = st.multiselect(
|
149 |
-
|
|
|
|
|
150 |
if "All/Not allocated" in region_filter or not region_filter:
|
151 |
filtered_country_names = unique_country_names
|
152 |
else:
|
@@ -156,8 +158,10 @@ else:
|
|
156 |
]
|
157 |
|
158 |
with col2:
|
159 |
-
country_filter = st.multiselect(
|
160 |
-
|
|
|
|
|
161 |
|
162 |
with col3:
|
163 |
current_year = datetime.now().year
|
@@ -172,8 +176,10 @@ with col3:
|
|
172 |
|
173 |
with col4:
|
174 |
crs_options = ["All/Not allocated"] + get_crs_options(client, collection_name)
|
175 |
-
crs_filter = st.multiselect(
|
176 |
-
|
|
|
|
|
177 |
|
178 |
with col5:
|
179 |
min_budget = st.slider(
|
@@ -191,8 +197,10 @@ col1_2, col2_2, col3_2, col4_2, col5_2 = st.columns(5)
|
|
191 |
|
192 |
with col1_2:
|
193 |
client_options = sorted(project_data["client"].dropna().unique().tolist())
|
194 |
-
client_filter = st.multiselect(
|
195 |
-
|
|
|
|
|
196 |
with col2_2:
|
197 |
st.empty()
|
198 |
with col3_2:
|
@@ -223,6 +231,20 @@ with col5_3:
|
|
223 |
reset_filters()
|
224 |
st.markdown("</div>", unsafe_allow_html=True)
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
###########################################
|
227 |
# Main Search / Results
|
228 |
###########################################
|
@@ -240,14 +262,13 @@ else:
|
|
240 |
# Apply threshold to semantic results if desired
|
241 |
semantic_thresholded = [r for r in semantic_all if r.score >= 0.0]
|
242 |
|
243 |
-
# 2) Filter results based on the user’s selections
|
244 |
-
# (Assuming filter_results can handle a string "All/Not allocated" as meaning "no filter")
|
245 |
filtered_semantic = filter_results(
|
246 |
semantic_thresholded,
|
247 |
-
|
248 |
-
|
249 |
end_year_range,
|
250 |
-
|
251 |
min_budget,
|
252 |
region_df,
|
253 |
iso_code_to_sub_region,
|
@@ -256,10 +277,10 @@ else:
|
|
256 |
)
|
257 |
filtered_lexical = filter_results(
|
258 |
lexical_all,
|
259 |
-
|
260 |
-
|
261 |
end_year_range,
|
262 |
-
|
263 |
min_budget,
|
264 |
region_df,
|
265 |
iso_code_to_sub_region,
|
@@ -267,10 +288,10 @@ else:
|
|
267 |
get_country_name
|
268 |
)
|
269 |
|
270 |
-
# Additional filter by client (if
|
271 |
-
if
|
272 |
-
filtered_semantic = [r for r in filtered_semantic if r.payload.get("metadata", {}).get("client", "Unknown Client") in
|
273 |
-
filtered_lexical = [r for r in filtered_lexical if r.payload.get("metadata", {}).get("client", "Unknown Client") in
|
274 |
|
275 |
# Remove duplicates
|
276 |
filtered_semantic_no_dupe = remove_duplicates(filtered_semantic)
|
@@ -309,7 +330,8 @@ else:
|
|
309 |
current_page = st.session_state.page
|
310 |
# Top pagination widget (right aligned, occupying 1/7 of page width)
|
311 |
col_pag_top = st.columns([6, 1])[1]
|
312 |
-
new_page_top = col_pag_top.selectbox("Select Page", list(range(1, total_pages + 1)),
|
|
|
313 |
st.session_state.page = new_page_top
|
314 |
|
315 |
start_index = (st.session_state.page - 1) * page_size
|
@@ -356,7 +378,7 @@ else:
|
|
356 |
new_crs_value_clean = re.sub(r'\.0$', '', str(new_crs_value))
|
357 |
crs_combined = f"{crs_key_clean}: {new_crs_value_clean}" if crs_key_clean else "Unknown"
|
358 |
|
359 |
-
# Combine Predecessor and Successor
|
360 |
predecessor = metadata.get("predecessor_id", "").strip()
|
361 |
successor = metadata.get("successor_id", "").strip()
|
362 |
extra_line = ""
|
@@ -385,7 +407,8 @@ else:
|
|
385 |
|
386 |
# Bottom pagination widget
|
387 |
col_pag_bot = st.columns([6, 1])[1]
|
388 |
-
new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)),
|
|
|
389 |
st.session_state.page = new_page_bot
|
390 |
|
391 |
# Semantic Search Results Branch
|
@@ -403,7 +426,8 @@ else:
|
|
403 |
|
404 |
# Top pagination widget (right aligned, occupying 1/7 of page width)
|
405 |
col_pag_top = st.columns([6, 1])[1]
|
406 |
-
new_page_top = col_pag_top.selectbox("Select Page", list(range(1, total_pages + 1)),
|
|
|
407 |
st.session_state.page = new_page_top
|
408 |
|
409 |
start_index = (st.session_state.page - 1) * page_size
|
@@ -492,5 +516,6 @@ else:
|
|
492 |
|
493 |
# Bottom pagination widget (right aligned, occupying 1/7 width)
|
494 |
col_pag_bot = st.columns([6, 1])[1]
|
495 |
-
new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)),
|
|
|
496 |
st.session_state.page = new_page_bot
|
|
|
27 |
highlight_query,
|
28 |
get_rag_answer,
|
29 |
compute_title,
|
30 |
+
format_project_id # formatting function for project IDs
|
31 |
)
|
32 |
from appStore.filter_utils import (
|
33 |
parse_budget,
|
|
|
145 |
col1, col2, col3, col4, col5 = st.columns([1, 1, 1, 1, 1])
|
146 |
|
147 |
with col1:
|
148 |
+
region_filter = st.multiselect(
|
149 |
+
"Region", options=["All/Not allocated"] + sorted(unique_sub_regions),
|
150 |
+
default=["All/Not allocated"], key="region_filter"
|
151 |
+
)
|
152 |
if "All/Not allocated" in region_filter or not region_filter:
|
153 |
filtered_country_names = unique_country_names
|
154 |
else:
|
|
|
158 |
]
|
159 |
|
160 |
with col2:
|
161 |
+
country_filter = st.multiselect(
|
162 |
+
"Country", options=["All/Not allocated"] + filtered_country_names,
|
163 |
+
default=["All/Not allocated"], key="country_filter"
|
164 |
+
)
|
165 |
|
166 |
with col3:
|
167 |
current_year = datetime.now().year
|
|
|
176 |
|
177 |
with col4:
|
178 |
crs_options = ["All/Not allocated"] + get_crs_options(client, collection_name)
|
179 |
+
crs_filter = st.multiselect(
|
180 |
+
"CRS", options=crs_options,
|
181 |
+
default=["All/Not allocated"], key="crs_filter"
|
182 |
+
)
|
183 |
|
184 |
with col5:
|
185 |
min_budget = st.slider(
|
|
|
197 |
|
198 |
with col1_2:
|
199 |
client_options = sorted(project_data["client"].dropna().unique().tolist())
|
200 |
+
client_filter = st.multiselect(
|
201 |
+
"Client", options=["All/Not allocated"] + client_options,
|
202 |
+
default=["All/Not allocated"], key="client_filter"
|
203 |
+
)
|
204 |
with col2_2:
|
205 |
st.empty()
|
206 |
with col3_2:
|
|
|
231 |
reset_filters()
|
232 |
st.markdown("</div>", unsafe_allow_html=True)
|
233 |
|
234 |
+
###########################################
|
235 |
+
# Helper function to process multiselect values
|
236 |
+
###########################################
|
237 |
+
def process_multiselect(filter_list):
|
238 |
+
if not filter_list or "All/Not allocated" in filter_list:
|
239 |
+
return None
|
240 |
+
return filter_list
|
241 |
+
|
242 |
+
# Process filters before passing them on
|
243 |
+
region_filter_val = process_multiselect(region_filter)
|
244 |
+
country_filter_val = process_multiselect(country_filter)
|
245 |
+
crs_filter_val = process_multiselect(crs_filter)
|
246 |
+
client_filter_val = process_multiselect(client_filter)
|
247 |
+
|
248 |
###########################################
|
249 |
# Main Search / Results
|
250 |
###########################################
|
|
|
262 |
# Apply threshold to semantic results if desired
|
263 |
semantic_thresholded = [r for r in semantic_all if r.score >= 0.0]
|
264 |
|
265 |
+
# 2) Filter results based on the user’s selections using the processed values
|
|
|
266 |
filtered_semantic = filter_results(
|
267 |
semantic_thresholded,
|
268 |
+
country_filter_val,
|
269 |
+
region_filter_val,
|
270 |
end_year_range,
|
271 |
+
crs_filter_val,
|
272 |
min_budget,
|
273 |
region_df,
|
274 |
iso_code_to_sub_region,
|
|
|
277 |
)
|
278 |
filtered_lexical = filter_results(
|
279 |
lexical_all,
|
280 |
+
country_filter_val,
|
281 |
+
region_filter_val,
|
282 |
end_year_range,
|
283 |
+
crs_filter_val,
|
284 |
min_budget,
|
285 |
region_df,
|
286 |
iso_code_to_sub_region,
|
|
|
288 |
get_country_name
|
289 |
)
|
290 |
|
291 |
+
# Additional filter by client (if client_filter_val is not None)
|
292 |
+
if client_filter_val is not None:
|
293 |
+
filtered_semantic = [r for r in filtered_semantic if r.payload.get("metadata", {}).get("client", "Unknown Client") in client_filter_val]
|
294 |
+
filtered_lexical = [r for r in filtered_lexical if r.payload.get("metadata", {}).get("client", "Unknown Client") in client_filter_val]
|
295 |
|
296 |
# Remove duplicates
|
297 |
filtered_semantic_no_dupe = remove_duplicates(filtered_semantic)
|
|
|
330 |
current_page = st.session_state.page
|
331 |
# Top pagination widget (right aligned, occupying 1/7 of page width)
|
332 |
col_pag_top = st.columns([6, 1])[1]
|
333 |
+
new_page_top = col_pag_top.selectbox("Select Page", list(range(1, total_pages + 1)),
|
334 |
+
index=current_page - 1, key="page_top")
|
335 |
st.session_state.page = new_page_top
|
336 |
|
337 |
start_index = (st.session_state.page - 1) * page_size
|
|
|
378 |
new_crs_value_clean = re.sub(r'\.0$', '', str(new_crs_value))
|
379 |
crs_combined = f"{crs_key_clean}: {new_crs_value_clean}" if crs_key_clean else "Unknown"
|
380 |
|
381 |
+
# Combine Predecessor and Successor in one row, formatted with format_project_id
|
382 |
predecessor = metadata.get("predecessor_id", "").strip()
|
383 |
successor = metadata.get("successor_id", "").strip()
|
384 |
extra_line = ""
|
|
|
407 |
|
408 |
# Bottom pagination widget
|
409 |
col_pag_bot = st.columns([6, 1])[1]
|
410 |
+
new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)),
|
411 |
+
index=st.session_state.page - 1, key="page_bot")
|
412 |
st.session_state.page = new_page_bot
|
413 |
|
414 |
# Semantic Search Results Branch
|
|
|
426 |
|
427 |
# Top pagination widget (right aligned, occupying 1/7 of page width)
|
428 |
col_pag_top = st.columns([6, 1])[1]
|
429 |
+
new_page_top = col_pag_top.selectbox("Select Page", list(range(1, total_pages + 1)),
|
430 |
+
index=current_page - 1, key="page_top_sem")
|
431 |
st.session_state.page = new_page_top
|
432 |
|
433 |
start_index = (st.session_state.page - 1) * page_size
|
|
|
516 |
|
517 |
# Bottom pagination widget (right aligned, occupying 1/7 width)
|
518 |
col_pag_bot = st.columns([6, 1])[1]
|
519 |
+
new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)),
|
520 |
+
index=st.session_state.page - 1, key="page_bot_sem")
|
521 |
st.session_state.page = new_page_bot
|