I am working on the audio tagging application where the tagger with listen to the audio file and based on that they will answer some questions and go to the next audio. But the tool that we have developed is actually taking a lot of time to load (or read from the drive) the next audio file when the next button is clicked.
I am looking for the way where I can load the next audio file in cache while anwering the question of current audio so when the next b
I loaded the initial data and displayed it directly to the screen. After writing that to the screen I immediately load the next chart’s data and save it to a session_state variable.
When the user clicks “Next” I display the previous session_state cached data and, after displaying it to the screen, I grab the next data group and save that to the session state variable for the next round.
Here’s the actual code I used. Hopefully it’s commented well enough to understand:
def market_scan(exchange):
exchange = exchange
num_candles = 75
watch_list = get_perp_list("FTX_perp.txt")
# Initialize session state with current coin and its' data
if "current_coin" not in st.session_state:
st.session_state.current_coin = watch_list[0]
if "next_coin_data" not in st.session_state:
st.session_state.next_coin_data = get_period_data_dict(watch_list[0], num_candles, exchange)
# ------------------------ Begin Display Page Layout ----------------------------------------
c1,c2,c3 = st.beta_columns((3,2,3))
c2.title("Market Scan", anchor="top")
st.button("Next",key="whatever")
coin = st.session_state.current_coin # Get name of current coin to print
coin_period_dict = st.session_state.next_coin_data # Get preloaded dictionary of coin data
show_charts(coin, coin_period_dict) # Display each chart in order
st.button("Next", key="dfsaf")
# ------------------------ End Display Page Layout ----------------------------------------
# Cache Next coin data for next page load
coin = (next_coin(watch_list))
st.session_state.next_coin_data = get_period_data_dict(coin, num_candles, exchange)