Shashank2k3 commited on
Commit
38f2027
·
verified ·
1 Parent(s): d0abc48

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +14 -4
src/streamlit_app.py CHANGED
@@ -32,10 +32,20 @@ st.markdown("""
32
  """, unsafe_allow_html=True)
33
 
34
  # ---------- Config & Secrets ----------
35
- def get_apify_token() -> Optional[str]:
36
- # Prefer Streamlit secrets; fallback to env var; last resort None
37
- token = st.secrets.get("APIFY_TOKEN", None) if hasattr(st, "secrets") else None
38
- return token or os.getenv("APIFY_TOKEN") # don't hardcode into source code
 
 
 
 
 
 
 
 
 
 
39
 
40
  APIFY_ACTOR_ID = "dSCLg0C3YEZ83HzYX" # your actor id
41
  # If your actor expects a different input shape, adjust below.
 
32
  """, unsafe_allow_html=True)
33
 
34
  # ---------- Config & Secrets ----------
35
+ def get_apify_token():
36
+ import os, streamlit as st
37
+ # 1) try env var
38
+ env_token = os.getenv("APIFY_TOKEN")
39
+ # 2) try secrets.toml, but don't crash if it's missing
40
+ secret_token = None
41
+ try:
42
+ # access st.secrets inside try/except because it raises if file is missing
43
+ secret_token = st.secrets.get("APIFY_TOKEN", None) # type: ignore
44
+ except FileNotFoundError:
45
+ secret_token = None
46
+ except Exception:
47
+ secret_token = None
48
+ return secret_token or env_token
49
 
50
  APIFY_ACTOR_ID = "dSCLg0C3YEZ83HzYX" # your actor id
51
  # If your actor expects a different input shape, adjust below.