Skip to content

Commit

Permalink
app-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Avdhesh-Varshney committed Nov 3, 2024
1 parent 8da46f8 commit 3a45c06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 52 deletions.
70 changes: 22 additions & 48 deletions Jarvis.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,34 @@
from database.mongodb import create_connection, login_user
from database.localStorageServer import server
from src.apps.page import application
from datetime import datetime, timedelta
import streamlit as st

today = datetime.now()

if "user" not in st.session_state:
st.session_state['password'] = None
st.session_state["user"] = ['', '', '', '', '', '', '', '']
st.session_state['expiration_date'] = (today - timedelta(days=10)).isoformat()
st.session_state['verified'] = False
st.session_state['password'] = None
st.session_state["user"] = ['', '', '', '', '', '', '', '']
st.session_state['expiration_date'] = (today - timedelta(days=10)).isoformat()
st.session_state['verified'] = False

def getCredentials():
conn = server()
return conn.getLocalStorageVal("password"), conn.getLocalStorageVal("user"), conn.getLocalStorageVal("expiration_date"), conn.getLocalStorageVal("verified")

def logged_in():
from src.auth.login import login
userData, password, remember_me = login()

if userData != []:
conn = server()
user = [userData['username'], userData['email'], userData['first_name'], userData['last_name'], userData['role'], userData['gender'], userData['age'], userData['about']]

conn.setLocalStorageVal("user", user)
conn.setLocalStorageVal("password", password)
conn.setLocalStorageVal("expiration_date", (today + timedelta(days=(30 if remember_me else 1))).isoformat())
conn.setLocalStorageVal("verified", True)
st.info("Please refresh the page to continue", icon="ℹ️")

def application():
# /apps/public
home = st.Page("src/apps/public/home.py", title="Home", icon=":material/home:")
youtubePlaylist = st.Page("src/apps/public/youtubePlaylist.py", title="Jarvis Videos", icon=":material/ondemand_video:")

# /auth
login_page = st.Page(logged_in, title="Log in", icon=":material/login:")
sign_up_page = st.Page("src/auth/signup.py", title="Sign up", icon=":material/person_add:")
return st.navigation({"": [home, youtubePlaylist], "Account": [login_page, sign_up_page]})
conn = server()
return conn.getLocalStorageVal("password"), conn.getLocalStorageVal("user"), conn.getLocalStorageVal("expiration_date"), conn.getLocalStorageVal("verified")

if __name__ == "__main__":
app = application()

if st.session_state['password'] is None:
st.session_state['password'], st.session_state['user'], st.session_state['expiration_date'], st.session_state['verified'] = getCredentials()

if st.session_state['password'] is not None and st.session_state['expiration_date'] > today.isoformat():
if not st.session_state['verified']:
conn = create_connection()
result = login_user(conn, st.session_state['user'].split(',')[0], st.session_state['password'])
if result:
st.session_state['verified'] = True
conn = server()
conn.setLocalStorageVal("verified", True)
if st.session_state['verified']:
from src.utils.functions import load_functions
app = st.navigation(pages=load_functions())

app.run()
app = application()

if st.session_state['password'] is None:
st.session_state['password'], st.session_state['user'], st.session_state['expiration_date'], st.session_state['verified'] = getCredentials()

if st.session_state['password'] is not None and st.session_state['expiration_date'] > today.isoformat():
if not st.session_state['verified']:
conn = create_connection()
result = login_user(conn, st.session_state['user'].split(',')[0], st.session_state['password'])
if result:
st.session_state['verified'] = True
conn = server()
conn.setLocalStorageVal("verified", True)
st.rerun()
st.rerun()
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
beautifulsoup4==4.12.3
deep-translator==1.11.4
diffusers==0.30.3
gdown==5.2.0
google-generativeai==0.7.1
Jinja2==3.1.3
Expand Down Expand Up @@ -35,9 +36,7 @@ speedtest-cli==2.1.3
streamlit==1.38.0
streamlit-ws-localstorage==1.0.6
tensorflow==2.16.1
websockets==13.0.1
torch==2.3.0
ultralytics==8.3.3
diffusers==0.30.3
transformers==4.45.2
PyAudio==0.2.14
ultralytics==8.3.3
websockets==13.0.1

0 comments on commit 3a45c06

Please sign in to comment.