peter2000 commited on
Commit
544db84
β€’
1 Parent(s): 5cf4bb5

Update appStore/keyword_search.py

Browse files
Files changed (1) hide show
  1. 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
- 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
- st.write("Filename: ", file.name)
 
 
 
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
- with st.spinner("πŸ‘‘ Performing semantic search on"):#+file.name+"..."):
100
- try:
101
- msg = 'Asked ' + question
102
- logging.info(msg)
103
- pipeline = st.session_state['pipeline']
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
 
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!")