AlexNijjar commited on
Commit
0eac6a7
1 Parent(s): 25306b9

implement continuous leaderboard fetching

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +24 -10
  3. requirements.txt +1 -0
.gitignore CHANGED
@@ -4,5 +4,6 @@ __pycache__/
4
  .ipynb_checkpoints
5
  *ipynb
6
  .vscode/
 
7
 
8
  logs/
 
4
  .ipynb_checkpoints
5
  *ipynb
6
  .vscode/
7
+ .idea/
8
 
9
  logs/
app.py CHANGED
@@ -1,13 +1,15 @@
1
  import os
 
2
  from dataclasses import dataclass
3
 
4
- from substrateinterface import Keypair
5
- from wandb.apis.public import Runs, Run
6
-
7
- import wandb
8
  import gradio as gr
 
 
 
 
9
 
10
  wandb_api = wandb.Api()
 
11
 
12
  SOURCE_VALIDATOR_UID = int(os.environ["SOURCE_VALIDATOR_UID"])
13
  WANDB_RUN_PATH = os.environ["WANDB_RUN_PATH"]
@@ -42,8 +44,11 @@ def is_valid_run(run: Run):
42
  return False
43
 
44
 
45
- def main():
46
- demo = gr.Blocks(css=".typewriter {font-family: 'JMH Typewriter', sans-serif;}")
 
 
 
47
  with demo:
48
  with gr.Accordion("Contest #1 Submission Leader: New Dream SDXL on NVIDIA RTX 4090s"):
49
  runs: Runs = wandb_api.runs(
@@ -77,20 +82,29 @@ def main():
77
  continue
78
 
79
  leaderboard: list[tuple] = [
80
- (entry.uid, entry.model, entry.score, entry.hotkey, entry.previous_day_winner)
81
  for entry in sorted(entries.values(), key=lambda entry: entry.rank)
82
  ]
83
 
84
  gr.components.Dataframe(
85
  value=leaderboard,
86
- headers=["Uid", "Model", "Score", "Hotkey", "Previous day winner"],
87
- datatype=["number", "markdown", "number", "markdown", "bool"],
88
  elem_id="leaderboard-table",
89
  interactive=False,
90
  visible=True,
91
  )
92
 
93
- demo.launch()
 
 
 
 
 
 
 
 
 
94
 
95
 
96
  main()
 
1
  import os
2
+ import time
3
  from dataclasses import dataclass
4
 
 
 
 
 
5
  import gradio as gr
6
+ import schedule
7
+ import wandb
8
+ from substrateinterface import Keypair
9
+ from wandb.apis.public import Run, Runs
10
 
11
  wandb_api = wandb.Api()
12
+ demo = gr.Blocks(css=".typewriter {font-family: 'JMH Typewriter', sans-serif;}")
13
 
14
  SOURCE_VALIDATOR_UID = int(os.environ["SOURCE_VALIDATOR_UID"])
15
  WANDB_RUN_PATH = os.environ["WANDB_RUN_PATH"]
 
44
  return False
45
 
46
 
47
+ def refresh_leaderboard():
48
+ print("Refreshing Leaderboard")
49
+
50
+ demo.clear()
51
+
52
  with demo:
53
  with gr.Accordion("Contest #1 Submission Leader: New Dream SDXL on NVIDIA RTX 4090s"):
54
  runs: Runs = wandb_api.runs(
 
82
  continue
83
 
84
  leaderboard: list[tuple] = [
85
+ (entry.rank + 1, entry.uid, entry.model, entry.score, entry.hotkey, entry.previous_day_winner)
86
  for entry in sorted(entries.values(), key=lambda entry: entry.rank)
87
  ]
88
 
89
  gr.components.Dataframe(
90
  value=leaderboard,
91
+ headers=["Rank", "Uid", "Model", "Score", "Hotkey", "Previous day winner"],
92
+ datatype=["number", "number", "markdown", "number", "markdown", "bool"],
93
  elem_id="leaderboard-table",
94
  interactive=False,
95
  visible=True,
96
  )
97
 
98
+
99
+ def main():
100
+ refresh_leaderboard()
101
+ schedule.every().day.at("09:30:00", "America/New_York").do(refresh_leaderboard)
102
+
103
+ demo.launch(prevent_thread_lock=True)
104
+
105
+ while True:
106
+ schedule.run_pending()
107
+ time.sleep(1)
108
 
109
 
110
  main()
requirements.txt CHANGED
@@ -2,3 +2,4 @@ black
2
  gradio
3
  wandb
4
  substrate-interface
 
 
2
  gradio
3
  wandb
4
  substrate-interface
5
+ schedule