From f79211fa48506f7dc15a7eec36e428c06ef5c499 Mon Sep 17 00:00:00 2001 From: Stefano Fiorucci Date: Tue, 16 May 2023 17:10:37 +0200 Subject: [PATCH] update streamlit and other libs; better caching; fix graphical appearance --- README.md | 2 +- Rock_fact_checker.py | 3 ++- app_utils/backend_utils.py | 12 ++++-------- app_utils/frontend_utils.py | 3 +++ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d8f51f5..f64b82b 100644 --- a/README.md +++ b/README.md @@ -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] diff --git a/Rock_fact_checker.py b/Rock_fact_checker.py index 0cb3141..1bcb252 100644 --- a/Rock_fact_checker.py +++ b/Rock_fact_checker.py @@ -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) diff --git a/app_utils/backend_utils.py b/app_utils/backend_utils.py index b253dc6..77f1749 100644 --- a/app_utils/backend_utils.py +++ b/app_utils/backend_utils.py @@ -18,7 +18,7 @@ ) -@st.cache() +@st.cache_data def load_statements(): """Load statements from file""" with open(STATEMENTS_PATH) as fin: @@ -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 @@ -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: diff --git a/app_utils/frontend_utils.py b/app_utils/frontend_utils.py index e3ccbcc..35ba170 100644 --- a/app_utils/frontend_utils.py +++ b/app_utils/frontend_utils.py @@ -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 confirm your statement',