Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,12 +31,12 @@ def build_context_for_result(res):
|
|
31 |
metadata = res.payload.get('metadata', {})
|
32 |
# Compute title if not already present.
|
33 |
title = metadata.get("title", compute_title(metadata))
|
34 |
-
|
35 |
# Use description.en if available; otherwise use description.de.
|
36 |
desc_en = metadata.get("description.en", "").strip()
|
37 |
desc_de = metadata.get("description.de", "").strip()
|
38 |
description = desc_en if desc_en != "" else desc_de
|
39 |
-
return f"{title}\n{
|
40 |
|
41 |
# Updated highlight: return HTML that makes the matched query red and bold.
|
42 |
def highlight_query(text, query):
|
@@ -84,7 +84,7 @@ DEDICATED_ENDPOINT = "https://qu2d8m6dmsollhly.us-east-1.aws.endpoints.huggingfa
|
|
84 |
WRITE_ACCESS_TOKEN = st.secrets["Llama_3_1"]
|
85 |
|
86 |
def get_rag_answer(query, top_results):
|
87 |
-
# Build context from each top result using title,
|
88 |
context = "\n\n".join([build_context_for_result(res) for res in top_results])
|
89 |
# Truncate context to 11500 tokens (approximation)
|
90 |
context = truncate_to_tokens(context, 2960)
|
@@ -362,7 +362,7 @@ if show_exact_matches:
|
|
362 |
title_html = highlight_query(metadata["title"], var) if var.strip() else metadata["title"]
|
363 |
st.markdown(f"#### {title_html}", unsafe_allow_html=True)
|
364 |
# Build snippet from objectives and description
|
365 |
-
|
366 |
desc_en = metadata.get("description.en", "").strip()
|
367 |
desc_de = metadata.get("description.de", "").strip()
|
368 |
description = desc_en if desc_en != "" else desc_de
|
@@ -404,8 +404,8 @@ if show_exact_matches:
|
|
404 |
client_name = metadata.get('client', 'Unknown Client')
|
405 |
contact = metadata.get("contact", "").strip()
|
406 |
additional_text = (
|
|
|
407 |
f"Commissioned by **{client_name}**<br>"
|
408 |
-
f"Objective **{objectives}**<br>"
|
409 |
f"Projekt duration **{start_year_str}-{end_year_str}**<br>"
|
410 |
f"Budget: Project: **{formatted_project_budget}**, Total volume: **{formatted_total_volume}**<br>"
|
411 |
f"Country: **{', '.join(matched_countries)}**<br>"
|
@@ -432,11 +432,11 @@ else:
|
|
432 |
if "title" not in metadata:
|
433 |
metadata["title"] = compute_title(metadata)
|
434 |
st.markdown(f"#### {metadata['title']}")
|
435 |
-
|
436 |
desc_en = metadata.get("description.en", "").strip()
|
437 |
desc_de = metadata.get("description.de", "").strip()
|
438 |
description = desc_en if desc_en != "" else desc_de
|
439 |
-
full_snippet = f"{
|
440 |
words = full_snippet.split()
|
441 |
preview_word_count = 90
|
442 |
preview_text = " ".join(words[:preview_word_count])
|
@@ -472,6 +472,7 @@ else:
|
|
472 |
client_name = metadata.get('client', 'Unknown Client')
|
473 |
contact = metadata.get("contact", "").strip()
|
474 |
additional_text = (
|
|
|
475 |
f"Commissioned by **{client_name}**<br>"
|
476 |
f"Projekt duration **{start_year_str}-{end_year_str}**<br>"
|
477 |
f"Budget: Project: **{formatted_project_budget}**, Total volume: **{formatted_total_volume}**<br>"
|
|
|
31 |
metadata = res.payload.get('metadata', {})
|
32 |
# Compute title if not already present.
|
33 |
title = metadata.get("title", compute_title(metadata))
|
34 |
+
objective = metadata.get("objective", "")
|
35 |
# Use description.en if available; otherwise use description.de.
|
36 |
desc_en = metadata.get("description.en", "").strip()
|
37 |
desc_de = metadata.get("description.de", "").strip()
|
38 |
description = desc_en if desc_en != "" else desc_de
|
39 |
+
return f"{title}\n{objective}\n{description}"
|
40 |
|
41 |
# Updated highlight: return HTML that makes the matched query red and bold.
|
42 |
def highlight_query(text, query):
|
|
|
84 |
WRITE_ACCESS_TOKEN = st.secrets["Llama_3_1"]
|
85 |
|
86 |
def get_rag_answer(query, top_results):
|
87 |
+
# Build context from each top result using title, objective, and description.
|
88 |
context = "\n\n".join([build_context_for_result(res) for res in top_results])
|
89 |
# Truncate context to 11500 tokens (approximation)
|
90 |
context = truncate_to_tokens(context, 2960)
|
|
|
362 |
title_html = highlight_query(metadata["title"], var) if var.strip() else metadata["title"]
|
363 |
st.markdown(f"#### {title_html}", unsafe_allow_html=True)
|
364 |
# Build snippet from objectives and description
|
365 |
+
objective = metadata.get("objective", "None")
|
366 |
desc_en = metadata.get("description.en", "").strip()
|
367 |
desc_de = metadata.get("description.de", "").strip()
|
368 |
description = desc_en if desc_en != "" else desc_de
|
|
|
404 |
client_name = metadata.get('client', 'Unknown Client')
|
405 |
contact = metadata.get("contact", "").strip()
|
406 |
additional_text = (
|
407 |
+
f"Objective: **{objective}**<br>"
|
408 |
f"Commissioned by **{client_name}**<br>"
|
|
|
409 |
f"Projekt duration **{start_year_str}-{end_year_str}**<br>"
|
410 |
f"Budget: Project: **{formatted_project_budget}**, Total volume: **{formatted_total_volume}**<br>"
|
411 |
f"Country: **{', '.join(matched_countries)}**<br>"
|
|
|
432 |
if "title" not in metadata:
|
433 |
metadata["title"] = compute_title(metadata)
|
434 |
st.markdown(f"#### {metadata['title']}")
|
435 |
+
objective = metadata.get("objective", "")
|
436 |
desc_en = metadata.get("description.en", "").strip()
|
437 |
desc_de = metadata.get("description.de", "").strip()
|
438 |
description = desc_en if desc_en != "" else desc_de
|
439 |
+
full_snippet = f"{description}"
|
440 |
words = full_snippet.split()
|
441 |
preview_word_count = 90
|
442 |
preview_text = " ".join(words[:preview_word_count])
|
|
|
472 |
client_name = metadata.get('client', 'Unknown Client')
|
473 |
contact = metadata.get("contact", "").strip()
|
474 |
additional_text = (
|
475 |
+
f"Objective: **{objective}**<br>"
|
476 |
f"Commissioned by **{client_name}**<br>"
|
477 |
f"Projekt duration **{start_year_str}-{end_year_str}**<br>"
|
478 |
f"Budget: Project: **{formatted_project_budget}**, Total volume: **{formatted_total_volume}**<br>"
|