abhishek thakur commited on
Commit
61b7603
Β·
1 Parent(s): 5c5968f

use old streamlit

Browse files
.env.example CHANGED
@@ -3,4 +3,7 @@ AUTOTRAIN_USERNAME=autoevaluator
3
  AUTOTRAIN_TOKEN=hf_XXX
4
  AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co
5
  MOONLANDING_URL=https://huggingface.co
6
- SUBMISSION_LIMIT=5
 
 
 
 
3
  AUTOTRAIN_TOKEN=hf_XXX
4
  AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co
5
  MOONLANDING_URL=https://huggingface.co
6
+ SUBMISSION_LIMIT=5
7
+ SELECTION_LIMIT=2
8
+ END_DATE=2022-12-1
9
+ EVAL_HIGHER_IS_BETTER=1
pages/2_πŸ“_Leaderboard.py DELETED
@@ -1,82 +0,0 @@
1
- import glob
2
- import json
3
- import os
4
- from datetime import datetime
5
-
6
- import pandas as pd
7
- import streamlit as st
8
- from huggingface_hub import snapshot_download
9
-
10
- import config
11
-
12
-
13
- def fetch_leaderboard(private=False):
14
- submissions_folder = snapshot_download(
15
- repo_id=config.COMPETITION_ID,
16
- allow_patterns="*.json",
17
- use_auth_token=config.AUTOTRAIN_TOKEN,
18
- repo_type="dataset",
19
- )
20
- submissions = []
21
- for submission in glob.glob(os.path.join(submissions_folder, "*.json")):
22
- with open(submission, "r") as f:
23
- submission_info = json.load(f)
24
- print(config.EVAL_HIGHER_IS_BETTER)
25
- if config.EVAL_HIGHER_IS_BETTER:
26
- submission_info["submissions"].sort(
27
- key=lambda x: x["private_score"] if private else x["public_score"], reverse=True
28
- )
29
- else:
30
- submission_info["submissions"].sort(key=lambda x: x["private_score"] if private else x["public_score"])
31
- # select only the best submission
32
- submission_info["submissions"] = submission_info["submissions"][0]
33
- temp_info = {
34
- "id": submission_info["id"],
35
- "name": submission_info["name"],
36
- "submission_id": submission_info["submissions"]["submission_id"],
37
- "submission_comment": submission_info["submissions"]["submission_comment"],
38
- "status": submission_info["submissions"]["status"],
39
- "selected": submission_info["submissions"]["selected"],
40
- "public_score": submission_info["submissions"]["public_score"],
41
- "private_score": submission_info["submissions"]["private_score"],
42
- "submission_date": submission_info["submissions"]["date"],
43
- }
44
- submissions.append(temp_info)
45
- print(submissions)
46
-
47
- df = pd.DataFrame(submissions)
48
- # sort by public score and then by submission_date
49
- df = df.sort_values(
50
- by=["public_score", "submission_date"],
51
- ascending=True if not config.EVAL_HIGHER_IS_BETTER else False,
52
- )
53
- df = df.reset_index(drop=True)
54
- df["rank"] = df.index + 1
55
-
56
- if private:
57
- columns = ["rank", "name", "private_score", "submission_date"]
58
- else:
59
- columns = ["rank", "name", "public_score", "submission_date"]
60
- st.table(df[columns])
61
-
62
-
63
- def app():
64
- st.set_page_config(page_title="Leaderboard", page_icon="πŸ€—")
65
- st.markdown("## Leaderboard")
66
- public_lb, private_lb = st.tabs(["Public", "Private"])
67
- current_date_time = datetime.now()
68
-
69
- with public_lb:
70
- st.header("Public Leaderboard")
71
- fetch_leaderboard(private=False)
72
-
73
- with private_lb:
74
- if current_date_time >= config.END_DATE:
75
- st.header("Private Leaderboard")
76
- fetch_leaderboard(private=True)
77
- else:
78
- st.error("Private Leaderboard will be available after the competition ends")
79
-
80
-
81
- if __name__ == "__main__":
82
- app()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/{3_πŸ”₯_New Submission.py β†’ 2_πŸ”₯_New Submission.py} RENAMED
File without changes
pages/{4_⭐️_Submission History.py β†’ 3_⭐️_Submission History.py} RENAMED
@@ -18,6 +18,7 @@ def get_subs(user_info, private=False):
18
  except EntryNotFoundError:
19
  st.error("No submissions found")
20
  return
 
21
  submissions_df = pd.DataFrame(user_submissions)
22
  if not private:
23
  submissions_df = submissions_df.drop(columns=["private_score"])
 
18
  except EntryNotFoundError:
19
  st.error("No submissions found")
20
  return
21
+ print(user_submissions)
22
  submissions_df = pd.DataFrame(user_submissions)
23
  if not private:
24
  submissions_df = submissions_df.drop(columns=["private_score"])
pages/4_πŸ“_Public Leaderboard.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+
4
+ import utils
5
+
6
+
7
+ def app():
8
+ st.set_page_config(page_title="Public Leaderboard", page_icon="πŸ€—")
9
+ st.markdown("## Public Leaderboard")
10
+ lb = utils.fetch_leaderboard(private=False)
11
+ st.table(lb)
12
+
13
+
14
+ if __name__ == "__main__":
15
+ app()
pages/5_πŸ“_Private Leaderboard.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import config
3
+ import streamlit as st
4
+
5
+
6
+ import utils
7
+
8
+
9
+ def app():
10
+ st.set_page_config(page_title="Private Leaderboard", page_icon="πŸ€—")
11
+ st.markdown("## Private Leaderboard")
12
+ current_date_time = datetime.now()
13
+
14
+ if current_date_time >= config.END_DATE:
15
+ st.header("Private Leaderboard")
16
+ lb = utils.fetch_leaderboard(private=True)
17
+ st.table(lb)
18
+ else:
19
+ st.error("Private Leaderboard will be available after the competition ends")
20
+
21
+
22
+ if __name__ == "__main__":
23
+ app()
utils.py CHANGED
@@ -6,8 +6,11 @@ import time
6
  import requests
