jostlebot commited on
Commit
80b6d02
·
1 Parent(s): e3e08e6

Security: Standardize on anthropic_key and remove sensitive error messages

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +7 -14
src/streamlit_app.py CHANGED
@@ -39,35 +39,28 @@ AGE_CONTEXT = {
39
 
40
  # Handle API key setup
41
  try:
42
- # Try multiple ways to get the API key
43
- api_key = None
44
-
45
- # Try environment variable first
46
- api_key = os.getenv("ANTHROPIC_KEY")
47
 
48
  # Try Streamlit secrets if env var not found
49
  if not api_key and hasattr(st, 'secrets'):
50
  try:
51
- api_key = st.secrets["ANTHROPIC_KEY"] # Try direct dictionary access
52
  except (KeyError, AttributeError):
53
- pass # Secret not found, continue to error message
54
-
55
- # Debug info (will be removed in production)
56
- st.write("Available secrets:", [k for k in st.secrets.keys()] if hasattr(st, 'secrets') else "No secrets available")
57
- st.write("Environment variables:", [k for k in os.environ.keys() if not k.startswith("_")])
58
 
59
  if not api_key:
60
  st.error("""
61
- ⚠️ Anthropic API key not found. Please make sure:
62
  1. You've added the secret in Hugging Face Space settings
63
- 2. The secret is named exactly 'ANTHROPIC_KEY'
64
  3. The Space has been rebuilt after adding the secret
65
  """)
66
  st.stop()
67
 
68
  c = Anthropic(api_key=api_key)
69
  except Exception as e:
70
- st.error(f"Error initializing Anthropic client: {str(e)}")
71
  st.stop()
72
 
73
  # Initialize session state
 
39
 
40
  # Handle API key setup
41
  try:
42
+ # Try to get API key from environment or secrets
43
+ api_key = os.getenv("anthropic_key")
 
 
 
44
 
45
  # Try Streamlit secrets if env var not found
46
  if not api_key and hasattr(st, 'secrets'):
47
  try:
48
+ api_key = st.secrets["anthropic_key"]
49
  except (KeyError, AttributeError):
50
+ pass
 
 
 
 
51
 
52
  if not api_key:
53
  st.error("""
54
+ ⚠️ API key not found. Please make sure:
55
  1. You've added the secret in Hugging Face Space settings
56
+ 2. The secret is named exactly 'anthropic_key'
57
  3. The Space has been rebuilt after adding the secret
58
  """)
59
  st.stop()
60
 
61
  c = Anthropic(api_key=api_key)
62
  except Exception as e:
63
+ st.error("Error initializing AI client. Please check your configuration.")
64
  st.stop()
65
 
66
  # Initialize session state