Skip to content

Commit

Permalink
update streamlit and other libs; better caching; fix graphical appear…
Browse files Browse the repository at this point in the history
…ance
  • Loading branch information
anakin87 committed May 16, 2023
1 parent 6a6ef27 commit f79211f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ emoji: 🎸
colorFrom: purple
colorTo: blue
sdk: streamlit
sdk_version: 1.10.0
sdk_version: 1.19.0
app_file: Rock_fact_checker.py
pinned: true
models: [sentence-transformers/msmarco-distilbert-base-tas-b, microsoft/deberta-v2-xlarge-mnli, google/flan-t5-large]
Expand Down
3 changes: 2 additions & 1 deletion Rock_fact_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def main():
col1, col2 = st.columns([2, 1])
fig = create_ternary_plot(agg_entailment_info)
with col1:
st.plotly_chart(fig, use_container_width=True)
# theme=None helps to preserve default plotly colors
st.plotly_chart(fig, use_container_width=True, theme=None)
with col2:
st.write(agg_entailment_info)

Expand Down
12 changes: 4 additions & 8 deletions app_utils/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)


@st.cache()
@st.cache_data
def load_statements():
"""Load statements from file"""
with open(STATEMENTS_PATH) as fin:
Expand All @@ -29,9 +29,7 @@ def load_statements():


# cached to make index and models load only at start
@st.cache(
hash_funcs={"builtins.SwigPyObject": lambda _: None}, allow_output_mutation=True
)
@st.cache_resource
def start_haystack():
"""
load document store, retriever, entailment checker and create pipeline
Expand Down Expand Up @@ -66,16 +64,14 @@ def start_haystack():

# the pipeline is not included as parameter of the following function,
# because it is difficult to cache
@st.cache(allow_output_mutation=True, ttl=36000)
@st.cache_resource
def check_statement(statement: str, retriever_top_k: int = 5):
"""Run query and verify statement"""
params = {"retriever": {"top_k": retriever_top_k}}
return pipe.run(statement, params=params)


@st.cache(
hash_funcs={"tokenizers.Tokenizer": lambda _: None}, allow_output_mutation=True
)
@st.cache_resource
def explain_using_llm(
statement: str, documents: List[Document], entailment_or_contradiction: str
) -> str:
Expand Down
3 changes: 3 additions & 0 deletions app_utils/frontend_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
import plotly.io as pio

# this helps to preserve default plotly colors
pio.templates.default = "plotly"

entailment_html_messages = {
"entailment": 'The knowledge base seems to <span style="color:green">confirm</span> your statement',
Expand Down

0 comments on commit f79211f

Please sign in to comment.