7
  from huggingface_hub import HfApi, hf_hub_download
8
  from huggingface_hub.utils._errors import EntryNotFoundError
9
-
 
 
10
  import config
 
11
 
12
 
13
  def get_auth_headers(token: str, prefix: str = "Bearer"):
@@ -201,10 +204,12 @@ def increment_submissions(user_id, submission_id, submission_comment):
201
  with open(user_fname, "r") as f:
202
  user_submission_info = json.load(f)
203
  todays_date = datetime.datetime.now().strftime("%Y-%m-%d")
 
204
  # here goes all the default stuff for submission
205
  user_submission_info["submissions"].append(
206
  {
207
  "date": todays_date,
 
208
  "submission_id": submission_id,
209
  "submission_comment": submission_comment,
210
  "status": "pending",
@@ -238,6 +243,7 @@ def verify_submission(bytes_data):
238
 
239
 
240
  def fetch_submissions(user_id):
 
241
  user_fname = hf_hub_download(
242
  repo_id=config.COMPETITION_ID,
243
  filename=f"{user_id}.json",
@@ -247,3 +253,60 @@ def fetch_submissions(user_id):
247
  with open(user_fname, "r") as f:
248
  user_submission_info = json.load(f)
249
  return user_submission_info["submissions"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  import requests
7
  from huggingface_hub import HfApi, hf_hub_download
8
  from huggingface_hub.utils._errors import EntryNotFoundError
9
+ import os
10
+ import glob
11
+ import pandas as pd
12
  import config
13
+ from huggingface_hub import snapshot_download
14
 
15
 
16
  def get_auth_headers(token: str, prefix: str = "Bearer"):
 
204
  with open(user_fname, "r") as f:
205
  user_submission_info = json.load(f)
206
  todays_date = datetime.datetime.now().strftime("%Y-%m-%d")
207
+ current_time = datetime.datetime.now().strftime("%H:%M:%S")
208
  # here goes all the default stuff for submission
209
  user_submission_info["submissions"].append(
210
  {
211
  "date": todays_date,
212
+ "time": current_time,
213
  "submission_id": submission_id,
214
  "submission_comment": submission_comment,
215
  "status": "pending",
 
243
 
244
 
245
  def fetch_submissions(user_id):
246
+ print(config.COMPETITION_ID)
247
  user_fname = hf_hub_download(
248
  repo_id=config.COMPETITION_ID,
249
  filename=f"{user_id}.json",
 
253
  with open(user_fname, "r") as f:
254
  user_submission_info = json.load(f)
255
  return user_submission_info["submissions"]
256
+
257
+
258
+ def fetch_leaderboard(private=False):
259
+ submissions_folder = snapshot_download(
260
+ repo_id=config.COMPETITION_ID,
261
+ allow_patterns="*.json",
262
+ use_auth_token=config.AUTOTRAIN_TOKEN,
263
+ repo_type="dataset",
264
+ )
265
+ submissions = []
266
+ for submission in glob.glob(os.path.join(submissions_folder, "*.json")):
267
+ with open(submission, "r") as f:
268
+ submission_info = json.load(f)
269
+ print(config.EVAL_HIGHER_IS_BETTER)
270
+ if config.EVAL_HIGHER_IS_BETTER:
271
+ submission_info["submissions"].sort(
272
+ key=lambda x: x["private_score"] if private else x["public_score"], reverse=True
273
+ )
274
+ else:
275
+ submission_info["submissions"].sort(key=lambda x: x["private_score"] if private else x["public_score"])
276
+ # select only the best submission
277
+ submission_info["submissions"] = submission_info["submissions"][0]
278
+ temp_info = {
279
+ "id": submission_info["id"],
280
+ "name": submission_info["name"],
281
+ "submission_id": submission_info["submissions"]["submission_id"],
282
+ "submission_comment": submission_info["submissions"]["submission_comment"],
283
+ "status": submission_info["submissions"]["status"],
284
+ "selected": submission_info["submissions"]["selected"],
285
+ "public_score": submission_info["submissions"]["public_score"],
286
+ "private_score": submission_info["submissions"]["private_score"],
287
+ "submission_date": submission_info["submissions"]["date"],
288
+ "submission_time": submission_info["submissions"]["time"],
289
+ }
290
+ submissions.append(temp_info)
291
+ print(submissions)
292
+
293
+ df = pd.DataFrame(submissions)
294
+ # convert submission date and time to datetime
295
+ df["submission_datetime"] = pd.to_datetime(
296
+ df["submission_date"] + " " + df["submission_time"], format="%Y-%m-%d %H:%M:%S"
297
+ )
298
+ # sort by submission datetime
299
+ # sort by public score and submission datetime
300
+ if config.EVAL_HIGHER_IS_BETTER:
301
+ df = df.sort_values(by=["public_score", "submission_datetime"], ascending=[False, True])
302
+ else:
303
+ df = df.sort_values(by=["public_score", "submission_datetime"], ascending=[True, True])
304
+ # reset index
305
+ df = df.reset_index(drop=True)
306
+ df["rank"] = df.index + 1
307
+
308
+ if private:
309
+ columns = ["rank", "name", "private_score", "submission_datetime"]
310
+ else:
311
+ columns = ["rank", "name", "public_score", "submission_datetime"]
312
+ return df[columns]