Stefano Fiorucci commited on
Commit
5764f5c
1 Parent(s): e20f916
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -7,9 +7,10 @@ from json import JSONDecodeError
7
  from markdown import markdown
8
  from annotated_text import annotation
9
  from urllib.parse import unquote
 
10
 
11
  from backend_utils import load_questions, query
12
- from frontend_utils import (set_state_if_absent, reset_results, get_random_question,
13
  SIDEBAR_STYLE, TWIN_PEAKS_IMG_SRC, LAURA_PALMER_IMG_SRC, SPOTIFY_IFRAME)
14
  from config import RETRIEVER_TOP_K, READER_TOP_K
15
 
@@ -27,7 +28,7 @@ def main():
27
  st.markdown(SIDEBAR_STYLE, unsafe_allow_html=True)
28
  st.sidebar.header("Who killed Laura Palmer?")
29
  st.sidebar.image(TWIN_PEAKS_IMG_SRC)
30
- st.sidebar.markdown("""
31
  <p align="center"><b>Twin Peaks Question Answering system</b></p>
32
  <div class="haystack-footer">
33
  <p><a href="https://github.com/anakin87/who-killed-laura-palmer">GitHub</a> -
@@ -61,7 +62,17 @@ def main():
61
  run_pressed = col1.button("Run")
62
  # Random question button
63
  if col2.button("Random question"):
64
- get_random_question(question)
 
 
 
 
 
 
 
 
 
 
65
  else:
66
  st.session_state.random_question_requested = False
67
  run_query = (run_pressed or question != st.session_state.question) \
 
7
  from markdown import markdown
8
  from annotated_text import annotation
9
  from urllib.parse import unquote
10
+ import random
11
 
12
  from backend_utils import load_questions, query
13
+ from frontend_utils import (set_state_if_absent, reset_results,
14
  SIDEBAR_STYLE, TWIN_PEAKS_IMG_SRC, LAURA_PALMER_IMG_SRC, SPOTIFY_IFRAME)
15
  from config import RETRIEVER_TOP_K, READER_TOP_K
16
 
 
28
  st.markdown(SIDEBAR_STYLE, unsafe_allow_html=True)
29
  st.sidebar.header("Who killed Laura Palmer?")
30
  st.sidebar.image(TWIN_PEAKS_IMG_SRC)
31
+ st.sidebar.markdown(f"""
32
  <p align="center"><b>Twin Peaks Question Answering system</b></p>
33
  <div class="haystack-footer">
34
  <p><a href="https://github.com/anakin87/who-killed-laura-palmer">GitHub</a> -
 
62
  run_pressed = col1.button("Run")
63
  # Random question button
64
  if col2.button("Random question"):
65
+ reset_results()
66
+ question = random.choice(questions)
67
+ # Avoid picking the same question twice (the change is not visible on the UI)
68
+ while question == st.session_state.question:
69
+ question = random.choice(questions)
70
+ st.session_state.question = question
71
+ st.session_state.random_question_requested = True
72
+ # Re-runs the script setting the random question as the textbox value
73
+ # Unfortunately necessary as the Random Question button is _below_ the textbox
74
+ raise st.script_runner.RerunException(
75
+ st.script_request_queue.RerunData(None))
76
  else:
77
  st.session_state.random_question_requested = False
78
  run_query = (run_pressed or question != st.session_state.question) \