mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-07-25 09:50:14 +00:00

* fix ui for few answers from api. add top_k_per_sample env * Add latest docstring and tutorial changes Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
import streamlit as st
|
|
from utils import retrieve_doc
|
|
from annotated_text import annotated_text
|
|
|
|
def annotate_answer(answer,context):
|
|
start_idx = context.find(answer)
|
|
end_idx = start_idx+len(answer)
|
|
annotated_text(context[:start_idx],(answer,"ANSWER","#8ef"),context[end_idx:])
|
|
|
|
st.write("# Haystack Demo")
|
|
st.sidebar.header("Options")
|
|
top_k_reader = st.sidebar.slider("Max. number of answers",min_value=1,max_value=10,value=3,step=1)
|
|
top_k_retriever = st.sidebar.slider("Max. number of documents from retriever",min_value=1,max_value=10,value=3,step=1)
|
|
question = st.text_input("Please provide your query:",value="Who is the father of Arya Starck?")
|
|
run_query = st.button("Run")
|
|
debug = st.sidebar.checkbox("Show debug info")
|
|
if run_query:
|
|
with st.spinner("Performing neural search on documents... 🧠 \n "
|
|
"Do you want to optimize speed or accuracy? \n"
|
|
"Check out the docs: https://haystack.deepset.ai/docs/latest/optimizationmd "):
|
|
results,raw_json = retrieve_doc(question,top_k_reader=top_k_reader,top_k_retriever=top_k_retriever)
|
|
st.write("## Retrieved answers:")
|
|
for result in results:
|
|
annotate_answer(result['answer'],result['context'])
|
|
'**Relevance:** ', result['relevance'] , '**Source:** ' , result['source']
|
|
if debug:
|
|
st.subheader('REST API JSON response')
|
|
st.write(raw_json) |