Spaces:
Running
Running
# ================================================= | |
# 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 | |
# ================================================= | |
def app_login(intro_video): | |
# st.subheader("π Project ASCEND π") | |
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=450) | |
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"] # password control | |
if st.button("Log in") and (user_password.lower()==speak_easy): # password control | |
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-4.1-mini" # o4 is another option but this works best with markdown / latex etc. | |
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") | |
# ================================================= | |
if __name__ == "__main__": | |
pass | |
# load_pages.test_load() # tests for successful module import | |
# print("<<< Main APP Compile Successful >>>") # DEBUG | |