Spaces:
Sleeping
Sleeping
Security: Standardize on anthropic_key and remove sensitive error messages
Browse files- 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
|
43 |
-
api_key =
|
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["
|
52 |
except (KeyError, AttributeError):
|
53 |
-
pass
|
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 |
-
⚠️
|
62 |
1. You've added the secret in Hugging Face Space settings
|
63 |
-
2. The secret is named exactly '
|
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(
|
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
|