File size: 4,283 Bytes
50b7d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93387c6
50b7d73
 
 
 
 
 
 
 
 
 
 
1bb9c4f
50b7d73
1bb9c4f
50b7d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bb9c4f
50b7d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
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

# =================================================
# Main Entry Page for Application
# =================================================


# =================================================
# Imports
# =================================================

import os, sys
sys.path.append(os.getcwd())                                                     # to fix ModuleNotFoundError for Pages code 
# print("sys.path:", sys.path)                                    

from   openai import OpenAI
from   pages  import load_pages

import streamlit as st
import streamlit.components.v1 as components

# =================================================
# Constants
# =================================================

# =================================================
# Functions
# =================================================

@st.dialog("Market Global Risk Monitor", width="medium")     # 'large'
def app_login(intro_video):

   if intro_video is not None:                                                   # Video has been loaded - use it
      st.video(intro_video, loop=True, autoplay=False, muted=False)      
   else:                                                                         # No video loaded, use static image 
      st.image(os.path.join(st.session_state["start_dir"],"pages","assets","logo.jpg"), width=1200)

   user_name     = st.text_input(label="User Name", placeholder="Please enter your User Name",label_visibility="collapsed",icon=":material/person_edit:")
   user_password = st.text_input(label="Password", type="password", placeholder="Please enter your password",label_visibility="collapsed",icon=":material/key:")

   speak_easy = os.environ["SPEAK_EASY"]                                         #    
   users      = os.environ["USERS"]                                              #    

   if st.button("Log in") and (user_password.lower()==speak_easy) and user_name in users:               # 
      st.session_state.logged_in = True
      st.session_state.user_name = user_name
      print("User Name is: ",st.session_state.user_name)                         # log user name 
      st.rerun()                                                                 # rerun application with new session state

# =================================================
# Load State Variables
# Consistent across pages e.g. user / logged in / etc.
# =================================================

if "wide_layout" not in st.session_state:
   st.set_page_config(layout="wide")                                             # set default to wide page mode
   st.session_state["wide_layout"] = True 

if "start_dir" not in st.session_state:
   st.session_state["start_dir"] = os.getcwd()                                   # start directory for file hierarchy 

if "openai_model" not in st.session_state:
   st.session_state["openai_model"] = "gpt-5.2-pro"                              # advanced reasoning model with webtool support

if "openai_client" not in st.session_state:
   API_KEY  = os.environ["API_KEY"]                                              # api key from environ / secrets
   st.session_state["openai_client"] = OpenAI(api_key=API_KEY)

if "messages" not in st.session_state:
   st.session_state.messages = []

# Load intro video - Optional

##intro_file = open(os.path.join(st.session_state["start_dir"],"pages","assets","ascend.mp4"),"rb")
##
##if intro_file is None:
##   print("ERROR: Intro video file did not load")
##
##intro_video  = intro_file.read()

intro_video = None

# Define login once and no pages available are available until a user login 

if st.query_params.get("test_more_pages", False):
   st.session_state.logged_in = True

if "logged_in" not in st.session_state:
   app_login(intro_video)         #  None to disable and revert back to splash image   

if "logged_in" not in st.session_state:
   pass
else:
   # Load default first page - Overview of Program  
   # load_pages.load_page("Overview")

   load_pages.load_page("Module_01")


# =================================================

if __name__ == "__main__":
   pass
   # load_pages.test_load()                                             # tests for successful module import  
   # print("<<< Main APP Compile Successful >>>")                       # DEBUG