Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -178,6 +178,13 @@ filtered_lexical = filter_results(lexical_all, country_filter, region_filter)##
|
|
178 |
filtered_semantic_no_dupe = remove_duplicates(filtered_semantic) # ToDo remove duplicates again?
|
179 |
filtered_lexical_no_dupe = remove_duplicates(filtered_lexical)
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
# 3) Retrieve top 15 *after* filtering
|
183 |
# Check user preference
|
@@ -211,18 +218,24 @@ if show_exact_matches:
|
|
211 |
# 6) Display the first 15 matching results
|
212 |
for res in filtered_lexical_no_dupe[:15]:
|
213 |
project_name = res.payload['metadata'].get('project_name', 'Project Link')
|
214 |
-
|
215 |
-
st.markdown(f"####
|
216 |
|
217 |
# Snippet logic (80 words)
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
220 |
preview_word_count = 200
|
221 |
preview_text = " ".join(words[:preview_word_count])
|
222 |
remainder_text = " ".join(words[preview_word_count:])
|
223 |
st.write(preview_text + ("..." if remainder_text else ""))
|
224 |
|
225 |
# Keywords
|
|
|
226 |
top_keywords = extract_top_keywords(full_text, top_n=5)
|
227 |
if top_keywords:
|
228 |
st.markdown(f"_{' 路 '.join(top_keywords)}_")
|
@@ -257,20 +270,17 @@ if show_exact_matches:
|
|
257 |
matched_countries.append(resolved_name)
|
258 |
|
259 |
# Format the year range
|
260 |
-
start_year_str =
|
261 |
-
end_year_str =
|
262 |
-
|
263 |
-
if matched_countries:
|
264 |
-
additional_text = (
|
265 |
-
f"**{', '.join(matched_countries)}**, commissioned by **{client_name}**, "
|
266 |
-
f"**{start_year_str}-{end_year_str}**, project ID: {id}, project budget: {total_project}, total volumne: {total_volume}"
|
267 |
-
)
|
268 |
-
else:
|
269 |
-
additional_text = (
|
270 |
-
f"Commissioned by **{client_name}**, **{start_year_str}-{end_year_str}**, project ID: {id}, project budget: {total_project}, total volumne: {total_volume}"
|
271 |
-
)
|
272 |
-
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
st.markdown(additional_text)
|
275 |
st.divider()
|
276 |
|
|
|
178 |
filtered_semantic_no_dupe = remove_duplicates(filtered_semantic) # ToDo remove duplicates again?
|
179 |
filtered_lexical_no_dupe = remove_duplicates(filtered_lexical)
|
180 |
|
181 |
+
# Define a helper function to format currency values
|
182 |
+
def format_currency(value):
|
183 |
+
try:
|
184 |
+
# Convert to float then int for formatting (assumes whole numbers)
|
185 |
+
return f"鈧瑊int(float(value)):,}"
|
186 |
+
except (ValueError, TypeError):
|
187 |
+
return value
|
188 |
|
189 |
# 3) Retrieve top 15 *after* filtering
|
190 |
# Check user preference
|
|
|
218 |
# 6) Display the first 15 matching results
|
219 |
for res in filtered_lexical_no_dupe[:15]:
|
220 |
project_name = res.payload['metadata'].get('project_name', 'Project Link')
|
221 |
+
proj_id = metadata.get('id', 'Unknown')
|
222 |
+
st.markdown(f"#### {project_name} [{proj_id}]")
|
223 |
|
224 |
# Snippet logic (80 words)
|
225 |
+
# Build snippet from objectives and descriptions.
|
226 |
+
objectives = metadata.get("objectives", "")
|
227 |
+
desc_de = metadata.get("description.de", "")
|
228 |
+
desc_en = metadata.get("description.en", "")
|
229 |
+
description = desc_de if desc_de else desc_en
|
230 |
+
full_snippet = f"Objective: {objectives} Description: {description}"
|
231 |
+
words = full_snippet.split()
|
232 |
preview_word_count = 200
|
233 |
preview_text = " ".join(words[:preview_word_count])
|
234 |
remainder_text = " ".join(words[preview_word_count:])
|
235 |
st.write(preview_text + ("..." if remainder_text else ""))
|
236 |
|
237 |
# Keywords
|
238 |
+
full_text = res.payload['page_content']
|
239 |
top_keywords = extract_top_keywords(full_text, top_n=5)
|
240 |
if top_keywords:
|
241 |
st.markdown(f"_{' 路 '.join(top_keywords)}_")
|
|
|
270 |
matched_countries.append(resolved_name)
|
271 |
|
272 |
# Format the year range
|
273 |
+
start_year_str = extract_year(start_year) if start_year else "Unknown"
|
274 |
+
end_year_str = extract_year(end_year) if end_year else "Unknown"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
+
formatted_project_budget = format_currency(total_project)
|
277 |
+
formatted_total_volume = format_currency(total_volume)
|
278 |
+
|
279 |
+
additional_text = (
|
280 |
+
f"Commissioned by **{client_name}**\n"
|
281 |
+
f"Projekt duration **{start_year_str}-{end_year_str}**\n"
|
282 |
+
f"Budget: Project: **{formatted_project_budget}**, total volume: **{formatted_total_volume}**"
|
283 |
+
)
|
284 |
st.markdown(additional_text)
|
285 |
st.divider()
|
286 |
|