JVice commited on
Commit
ce4ee87
1 Parent(s): df54106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -1,28 +1,47 @@
1
  import streamlit as st
2
  st.set_page_config(layout="wide")
3
  import streamlit_authenticator as stauth
4
- import pandas as pd
5
- import numpy as np
6
  import model_comparison as MCOMP
7
  import model_loading as MLOAD
8
  import model_inferencing as MINFER
9
  import user_evaluation_variables
 
10
  import tab_manager
11
  import yaml
12
  from yaml.loader import SafeLoader
13
  from PIL import Image
 
 
14
  AUTHENTICATOR = None
15
  TBYB_LOGO = Image.open('./assets/TBYB_logo_light.png')
16
  USER_LOGGED_IN = False
17
  USER_DATABASE_PATH = './data/user_database.yaml'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def create_new_user(authenticator, users):
19
  try:
20
  if authenticator.register_user('Register user', preauthorization=False):
21
  st.success('User registered successfully')
22
  except Exception as e:
23
  st.error(e)
24
- with open(USER_DATABASE_PATH, 'w') as file:
25
- yaml.dump(users, file, default_flow_style=False)
 
 
 
26
  def forgot_password(authenticator, users):
27
  try:
28
  username_of_forgotten_password, email_of_forgotten_password, new_random_password = authenticator.forgot_password(
@@ -57,7 +76,7 @@ def user_login_create():
57
  global TBYB_LOGO
58
  global USER_LOGGED_IN
59
  users = None
60
- with open(USER_DATABASE_PATH) as file:
61
  users = yaml.load(file, Loader=SafeLoader)
62
  AUTHENTICATOR = stauth.Authenticate(
63
  users['credentials'],
 
1
  import streamlit as st
2
  st.set_page_config(layout="wide")
3
  import streamlit_authenticator as stauth
4
+ from uuid import uuid4
 
5
  import model_comparison as MCOMP
6
  import model_loading as MLOAD
7
  import model_inferencing as MINFER
8
  import user_evaluation_variables
9
+ from pathlib import Path
10
  import tab_manager
11
  import yaml
12
  from yaml.loader import SafeLoader
13
  from PIL import Image
14
+ from huggingface_hub import CommitScheduler
15
+
16
  AUTHENTICATOR = None
17
  TBYB_LOGO = Image.open('./assets/TBYB_logo_light.png')
18
  USER_LOGGED_IN = False
19
  USER_DATABASE_PATH = './data/user_database.yaml'
20
+
21
+
22
+ USER_DATABASE_DIR = Path("user_database")
23
+ USER_DATABASE_DIR.mkdir(parents=True, exist_ok=True)
24
+
25
+ USER_DATABASE_PATH = USER_DATABASE_DIR / f"tbyb-users-{uuid4()}.json"
26
+
27
+ USER_DATABASE_UPDATE_SCHEDULER = CommitScheduler(
28
+ repo_id="try-before-you-bias-data",
29
+ repo_type="dataset",
30
+ folder_path=USER_DATABASE_DIR,
31
+ path_in_repo="data",
32
+ every=2,
33
+ )
34
  def create_new_user(authenticator, users):
35
  try:
36
  if authenticator.register_user('Register user', preauthorization=False):
37
  st.success('User registered successfully')
38
  except Exception as e:
39
  st.error(e)
40
+ with USER_DATABASE_UPDATE_SCHEDULER.lock:
41
+ with USER_DATABASE_PATH.open('w') as file:
42
+ yaml.dump(users, file, default_flow_style=False)
43
+
44
+
45
  def forgot_password(authenticator, users):
46
  try:
47
  username_of_forgotten_password, email_of_forgotten_password, new_random_password = authenticator.forgot_password(
 
76
  global TBYB_LOGO
77
  global USER_LOGGED_IN
78
  users = None
79
+ with open(userDataFile) as file:
80
  users = yaml.load(file, Loader=SafeLoader)
81
  AUTHENTICATOR = stauth.Authenticate(
82
  users['credentials'],