Spaces:
Sleeping
Sleeping
Update environment variable handling for Hugging Face Spaces
Browse files- src/streamlit_app.py +9 -7
src/streamlit_app.py
CHANGED
@@ -3,8 +3,15 @@ import streamlit as st
|
|
3 |
from anthropic import Anthropic
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
-
# Load environment variables
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Configure page
|
10 |
st.set_page_config(
|
@@ -14,11 +21,6 @@ st.set_page_config(
|
|
14 |
)
|
15 |
|
16 |
# Initialize Anthropic client
|
17 |
-
api_key = os.getenv('ANTHROPIC_API_KEY')
|
18 |
-
if not api_key:
|
19 |
-
st.error("Please set your ANTHROPIC_API_KEY in the .env file")
|
20 |
-
st.stop()
|
21 |
-
|
22 |
c = Anthropic(
|
23 |
api_key=api_key,
|
24 |
)
|
|
|
3 |
from anthropic import Anthropic
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
+
# Load environment variables from .env file if it exists (local development)
|
7 |
+
if os.path.exists(".env"):
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Get API key from environment variables (works for both local and Hugging Face Spaces)
|
11 |
+
api_key = os.getenv('ANTHROPIC_API_KEY')
|
12 |
+
if not api_key:
|
13 |
+
st.error("Please set your ANTHROPIC_API_KEY in the environment variables or .env file")
|
14 |
+
st.stop()
|
15 |
|
16 |
# Configure page
|
17 |
st.set_page_config(
|
|
|
21 |
)
|
22 |
|
23 |
# Initialize Anthropic client
|
|
|
|
|
|
|
|
|
|
|
24 |
c = Anthropic(
|
25 |
api_key=api_key,
|
26 |
)
|