mswhite commited on
Commit
50b7d73
·
verified ·
1 Parent(s): 0dff441

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -107
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="large")
30
- def app_login(intro_video):
31
-
32
- # st.subheader("🚀 Project ASCEND 🚀")
33
-
34
- if intro_video is not None: # Video has been loaded - use it
35
- st.video(intro_video, loop=True, autoplay=False, muted=False)
36
- else: # No video loaded, use static image
37
- st.image(os.path.join(st.session_state["start_dir"],"pages","assets","logo.jpg"), width=1200)
38
-
39
- user_name = st.text_input(label="User Name", placeholder="Please enter your User Name",label_visibility="collapsed",icon=":material/person_edit:")
40
- user_password = st.text_input(label="Password", type="password", placeholder="Please enter your password",label_visibility="collapsed",icon=":material/key:")
41
-
42
- # speak_easy = os.environ["SPEAK_EASY"] # password control
43
-
44
- if st.button("Log in"): # and (user_password.lower()==speak_easy): # password control
45
- st.session_state.logged_in = True
46
- st.session_state.user_name = user_name
47
- print("User Name is: ",st.session_state.user_name) # log user name
48
- st.rerun() # rerun application with new session state
49
-
50
- # =================================================
51
- # Load State Variables
52
- # Consistent across pages e.g. user / logged in / etc.
53
- # =================================================
54
-
55
- if "wide_layout" not in st.session_state:
56
- st.set_page_config(layout="wide") # set default to wide page mode
57
- st.session_state["wide_layout"] = True
58
-
59
- if "start_dir" not in st.session_state:
60
- st.session_state["start_dir"] = os.getcwd() # start directory for file hierarchy
61
-
62
- if "openai_model" not in st.session_state:
63
- st.session_state["openai_model"] = "gpt-4.1-mini" # o4 is another option but this works best with markdown / latex etc.
64
-
65
- if "openai_client" not in st.session_state:
66
- API_KEY = os.environ["API_KEY"] # api key from environ / secrets
67
- st.session_state["openai_client"] = OpenAI(api_key=API_KEY)
68
-
69
- if "messages" not in st.session_state:
70
- st.session_state.messages = []
71
-
72
- # Load intro video - Optional
73
-
74
- ##intro_file = open(os.path.join(st.session_state["start_dir"],"pages","assets","ascend.mp4"),"rb")
75
- ##
76
- ##if intro_file is None:
77
- ## print("ERROR: Intro video file did not load")
78
- ##
79
- ##intro_video = intro_file.read()
80
-
81
- intro_video = None
82
-
83
- # Define login once and no pages available are available until a user login
84
-
85
- if st.query_params.get("test_more_pages", False):
86
- st.session_state.logged_in = True
87
-
88
- if "logged_in" not in st.session_state:
89
- app_login(intro_video) # None to disable and revert back to splash image
90
-
91
- if "logged_in" not in st.session_state:
92
- pass
93
- else:
94
- # Load default first page - Overview of Program
95
- # load_pages.load_page("Overview")
96
-
97
- load_pages.load_page("Module_01")
98
-
99
-
100
- # =================================================
101
-
102
- if __name__ == "__main__":
103
- pass
104
- # load_pages.test_load() # tests for successful module import
105
- # print("<<< Main APP Compile Successful >>>") # DEBUG
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
+