Changed Semantic Search result display in Dashboard

-Changed Semantic Search result display in Dashboard
This commit is contained in:
Will
2024-01-19 12:47:57 -08:00
parent 7f34ffd762
commit 8d9fdcfc8c
2 changed files with 24 additions and 22 deletions
@@ -236,14 +236,27 @@ def build_page(username: str):
try:
json_results = utils.semantic_search(search_term, num_results)
if not json_results or "results" not in json_results:
if json_results and "error" in json_results:
error = json_results["error"]
if "index_not_found_exception" in error:
st.warning("No text has been indexed!")
else:
st.error(f"Error from NLP service: {error}")
elif not json_results or "results" not in json_results:
st.warning("No results retrieved from semantic search, service might be busy")
else:
for result in json_results["results"]:
(header, text, footer) = templates.semantic_search_result(result)
st.write(header, unsafe_allow_html=True)
st.write(text, unsafe_allow_html=False)
st.write(footer, unsafe_allow_html=True)
if len(json_results) > 0:
for result in json_results["results"]:
header = templates.semantic_search_result(result)
st.subheader("", divider="red")
st.markdown(header, unsafe_allow_html=True)
st.markdown("")
st.code(result["text"], None)
st.subheader("", divider="red")
else:
st.warning("No results retrieved from semantic search")
except Exception as e:
st.error(f"Exception: {e}")
+5 -16
View File
@@ -196,7 +196,7 @@ def sourcecode_search_result(i: int, object_id: str, download_url: str, source:
)
def semantic_search_result(result) -> Tuple[str, str, str]:
def semantic_search_result(result) ->str:
"""HTML scripts to display a semantic search json result."""
text = result["text"]
@@ -220,23 +220,12 @@ def semantic_search_result(result) -> Tuple[str, str, str]:
else None
)
return (
f"""
return f"""
<div style="font-size:120%;">
<a href="{view_file_url}">
{originating_object_path}
</a>
</div>
<div style="font-size:95%;">
<div style="color:grey;font-size:95%;">
Score: {score}
&nbsp;
{f"Source: {source}" if source else ""}
{pdf_html}
</div>
<pre>""",
text,
"""</pre>
</div>
""",
)
<div style="color:grey;font-size:95%;">
Score: {score}<br>{f"Source: {source}" if source else ""}<br>{pdf_html}
"""