From 52edc8013ab47fbe8b7c3b9922ef67a1cffe58ec Mon Sep 17 00:00:00 2001 From: Akash kumar Date: Sat, 14 Dec 2024 17:54:59 +0530 Subject: [PATCH 1/2] fix: bug fix on hosting --- streamlit/app.py | 12 +++++++----- utils/secret_loader.py | 17 +++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/streamlit/app.py b/streamlit/app.py index 60f5cb1..ce26eb4 100644 --- a/streamlit/app.py +++ b/streamlit/app.py @@ -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 diff --git a/utils/secret_loader.py b/utils/secret_loader.py index d833bc8..df4334b 100644 --- a/utils/secret_loader.py +++ b/utils/secret_loader.py @@ -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"] From d0bc4425b436a2ecbca79dd2aa5801b7feacc363 Mon Sep 17 00:00:00 2001 From: Akash kumar Date: Sat, 14 Dec 2024 17:57:44 +0530 Subject: [PATCH 2/2] update: update in .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f1fc841..28d0090 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__ .venv notebook.ipynb -.snow \ No newline at end of file +.snow +.devcontainer