My Streamlit app cannot access environment variables after deployment Is this a secrets configuration issue

0 votes
May 11 in Generative AI by gaurav
• 24,180 points
55 views

1 answer to this question.

0 votes

Yes this sounds like a configuration issue , the exact fox depends on where you deployed it .
Streamlit system usually uses its own secret systems not .env files .
The local .env files don't go with you when you do the deployment. Streamlit has its own secret manager
# You configure this in Streamlit Cloud dashboard

# Settings → Secrets → paste this in

OPENAI_API_KEY = "sk-your-key-here"

DATABASE_URL = "postgresql://..."

[database]

host = "localhost"

port = 5432


Then in your code, access it like this: 

import streamlit as st

# Access flat secrets

api_key = st.secrets["OPENAI_API_KEY"]

# Access nested secrets

db_host = st.secrets["database"]["host"]

# Or use it like a dict

db_config = st.secrets["database"]

answered May 12 by anonymous
• 740 points

Related Questions In Generative AI

0 votes
1 answer

My LangChain app stopped working after upgrading to v0.2. What changed in agent execution?

The v0.2 upgrade broke a lot of ...READ MORE

answered May 12 in Generative AI by anonymous
• 740 points
42 views
0 votes
1 answer

My API requests fail after enabling 2FA on the provider account. Is there an automation workaround?

Yes , this happens and usually because ...READ MORE

answered May 12 in Generative AI by anonymous
• 740 points
34 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP