Spaces:
Runtime error
Runtime error
Update appStore/keyword_search.py
Browse files- appStore/keyword_search.py +26 -40
appStore/keyword_search.py
CHANGED
@@ -81,46 +81,32 @@ def app():
|
|
81 |
value="What particular risks does climate change pose for women?",)
|
82 |
if st.button("Find them."):
|
83 |
#file = st.file_uploader('Upload PDF File', type=['pdf', 'docx', 'txt'])
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
st.write(
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
start_idx = context.find(answer)
|
111 |
-
end_idx = start_idx + len(answer)
|
112 |
-
st.write(
|
113 |
-
markdown(context[:start_idx] + str(annotation(body=answer, label="ANSWER", background="#964448", color='#ffffff')) + context[end_idx:]),
|
114 |
-
unsafe_allow_html=True,
|
115 |
-
)
|
116 |
-
st.markdown(f"**Relevance:** {result['relevance']}")
|
117 |
-
else:
|
118 |
-
st.info(
|
119 |
-
"π€ Haystack is unsure whether any of the documents contain an answer to your question. Try to reformulate it!"
|
120 |
-
)
|
121 |
-
|
122 |
-
except Exception as e:
|
123 |
-
logging.exception(e)
|
124 |
|
125 |
else:
|
126 |
st.info("π€ No document found, please try to upload it at the sidebar!"
|
|
|
81 |
value="What particular risks does climate change pose for women?",)
|
82 |
if st.button("Find them."):
|
83 |
#file = st.file_uploader('Upload PDF File', type=['pdf', 'docx', 'txt'])
|
84 |
+
|
85 |
+
with st.spinner("π Performing semantic search on"):#+file.name+"..."):
|
86 |
+
try:
|
87 |
+
msg = 'Asked ' + question
|
88 |
+
logging.info(msg)
|
89 |
+
pipeline = st.session_state['pipeline']
|
90 |
+
results = ask_question(question,pipeline)
|
91 |
+
st.write('## Top Results')
|
92 |
+
#st.write(results)
|
93 |
+
for count, result in enumerate(results):
|
94 |
+
if result["answer"]:
|
95 |
+
answer, context = result["answer"], result["context"]
|
96 |
+
start_idx = context.find(answer)
|
97 |
+
end_idx = start_idx + len(answer)
|
98 |
+
st.write(
|
99 |
+
markdown(context[:start_idx] + str(annotation(body=answer, label="ANSWER", background="#964448", color='#ffffff')) + context[end_idx:]),
|
100 |
+
unsafe_allow_html=True,
|
101 |
+
)
|
102 |
+
st.markdown(f"**Relevance:** {result['relevance']}")
|
103 |
+
else:
|
104 |
+
st.info(
|
105 |
+
"π€ Haystack is unsure whether any of the documents contain an answer to your question. Try to reformulate it!"
|
106 |
+
)
|
107 |
+
|
108 |
+
except Exception as e:
|
109 |
+
logging.exception(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
else:
|
112 |
st.info("π€ No document found, please try to upload it at the sidebar!"
|