Abhilashvj commited on
Commit
26e317f
1 Parent(s): 7c1456a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -88,7 +88,7 @@ def retrieve(query):
88
  break
89
  elif i == len(contexts) - 1:
90
  prompt = prompt_start + "\n\n---\n\n".join(contexts) + prompt_end
91
- return prompt
92
 
93
 
94
  # first let's make it simpler to get answers
@@ -109,8 +109,8 @@ def complete(prompt):
109
 
110
  def query(question, top_k_reader, top_k_retriever):
111
  # first we retrieve relevant items from Pinecone
112
- query_with_contexts = retrieve(question)
113
- return complete(query_with_contexts)
114
 
115
 
116
  indexing_pipeline_with_classification = Pipeline()
@@ -312,28 +312,28 @@ if st.session_state.results:
312
 
313
  st.write("## Results:")
314
 
315
- for result in st.session_state.results:
316
- # answer, context = result.answer, result.context
317
- # start_idx = context.find(answer)
318
- # end_idx = start_idx + len(answer)
319
- # Hack due to this bug: https://github.com/streamlit/streamlit/issues/3190
320
- try:
321
- # source = f"[{result.meta['Title']}]({result.meta['link']})"
322
- # st.write(
323
- # markdown(f'**Source:** {source} \n {context[:start_idx] } {str(annotation(answer, "ANSWER", "#8ef"))} {context[end_idx:]} \n '),
324
- # unsafe_allow_html=True,
325
- # )
326
- # all_contexts = '\n'.join(contexts)
327
- st.write(markdown(f"# Answer: {result}"),#"\n ## Extracted from context: \n {all_contexts}"),
328
- unsafe_allow_html=True,
329
- )
330
- except:
331
- # filename = result.meta.get('filename', "")
332
- # st.write(
333
- # markdown(f'From file: {filename} \n {context[:start_idx] } {str(annotation(answer, "ANSWER", "#8ef"))} {context[end_idx:]} \n '),
334
- # unsafe_allow_html=True,
335
- # )
336
- st.write(
337
- markdown(f"Answer: {result}"),
338
- unsafe_allow_html=True,
339
- )
 
88
  break
89
  elif i == len(contexts) - 1:
90
  prompt = prompt_start + "\n\n---\n\n".join(contexts) + prompt_end
91
+ return prompt, contexts
92
 
93
 
94
  # first let's make it simpler to get answers
 
109
 
110
  def query(question, top_k_reader, top_k_retriever):
111
  # first we retrieve relevant items from Pinecone
112
+ query_with_contexts, contexts = retrieve(question)
113
+ return complete(query_with_contexts), contexts
114
 
115
 
116
  indexing_pipeline_with_classification = Pipeline()
 
312
 
313
  st.write("## Results:")
314
 
315
+ result, contexts = st.session_state.results:
316
+ # answer, context = result.answer, result.context
317
+ # start_idx = context.find(answer)
318
+ # end_idx = start_idx + len(answer)
319
+ # Hack due to this bug: https://github.com/streamlit/streamlit/issues/3190
320
+ try:
321
+ # source = f"[{result.meta['Title']}]({result.meta['link']})"
322
+ # st.write(
323
+ # markdown(f'**Source:** {source} \n {context[:start_idx] } {str(annotation(answer, "ANSWER", "#8ef"))} {context[end_idx:]} \n '),
324
+ # unsafe_allow_html=True,
325
+ # )
326
+ all_contexts = '\n'.join(contexts)
327
+ st.write(markdown(f"# Answer: {result} \n ## Extracted from context: \n {all_contexts}"),
328
+ unsafe_allow_html=True,
329
+ )
330
+ except:
331
+ # filename = result.meta.get('filename', "")
332
+ # st.write(
333
+ # markdown(f'From file: {filename} \n {context[:start_idx] } {str(annotation(answer, "ANSWER", "#8ef"))} {context[end_idx:]} \n '),
334
+ # unsafe_allow_html=True,
335
+ # )
336
+ st.write(
337
+ markdown(f"Answer: {result}"),
338
+ unsafe_allow_html=True,
339
+ )