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

Update appStore/keyword_search.py

Browse files
Files changed (1) hide show
  1. 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
- if file is not None:
86
- with tempfile.NamedTemporaryFile(mode="wb") as temp:
87
- bytes_data = file.getvalue()
88
- temp.write(bytes_data)
89
- file_name = file.name
90
- file_path = temp.name
91
-
92
- st.write("Filename: ", file.name)
93
-
94
- # load document
95
- documents = pre.load_document(temp.name,file_name)
96
- documents_processed = pre.preprocessing(documents)
97
- pipeline = start_haystack(documents_processed)
98
-
99
- #if st.button("Find them."):
100
- with st.spinner("πŸ‘‘ Performing semantic search on"):#+file.name+"..."):
101
- try:
102
- msg = 'Asked ' + question
103
- logging.info(msg)
104
- results = ask_question(question,pipeline)
105
- st.write('## Top Results')
106
- #st.write(results)
107
- for count, result in enumerate(results):
108
- if result["answer"]:
109
- answer, context = result["answer"], result["context"]
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!"