anakin87 commited on
Commit
f79211f
1 Parent(s): 6a6ef27

update streamlit and other libs; better caching; fix graphical appearance

Browse files
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🎸
4
  colorFrom: purple
5
  colorTo: blue
6
  sdk: streamlit
7
- sdk_version: 1.10.0
8
  app_file: Rock_fact_checker.py
9
  pinned: true
10
  models: [sentence-transformers/msmarco-distilbert-base-tas-b, microsoft/deberta-v2-xlarge-mnli, google/flan-t5-large]
 
4
  colorFrom: purple
5
  colorTo: blue
6
  sdk: streamlit
7
+ sdk_version: 1.19.0
8
  app_file: Rock_fact_checker.py
9
  pinned: true
10
  models: [sentence-transformers/msmarco-distilbert-base-tas-b, microsoft/deberta-v2-xlarge-mnli, google/flan-t5-large]
Rock_fact_checker.py CHANGED
@@ -109,7 +109,8 @@ def main():
109
  col1, col2 = st.columns([2, 1])
110
  fig = create_ternary_plot(agg_entailment_info)
111
  with col1:
112
- st.plotly_chart(fig, use_container_width=True)
 
113
  with col2:
114
  st.write(agg_entailment_info)
115
 
 
109
  col1, col2 = st.columns([2, 1])
110
  fig = create_ternary_plot(agg_entailment_info)
111
  with col1:
112
+ # theme=None helps to preserve default plotly colors
113
+ st.plotly_chart(fig, use_container_width=True, theme=None)
114
  with col2:
115
  st.write(agg_entailment_info)
116
 
app_utils/backend_utils.py CHANGED
@@ -18,7 +18,7 @@ from app_utils.config import (
18
  )
19
 
20
 
21
- @st.cache()
22
  def load_statements():
23
  """Load statements from file"""
24
  with open(STATEMENTS_PATH) as fin:
@@ -29,9 +29,7 @@ def load_statements():
29
 
30
 
31
  # cached to make index and models load only at start
32
- @st.cache(
33
- hash_funcs={"builtins.SwigPyObject": lambda _: None}, allow_output_mutation=True
34
- )
35
  def start_haystack():
36
  """
37
  load document store, retriever, entailment checker and create pipeline
@@ -66,16 +64,14 @@ pipe, prompt_node = start_haystack()
66
 
67
  # the pipeline is not included as parameter of the following function,
68
  # because it is difficult to cache
69
- @st.cache(allow_output_mutation=True, ttl=36000)
70
  def check_statement(statement: str, retriever_top_k: int = 5):
71
  """Run query and verify statement"""
72
  params = {"retriever": {"top_k": retriever_top_k}}
73
  return pipe.run(statement, params=params)
74
 
75
 
76
- @st.cache(
77
- hash_funcs={"tokenizers.Tokenizer": lambda _: None}, allow_output_mutation=True
78
- )
79
  def explain_using_llm(
80
  statement: str, documents: List[Document], entailment_or_contradiction: str
81
  ) -> str:
 
18
  )
19
 
20
 
21
+ @st.cache_data
22
  def load_statements():
23
  """Load statements from file"""
24
  with open(STATEMENTS_PATH) as fin:
 
29
 
30
 
31
  # cached to make index and models load only at start
32
+ @st.cache_resource
 
 
33
  def start_haystack():
34
  """
35
  load document store, retriever, entailment checker and create pipeline
 
64
 
65
  # the pipeline is not included as parameter of the following function,
66
  # because it is difficult to cache
67
+ @st.cache_resource
68
  def check_statement(statement: str, retriever_top_k: int = 5):
69
  """Run query and verify statement"""
70
  params = {"retriever": {"top_k": retriever_top_k}}
71
  return pipe.run(statement, params=params)
72
 
73
 
74
+ @st.cache_resource
 
 
75
  def explain_using_llm(
76
  statement: str, documents: List[Document], entailment_or_contradiction: str
77
  ) -> str:
app_utils/frontend_utils.py CHANGED
@@ -1,7 +1,10 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.graph_objects as go
 
4
 
 
 
5
 
6
  entailment_html_messages = {
7
  "entailment": 'The knowledge base seems to <span style="color:green">confirm</span> your statement',
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.graph_objects as go
4
+ import plotly.io as pio
5
 
6
+ # this helps to preserve default plotly colors
7
+ pio.templates.default = "plotly"
8
 
9
  entailment_html_messages = {
10
  "entailment": 'The knowledge base seems to <span style="color:green">confirm</span> your statement',