Spaces:
Sleeping
Sleeping
Commit
·
15ea144
1
Parent(s):
cc5e36a
feat(app): Improve the answer readability
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ def load_documents():
|
|
| 30 |
return documents
|
| 31 |
|
| 32 |
|
| 33 |
-
@st.
|
| 34 |
def get_document_store(documents):
|
| 35 |
"""
|
| 36 |
Index the files in the document store.
|
|
@@ -45,7 +45,7 @@ def get_document_store(documents):
|
|
| 45 |
return document_store
|
| 46 |
|
| 47 |
|
| 48 |
-
@st.
|
| 49 |
def get_question_pipeline(_doc_store):
|
| 50 |
"""
|
| 51 |
Create the pipeline with the retriever and reader components.
|
|
@@ -119,10 +119,16 @@ if user_query := st.text_input(
|
|
| 119 |
with st.spinner("Waiting"):
|
| 120 |
try:
|
| 121 |
answer = search(pipe, user_query)
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
except Exception as e:
|
| 124 |
st.error("We do not have an answer for your question")
|
| 125 |
-
# Show balloons only once
|
| 126 |
-
if not st.session_state.get("run_once", False):
|
| 127 |
-
st.balloons()
|
| 128 |
-
st.session_state["run_once"] = True
|
|
|
|
| 30 |
return documents
|
| 31 |
|
| 32 |
|
| 33 |
+
@st.cache_resource(show_spinner=False)
|
| 34 |
def get_document_store(documents):
|
| 35 |
"""
|
| 36 |
Index the files in the document store.
|
|
|
|
| 45 |
return document_store
|
| 46 |
|
| 47 |
|
| 48 |
+
@st.cache_resource(show_spinner=False)
|
| 49 |
def get_question_pipeline(_doc_store):
|
| 50 |
"""
|
| 51 |
Create the pipeline with the retriever and reader components.
|
|
|
|
| 119 |
with st.spinner("Waiting"):
|
| 120 |
try:
|
| 121 |
answer = search(pipe, user_query)
|
| 122 |
+
for idx, ans in enumerate(answer):
|
| 123 |
+
st.info(
|
| 124 |
+
f"""
|
| 125 |
+
Answer {idx+1}: "{ans.data}" | Score: {ans.score:0.4f}
|
| 126 |
+
Document: "{ans.document.meta["title"]}"
|
| 127 |
+
URL: {ans.document.meta["url"]}
|
| 128 |
+
"""
|
| 129 |
+
)
|
| 130 |
+
with st.expander("See details", expanded=False):
|
| 131 |
+
st.write(ans)
|
| 132 |
+
st.divider()
|
| 133 |
except Exception as e:
|
| 134 |
st.error("We do not have an answer for your question")
|
|
|
|
|
|
|
|
|
|
|
|
utils.py
CHANGED
|
@@ -24,7 +24,6 @@ def get_unique_docs(dataset, unique_docs: set):
|
|
| 24 |
"context_id": doc["context_id"],
|
| 25 |
"url": doc["url"],
|
| 26 |
"source": "QASports",
|
| 27 |
-
"category": "basketball",
|
| 28 |
},
|
| 29 |
)
|
| 30 |
docs.append(document)
|
|
|
|
| 24 |
"context_id": doc["context_id"],
|
| 25 |
"url": doc["url"],
|
| 26 |
"source": "QASports",
|
|
|
|
| 27 |
},
|
| 28 |
)
|
| 29 |
docs.append(document)
|