Knight-coderr commited on
Commit
7cded74
·
verified ·
1 Parent(s): 2725bb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -27,12 +27,16 @@ tickers = ['TSLA', 'MSFT', 'PG', 'META', 'AMZN', 'GOOG', 'AMD', 'AAPL', 'NFLX',
27
  start_date = (datetime.today() - pd.DateOffset(years=1)).strftime('%Y-%m-%d')
28
  end_date = datetime.today().strftime('%Y-%m-%d')
29
 
30
- # Only load stock data once per session
31
- if 'stock_data' not in st.session_state:
32
- with st.spinner("Loading stock data..."):
33
- st.session_state['stock_data'] = load_stock_data(tickers, start_date, end_date)
 
 
 
 
34
 
35
- stock_data = st.session_state['stock_data']
36
 
37
 
38
  # Perform sentiment analysis on tweets (assuming you still have your tweets data)
 
27
  start_date = (datetime.today() - pd.DateOffset(years=1)).strftime('%Y-%m-%d')
28
  end_date = datetime.today().strftime('%Y-%m-%d')
29
 
30
+ # Cache stock data for 1 day using st.cache_data
31
+ @st.cache_data(ttl=86400)
32
+ def load_and_cache_stock_data():
33
+ return load_stock_data(tickers, start_date, end_date)
34
+
35
+ # Initialize stock_data once at app startup
36
+ if "stock_data" not in st.session_state:
37
+ st.session_state["stock_data"] = load_and_cache_stock_data()
38
 
39
+ stock_data = st.session_state["stock_data"]
40
 
41
 
42
  # Perform sentiment analysis on tweets (assuming you still have your tweets data)