Skip to content

Commit

Permalink
More demo bugfixes (#1832)
Browse files Browse the repository at this point in the history
* Trying to fix a bug occurring when dataset is None (happens with many parallel request for some reason)

* Change favicon and title and fix bug with version number

* Improve the text description and partially fix the enter-to-run function
  • Loading branch information
ZanSara committed Dec 1, 2021
1 parent e39d015 commit c21521d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion haystack/nodes/retriever/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def _get_predictions(self, dicts: List[Dict]) -> Dict[str, List[np.ndarray]]:
self.model.eval()

# When running evaluations etc., we don't want a progress bar for every single query
if len(dataset) == 1:
if dataset and len(dataset) == 1:
disable_tqdm = True
else:
disable_tqdm = not self.progress_bar
Expand Down
27 changes: 16 additions & 11 deletions ui/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@

def main():

st.set_page_config(page_title='Haystack Demo', page_icon="https://haystack.deepset.ai/img/HaystackIcon.png")

# Persistent state
state = SessionState.get(
random_question=DEFAULT_QUESTION_AT_STARTUP,
random_answer="",
last_question=DEFAULT_QUESTION_AT_STARTUP,
results=None,
raw_json=None,
get_next_question=True
)

# Small callback to reset the interface in case the text of the question changes
Expand All @@ -48,13 +50,15 @@ def reset_results(*args):

# Title
st.write("# Haystack Demo - Explore the world")
st.write("""
This demo takes its data from a selection of Wikipedia pages crawled in November 2021 on the topic of 'Countries and capital cities'.
st.markdown("""
This demo takes its data from a selection of Wikipedia pages crawled in November 2021 on the topic of
<h3 style='text-align:center;padding: 0 0 1rem;'>Countries and capital cities</h3>
Ask any question on this topic and see if Haystack can find the correct answer to your query!
Ask any question on this topic and see if Haystack can find the correct answer to your query!
*Note: do not use keywords, but type full-fledged questions.* The demo is not optimized to deal with keyword queries and might misunderstand you.
""")
*Note: do not use keywords, but full-fledged questions.* The demo is not optimized to deal with keyword queries and might misunderstand you.
""", unsafe_allow_html=True)

# Sidebar
st.sidebar.header("Options")
Expand Down Expand Up @@ -88,7 +92,7 @@ def reset_results(*args):
st.subheader("REST API JSON response")
st.sidebar.write(raw_json)

hs_version = None
hs_version = ""
try:
hs_version = f" <small>(v{haystack_version()})</small>"
except Exception:
Expand Down Expand Up @@ -136,11 +140,12 @@ def reset_results(*args):
col2.markdown("<style>.stButton button {width:100%;}</style>", unsafe_allow_html=True)

# Run button
run_query = col1.button("Run")
run_pressed = col1.button("Run")
run_query = run_pressed or question != state.last_question

# Get next random question from the CSV
state.get_next_question = col2.button("Random question")
if state.get_next_question:
#state.get_next_question = col2.button("Random question")
if col2.button("Random question"):
reset_results()
new_row = df.sample(1)
while new_row["Question Text"].values[0] == state.random_question: # Avoid picking the same question twice (the change is not visible on the UI)
Expand All @@ -162,6 +167,7 @@ def reset_results(*args):
# Get results for query
if run_query and question:
reset_results()
state.last_question = question
with st.spinner(
"🧠 &nbsp;&nbsp; Performing neural search on documents... \n "
"Do you want to optimize speed or accuracy? \n"
Expand Down Expand Up @@ -240,5 +246,4 @@ def reset_results(*args):
st.subheader("REST API JSON response")
st.write(state.raw_json)


main()

0 comments on commit c21521d

Please sign in to comment.