當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Streamlit st.experimental_singleton.clear用法及代碼示例

清除所有單例緩存。

函數簽名

st.experimental_singleton.clear()

示例

在下麵的示例中,按下 "Clear All" 按鈕將清除 all 單例緩存。即從所有用 @st.experimental_singleton 修飾的函數中清除緩存的單例對象。

import streamlit as st
from transformers import BertModel

@st.experimental_singleton
 def get_database_session(url):
     # Create a database session object that points to the URL.
     return session

@st.experimental_singleton
def get_model(model_type):
    # Create a model of the specified type.
    return BertModel.from_pretrained(model_type)

if st.button("Clear All"):
    # Clears all singleton caches:
    st.experimental_singleton.clear()

相關用法


注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.experimental_singleton.clear。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。