jeremyadd commited on
Commit
2355079
·
verified ·
1 Parent(s): 9bd0e78

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __author__ = 'Jeremy Atia'
2
+
3
+ import sys
4
+ import pandas as pd
5
+ import streamlit as st
6
+ from users import Users
7
+ from leaderboard import LeaderBoard
8
+ from templates import overview, data, evaluation
9
+ from streamlit.cli import main as stmain
10
+ from config import Y_TEST_GOOGLE_PUBLIC_LINK, SKLEARN_SCORER, GREATER_IS_BETTER, SKLEARN_ADDITIONAL_PARAMETERS
11
+
12
+ @st.cache
13
+ def load_target(google_link: str) -> pd.DataFrame:
14
+ url='https://drive.google.com/uc?id=' + google_link.split('/')[-2]
15
+ y_test = pd.read_csv(url, index_col=0)
16
+ return y_test
17
+
18
+
19
+ def evaluate(y_true, y_pred, callable, additional_parameters=SKLEARN_ADDITIONAL_PARAMETERS):
20
+ return callable(y_true, y_pred, **additional_parameters)
21
+
22
+
23
+ def main():
24
+ st.header('Datathon Platform')
25
+ ldb = LeaderBoard()
26
+ users = Users()
27
+
28
+ # Sidebar Navigation
29
+ st.sidebar.title('Navigation')
30
+ options = st.sidebar.radio('Select a page:',
31
+ ['Overview', 'Data', 'Evaluation', 'Submit'])
32
+
33
+ if options in ['Overview', 'Data', 'Evaluation']:
34
+ st.markdown(eval(options.lower()), unsafe_allow_html=True)
35
+
36
+ else:
37
+ with st.sidebar:
38
+ login = st.text_input('login')
39
+ password = st.text_input('password')
40
+
41
+ if users.exists(login, password):
42
+ st.write('Welcome', login)
43
+ st.markdown('Submit the test predictions as a csv file ordered the same way as given, in the example.')
44
+
45
+ if users.is_admin(login, password):
46
+ with st.sidebar:
47
+ st.write("***************")
48
+ st.write("Manage the app")
49
+ pause_datathon = st.checkbox("Pause Datathon", value=not(is_datathon_running()))
50
+ change_datathon_status(pause_datathon)
51
+
52
+ uploaded_file = st.file_uploader('Predictions', type='csv', accept_multiple_files=False)
53
+ leaderboard = ldb.get()
54
+ if uploaded_file is not None and is_datathon_running():
55
+ y_pred = pd.read_csv(uploaded_file, index_col=0)
56
+ y_test = load_target(google_link=Y_TEST_GOOGLE_PUBLIC_LINK)
57
+ score = evaluate(y_test, y_pred, callable=SKLEARN_SCORER)
58
+ st.write("Your score is", score)
59
+ leaderboard = ldb.edit(leaderboard, id=login, score=score)
60
+
61
+ with st.expander("Show leaderboard", expanded=True):
62
+ st.write(ldb.show(leaderboard, ascending=not(GREATER_IS_BETTER)))
63
+ else:
64
+ st.info("Please enter a valid login/password on the left side bar.")
65
+
66
+ def is_datathon_running() -> bool:
67
+ with open('STATUS_DATATHON.txt', 'r') as f:
68
+ content = f.readline()
69
+ if content == 'running':
70
+ return True
71
+ else:
72
+ return False
73
+
74
+ def change_datathon_status(pause_datathon: bool) -> None:
75
+ if pause_datathon:
76
+ with open('STATUS_DATATHON.txt', 'w') as f:
77
+ f.write('pause')
78
+ else:
79
+ with open('STATUS_DATATHON.txt', 'w') as f:
80
+ f.write('running')
81
+
82
+
83
+ if __name__ == '__main__':
84
+ if st._is_running_with_streamlit:
85
+ main()
86
+ else:
87
+ sys.argv = ["streamlit", "run", sys.argv[0]]
88
+ sys.exit(stmain())