Skip to content

Commit

Permalink
Merge pull request #47 from theakash04/dev/akash
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh-Gi-t authored Dec 14, 2024
2 parents 81196aa + d0bc442 commit b81b1b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
__pycache__
.venv
notebook.ipynb
.snow
.snow
.devcontainer
12 changes: 7 additions & 5 deletions streamlit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from snowflake.main import RAG
import asyncio

if "session" not in st.session_state:
sfConnect = SnowflakeConnector()
st.session_state.session = sfConnect.get_session()

st.session_state.setdefault("sfConnect", SnowflakeConnector())
st.session_state.setdefault("session", st.session_state.sfConnect.get_session())
st.session_state.setdefault("root", Root(st.session_state.session))

# Access variables
session = st.session_state.session

if "root" not in st.session_state:
st.session_state.root = Root(session)

root = st.session_state.root

# intialize chat history
Expand Down
17 changes: 11 additions & 6 deletions utils/secret_loader.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import os
import streamlit as st
from dotenv import load_dotenv

def get_secret(key: str):
"""Fetch secret from Streamlit secrets or fallback to environment variables."""
secrets_file_path = os.path.join(os.getcwd(), ".streamlit", "secrets.toml")
if not os.path.exists(secrets_file_path):
return os.environ[key]
# Use st.secrets only if the file exists and the key is present
"""Fetch secret from environment variables or fallback to Streamlit secrets."""
secret_value = os.environ[key]
if secret_value:
return secret_value

# if not found in env
try:
if key in st.secrets:
return st.secrets[key]
except FileNotFoundError:
pass # Silently skip st.secrets if secrets.toml doesn't exist
pass

return None



__all__ = ["get_secret"]

0 comments on commit b81b1b7

Please sign in to comment.