Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,107 +1,105 @@
|
|
| 1 |
-
|
| 2 |
-
# =================================================
|
| 3 |
-
# Main Entry Page for Application
|
| 4 |
-
# =================================================
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# =================================================
|
| 8 |
-
# Imports
|
| 9 |
-
# =================================================
|
| 10 |
-
|
| 11 |
-
import os, sys
|
| 12 |
-
sys.path.append(os.getcwd()) # to fix ModuleNotFoundError for Pages code
|
| 13 |
-
# print("sys.path:", sys.path)
|
| 14 |
-
|
| 15 |
-
from openai import OpenAI
|
| 16 |
-
from pages import load_pages
|
| 17 |
-
|
| 18 |
-
import streamlit as st
|
| 19 |
-
import streamlit.components.v1 as components
|
| 20 |
-
|
| 21 |
-
# =================================================
|
| 22 |
-
# Constants
|
| 23 |
-
# =================================================
|
| 24 |
-
|
| 25 |
-
# =================================================
|
| 26 |
-
# Functions
|
| 27 |
-
# =================================================
|
| 28 |
-
|
| 29 |
-
@st.dialog("BMO GAM Global Risk Monitor", width="
|
| 30 |
-
def app_login(intro_video):
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
st.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
st.session_state.
|
| 46 |
-
st.
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
#
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
##intro_file
|
| 75 |
-
##
|
| 76 |
-
##
|
| 77 |
-
##
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
| 1 |
+
|
| 2 |
+
# =================================================
|
| 3 |
+
# Main Entry Page for Application
|
| 4 |
+
# =================================================
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# =================================================
|
| 8 |
+
# Imports
|
| 9 |
+
# =================================================
|
| 10 |
+
|
| 11 |
+
import os, sys
|
| 12 |
+
sys.path.append(os.getcwd()) # to fix ModuleNotFoundError for Pages code
|
| 13 |
+
# print("sys.path:", sys.path)
|
| 14 |
+
|
| 15 |
+
from openai import OpenAI
|
| 16 |
+
from pages import load_pages
|
| 17 |
+
|
| 18 |
+
import streamlit as st
|
| 19 |
+
import streamlit.components.v1 as components
|
| 20 |
+
|
| 21 |
+
# =================================================
|
| 22 |
+
# Constants
|
| 23 |
+
# =================================================
|
| 24 |
+
|
| 25 |
+
# =================================================
|
| 26 |
+
# Functions
|
| 27 |
+
# =================================================
|
| 28 |
+
|
| 29 |
+
@st.dialog("BMO GAM Global Risk Monitor", width="medium") # 'large'
|
| 30 |
+
def app_login(intro_video):
|
| 31 |
+
|
| 32 |
+
if intro_video is not None: # Video has been loaded - use it
|
| 33 |
+
st.video(intro_video, loop=True, autoplay=False, muted=False)
|
| 34 |
+
else: # No video loaded, use static image
|
| 35 |
+
st.image(os.path.join(st.session_state["start_dir"],"pages","assets","logo.jpg"), width=1200)
|
| 36 |
+
|
| 37 |
+
user_name = st.text_input(label="User Name", placeholder="Please enter your User Name",label_visibility="collapsed",icon=":material/person_edit:")
|
| 38 |
+
user_password = st.text_input(label="Password", type="password", placeholder="Please enter your password",label_visibility="collapsed",icon=":material/key:")
|
| 39 |
+
|
| 40 |
+
speak_easy = os.environ["SPEAK_EASY"] #
|
| 41 |
+
|
| 42 |
+
if st.button("Log in") and (user_password.lower()==speak_easy): #
|
| 43 |
+
st.session_state.logged_in = True
|
| 44 |
+
st.session_state.user_name = user_name
|
| 45 |
+
print("User Name is: ",st.session_state.user_name) # log user name
|
| 46 |
+
st.rerun() # rerun application with new session state
|
| 47 |
+
|
| 48 |
+
# =================================================
|
| 49 |
+
# Load State Variables
|
| 50 |
+
# Consistent across pages e.g. user / logged in / etc.
|
| 51 |
+
# =================================================
|
| 52 |
+
|
| 53 |
+
if "wide_layout" not in st.session_state:
|
| 54 |
+
st.set_page_config(layout="wide") # set default to wide page mode
|
| 55 |
+
st.session_state["wide_layout"] = True
|
| 56 |
+
|
| 57 |
+
if "start_dir" not in st.session_state:
|
| 58 |
+
st.session_state["start_dir"] = os.getcwd() # start directory for file hierarchy
|
| 59 |
+
|
| 60 |
+
if "openai_model" not in st.session_state:
|
| 61 |
+
st.session_state["openai_model"] = "gpt-4.1-mini" # o4 is another option but this works best with markdown / latex etc.
|
| 62 |
+
|
| 63 |
+
if "openai_client" not in st.session_state:
|
| 64 |
+
API_KEY = os.environ["API_KEY"] # api key from environ / secrets
|
| 65 |
+
st.session_state["openai_client"] = OpenAI(api_key=API_KEY)
|
| 66 |
+
|
| 67 |
+
if "messages" not in st.session_state:
|
| 68 |
+
st.session_state.messages = []
|
| 69 |
+
|
| 70 |
+
# Load intro video - Optional
|
| 71 |
+
|
| 72 |
+
##intro_file = open(os.path.join(st.session_state["start_dir"],"pages","assets","ascend.mp4"),"rb")
|
| 73 |
+
##
|
| 74 |
+
##if intro_file is None:
|
| 75 |
+
## print("ERROR: Intro video file did not load")
|
| 76 |
+
##
|
| 77 |
+
##intro_video = intro_file.read()
|
| 78 |
+
|
| 79 |
+
intro_video = None
|
| 80 |
+
|
| 81 |
+
# Define login once and no pages available are available until a user login
|
| 82 |
+
|
| 83 |
+
if st.query_params.get("test_more_pages", False):
|
| 84 |
+
st.session_state.logged_in = True
|
| 85 |
+
|
| 86 |
+
if "logged_in" not in st.session_state:
|
| 87 |
+
app_login(intro_video) # None to disable and revert back to splash image
|
| 88 |
+
|
| 89 |
+
if "logged_in" not in st.session_state:
|
| 90 |
+
pass
|
| 91 |
+
else:
|
| 92 |
+
# Load default first page - Overview of Program
|
| 93 |
+
# load_pages.load_page("Overview")
|
| 94 |
+
|
| 95 |
+
load_pages.load_page("Module_01")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# =================================================
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
pass
|
| 102 |
+
# load_pages.test_load() # tests for successful module import
|
| 103 |
+
# print("<<< Main APP Compile Successful >>>") # DEBUG
|
| 104 |
+
|
| 105 |
+
|
|
|
|
|
|