peter2000 commited on
Commit
0368090
β€’
1 Parent(s): f52333f

Update appStore/keyword_search.py

Browse files
Files changed (1) hide show
  1. appStore/keyword_search.py +28 -31
appStore/keyword_search.py CHANGED
@@ -72,41 +72,38 @@ def app():
72
  """)
73
 
74
  st.markdown("")
75
- #st.markdown("")
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
- #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!"
 
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!"