Spaces:
Runtime error
Runtime error
Update appStore/keyword_search.py
Browse files- appStore/keyword_search.py +28 -31
appStore/keyword_search.py
CHANGED
@@ -72,41 +72,38 @@ def app():
|
|
72 |
""")
|
73 |
|
74 |
st.markdown("")
|
75 |
-
|
76 |
-
#st.markdown("## π Step One: Upload document ")
|
77 |
-
|
78 |
with st.container():
|
79 |
-
file = st.session_state['file']
|
80 |
question = st.text_input("Please enter your question here, we will look for the answer in the document.",
|
81 |
value="What particular risks does climate change pose for women?",)
|
82 |
if st.button("Find them."):
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
|
111 |
else:
|
112 |
st.info("π€ No document found, please try to upload it at the sidebar!"
|
|
|
72 |
""")
|
73 |
|
74 |
st.markdown("")
|
75 |
+
|
|
|
|
|
76 |
with st.container():
|
|
|
77 |
question = st.text_input("Please enter your question here, we will look for the answer in the document.",
|
78 |
value="What particular risks does climate change pose for women?",)
|
79 |
if st.button("Find them."):
|
80 |
+
pipeline = st.session_state['pipeline
|
81 |
+
if pipeline is not None:
|
82 |
+
with st.spinner("π Performing semantic search on"):#+file.name+"..."):
|
83 |
+
try:
|
84 |
+
msg = 'Asked ' + question
|
85 |
+
logging.info(msg)
|
86 |
+
pipeline = st.session_state['pipeline']
|
87 |
+
results = ask_question(question,pipeline)
|
88 |
+
st.write('## Top Results')
|
89 |
+
#st.write(results)
|
90 |
+
for count, result in enumerate(results):
|
91 |
+
if result["answer"]:
|
92 |
+
answer, context = result["answer"], result["context"]
|
93 |
+
start_idx = context.find(answer)
|
94 |
+
end_idx = start_idx + len(answer)
|
95 |
+
st.write(
|
96 |
+
markdown(context[:start_idx] + str(annotation(body=answer, label="ANSWER", background="#964448", color='#ffffff')) + context[end_idx:]),
|
97 |
+
unsafe_allow_html=True,
|
98 |
+
)
|
99 |
+
st.markdown(f"**Relevance:** {result['relevance']}")
|
100 |
+
else:
|
101 |
+
st.info(
|
102 |
+
"π€ Haystack is unsure whether any of the documents contain an answer to your question. Try to reformulate it!"
|
103 |
+
)
|
104 |
+
|
105 |
+
except Exception as e:
|
106 |
+
logging.exception(e)
|
107 |
|
108 |
else:
|
109 |
st.info("π€ No document found, please try to upload it at the sidebar!"
|