Spaces:
Runtime error
Runtime error
Update appStore/keyword_search.py
Browse files- appStore/keyword_search.py +35 -37
appStore/keyword_search.py
CHANGED
@@ -81,46 +81,44 @@ def app():
|
|
81 |
|
82 |
file = st.session_state['file']
|
83 |
if file is not None:
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
91 |
|
92 |
-
# load document
|
93 |
-
documents = pre.load_document(temp.name,file_name)
|
94 |
-
documents_processed = pre.preprocessing(documents)
|
95 |
-
pipeline = start_haystack(documents_processed )
|
96 |
-
|
97 |
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
else:
|
126 |
st.info("π€ No document found, please try to upload it at the sidebar!")
|
|
|
81 |
|
82 |
file = st.session_state['file']
|
83 |
if file is not None:
|
84 |
+
with tempfile.NamedTemporaryFile(mode="wb") as temp:
|
85 |
+
bytes_data = file.getvalue()
|
86 |
+
temp.write(bytes_data)
|
87 |
+
file_name = file.name
|
88 |
+
file_path = temp.name
|
89 |
+
|
90 |
+
# load document
|
91 |
+
documents = pre.load_document(temp.name,file_name)
|
92 |
+
documents_processed = pre.preprocessing(documents)
|
93 |
+
pipeline = start_haystack(documents_processed )
|
94 |
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
|
97 |
+
with st.spinner("π Performing semantic search on"):#+file.name+"..."):
|
98 |
+
try:
|
99 |
+
msg = 'Asked ' + question
|
100 |
+
logging.info(msg)
|
101 |
+
pipeline = st.session_state['pipeline']
|
102 |
+
results = ask_question(question,pipeline)
|
103 |
+
st.write('## Top Results')
|
104 |
+
#st.write(results)
|
105 |
+
for count, result in enumerate(results):
|
106 |
+
if result["answer"]:
|
107 |
+
answer, context = result["answer"], result["context"]
|
108 |
+
start_idx = context.find(answer)
|
109 |
+
end_idx = start_idx + len(answer)
|
110 |
+
st.write(
|
111 |
+
markdown(context[:start_idx] + str(annotation(body=answer, label="ANSWER", background="#964448", color='#ffffff')) + context[end_idx:]),
|
112 |
+
unsafe_allow_html=True,
|
113 |
+
)
|
114 |
+
st.markdown(f"**Relevance:** {result['relevance']}")
|
115 |
+
else:
|
116 |
+
st.info(
|
117 |
+
"π€ Haystack is unsure whether any of the documents contain an answer to your question. Try to reformulate it!"
|
118 |
+
)
|
119 |
+
|
120 |
+
except Exception as e:
|
121 |
+
logging.exception(e)
|
122 |
|
123 |
else:
|
124 |
st.info("π€ No document found, please try to upload it at the sidebar!")
|