chenemii commited on
Commit
d073ef9
·
1 Parent(s): ef472f7

updated security

Browse files
Files changed (1) hide show
  1. app/streamlit_app.py +25 -7
app/streamlit_app.py CHANGED
@@ -118,13 +118,23 @@ def main():
118
  )
119
 
120
  if enable_gpt:
121
- api_key = os.getenv("OPENAI_API_KEY")
122
- if not api_key:
 
 
 
 
 
 
 
 
 
 
 
 
123
  st.sidebar.warning(
124
- "⚠️ OpenAI API key not found. Set the OPENAI_API_KEY environment variable."
125
  )
126
- else:
127
- st.sidebar.success("✅ OpenAI API key configured")
128
  else:
129
  st.sidebar.info(
130
  "Using sample analysis mode (no API key required)"
@@ -347,8 +357,16 @@ def main():
347
  st.subheader("Swing Analysis and Recommendations")
348
 
349
  # Check if we're using the sample analysis (no API key)
350
- api_key = os.getenv("OPENAI_API_KEY")
351
- if not api_key and not enable_gpt:
 
 
 
 
 
 
 
 
352
  st.info("ℹ️ **Using sample analysis mode**. The recommendations below are general examples and not personalized to your specific swing.")
353
 
354
  st.markdown(analysis)
 
118
  )
119
 
120
  if enable_gpt:
121
+ # Check for OpenAI API key in Streamlit secrets
122
+ api_key_available = False
123
+ try:
124
+ if st.secrets["openai"]["api_key"]:
125
+ api_key_available = True
126
+ st.sidebar.success("✅ OpenAI API key configured in Streamlit secrets")
127
+ except (KeyError, FileNotFoundError):
128
+ # Fallback to environment variable
129
+ api_key = os.getenv("OPENAI_API_KEY")
130
+ if api_key:
131
+ api_key_available = True
132
+ st.sidebar.success("✅ OpenAI API key configured in environment variables")
133
+
134
+ if not api_key_available:
135
  st.sidebar.warning(
136
+ "⚠️ OpenAI API key not found. Add it to your .streamlit/secrets.toml file."
137
  )
 
 
138
  else:
139
  st.sidebar.info(
140
  "Using sample analysis mode (no API key required)"
 
357
  st.subheader("Swing Analysis and Recommendations")
358
 
359
  # Check if we're using the sample analysis (no API key)
360
+ api_key_available = False
361
+ try:
362
+ if st.secrets["openai"]["api_key"]:
363
+ api_key_available = True
364
+ except (KeyError, FileNotFoundError):
365
+ api_key = os.getenv("OPENAI_API_KEY")
366
+ if api_key:
367
+ api_key_available = True
368
+
369
+ if not api_key_available and not enable_gpt:
370
  st.info("ℹ️ **Using sample analysis mode**. The recommendations below are general examples and not personalized to your specific swing.")
371
 
372
  st.markdown(analysis)