Stefano Fiorucci commited on
Commit
a066522
β€’
1 Parent(s): 5764f5c

refactoring

Browse files
app.py CHANGED
@@ -9,10 +9,10 @@ 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
 
17
  def main():
18
  questions = load_questions()
@@ -109,7 +109,7 @@ def main():
109
  for result in st.session_state.results['answers']:
110
  result = result.to_dict()
111
  if result["answer"]:
112
- if alert_irrelevance and result['score'] < 0.50:
113
  alert_irrelevance = False
114
  st.write("""
115
  <h4 style='color: darkred'>Attention, the
 
9
  from urllib.parse import unquote
10
  import random
11
 
12
+ from app_utils.backend_utils import load_questions, query
13
+ from app_utils.frontend_utils import (set_state_if_absent, reset_results,
14
  SIDEBAR_STYLE, TWIN_PEAKS_IMG_SRC, LAURA_PALMER_IMG_SRC, SPOTIFY_IFRAME)
15
+ from app_utils.config import RETRIEVER_TOP_K, READER_TOP_K, LOW_RELEVANCE_THRESHOLD
16
 
17
  def main():
18
  questions = load_questions()
 
109
  for result in st.session_state.results['answers']:
110
  result = result.to_dict()
111
  if result["answer"]:
112
+ if alert_irrelevance and result['score'] < LOW_RELEVANCE_THRESHOLD:
113
  alert_irrelevance = False
114
  st.write("""
115
  <h4 style='color: darkred'>Attention, the
backend_utils.py β†’ app_utils/backend_utils.py RENAMED
File without changes
config.py β†’ app_utils/config.py RENAMED
@@ -6,4 +6,5 @@ RETRIEVER_MODEL_FORMAT = "sentence_transformers"
6
  READER_MODEL = "deepset/roberta-base-squad2"
7
  READER_CONFIG_THRESHOLD = 0.15
8
  RETRIEVER_TOP_K = 10
9
- READER_TOP_K = 5
 
 
6
  READER_MODEL = "deepset/roberta-base-squad2"
7
  READER_CONFIG_THRESHOLD = 0.15
8
  RETRIEVER_TOP_K = 10
9
+ READER_TOP_K = 5
10
+ LOW_RELEVANCE_THRESHOLD = 0.5
frontend_utils.py β†’ app_utils/frontend_utils.py RENAMED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- import random
3
 
4
  def set_state_if_absent(key, value):
5
  if key not in st.session_state:
@@ -11,19 +11,6 @@ def reset_results(*args):
11
  st.session_state.results = None
12
  st.session_state.raw_json = None
13
 
14
- def get_random_question(questions):
15
- reset_results()
16
- question = random.choice(questions)
17
- # Avoid picking the same question twice (the change is not visible on the UI)
18
- while question == st.session_state.question:
19
- question = random.choice(questions)
20
- st.session_state.question = question
21
- st.session_state.random_question_requested = True
22
- # Re-runs the script setting the random question as the textbox value
23
- # Unfortunately necessary as the Random Question button is _below_ the textbox
24
- raise st.script_runner.RerunException(
25
- st.script_request_queue.RerunData(None))
26
-
27
  SIDEBAR_STYLE = """
28
  <style>
29
  [data-testid="stSidebar"][aria-expanded="true"] > div:first-child{
 
1
  import streamlit as st
2
+
3
 
4
  def set_state_if_absent(key, value):
5
  if key not in st.session_state:
 
11
  st.session_state.results = None
12
  st.session_state.raw_json = None
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  SIDEBAR_STYLE = """
15
  <style>
16
  [data-testid="stSidebar"][aria-expanded="true"] > div:first-child{