def check_streamlit(): """ Function to check whether python code is run within streamlit Returns ------- use_streamlit : boolean True if code is run within streamlit, else False """ try: from streamlit.scriptrunner.script_run_context import get_script_run_ctx if not get_script_run_ctx(): use_streamlit = False else: use_streamlit = True except ModuleNotFoundError: use_streamlit = False return use_streamlit