JVice commited on
Commit
14bd377
·
1 Parent(s): bacdbed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -3,26 +3,52 @@ 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 +83,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'],
 
3
  import streamlit_authenticator as stauth
4
  import pandas as pd
5
  import numpy as np
6
+ import uuid
7
  import model_comparison as MCOMP
8
  import model_loading as MLOAD
9
  import model_inferencing as MINFER
10
  import user_evaluation_variables
11
+ from pathlib import Path
12
  import tab_manager
13
  import yaml
14
  from yaml.loader import SafeLoader
15
  from PIL import Image
16
+ from huggingface_hub import CommitScheduler, HfApi, CommitOperationAdd
17
+
18
  AUTHENTICATOR = None
19
  TBYB_LOGO = Image.open('./assets/TBYB_logo_light.png')
20
  USER_LOGGED_IN = False
21
  USER_DATABASE_PATH = './data/user_database.yaml'
22
+
23
+ userDataFile = Path("data/") / f"user_database_{uuid.uuid4()}.yaml"
24
+ userDataFolder = userDataFile.parent
25
+
26
+ USER_DATABASE_UPDATE_SCHEDULER = CommitScheduler(
27
+ repo_id="JVice/try-before-you-bias",
28
+ repo_type="dataset",
29
+ folder_path=userDataFolder,
30
+ path_in_repo="data",
31
+ every=5,
32
+ )
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
+
41
+ with USER_DATABASE_UPDATE_SCHEDULER.lock:
42
+ with open(userDataFile, 'w') as file:
43
+ yaml.dump(users, file, default_flow_style=False)
44
+ # HfApi().create_commit(
45
+ # repo_id="JVice/try-before-you-bias",
46
+ # operations=[CommitOperationAdd(path_in_repo="data/user_database.yaml",
47
+ # path_or_fileobj="~/repo/data/user_database.yaml")],
48
+ # commit_message="Updating ",
49
+ # )
50
+
51
+
52
  def forgot_password(authenticator, users):
53
  try:
54
  username_of_forgotten_password, email_of_forgotten_password, new_random_password = authenticator.forgot_password(
 
83
  global TBYB_LOGO
84
  global USER_LOGGED_IN
85
  users = None
86
+ with open(userDataFile) as file:
87
  users = yaml.load(file, Loader=SafeLoader)
88
  AUTHENTICATOR = stauth.Authenticate(
89
  users['credentials'],