PRSHNTKUMR commited on
Commit
e4c86d7
·
verified ·
1 Parent(s): 201de73

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +5 -5
src/streamlit_app.py CHANGED
@@ -29,11 +29,11 @@ from docx import Document
29
 
30
  # --- Load API Key Securely ---
31
  _ = load_dotenv(find_dotenv())
32
- API_KEY = st.secrets.get("OPENAI_API_KEY", os.getenv("OPENAI_API_KEY"))
33
-
34
- if not API_KEY:
35
- st.error("❌ `OPENAI_API_KEY` is missing.\n\nGo to Hugging Face Settings → Secrets and add it, or use a `.env` file locally.")
36
- st.stop()
37
 
38
  embeddings_model = OpenAIEmbeddings(openai_api_key=API_KEY)
39
 
 
29
 
30
  # --- Load API Key Securely ---
31
  _ = load_dotenv(find_dotenv())
32
+ try:
33
+ API_KEY = st.secrets["OPENAI_API_KEY"]
34
+ except st.runtime.secrets.StreamlitSecretNotFoundError:
35
+ # fallback to .env or env var if running locally
36
+ API_KEY = os.getenv("OPENAI_API_KEY")
37
 
38
  embeddings_model = OpenAIEmbeddings(openai_api_key=API_KEY)
39