Spaces:
Running
Running
update dataset with at leaset 10 min interval
#82
by
ZeroCommand
- opened
- app_leaderboard.py +9 -0
app_leaderboard.py
CHANGED
@@ -3,12 +3,15 @@ import logging
|
|
3 |
import datasets
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
from fetch_utils import (check_dataset_and_get_config,
|
8 |
check_dataset_and_get_split)
|
9 |
|
10 |
import leaderboard
|
11 |
logger = logging.getLogger(__name__)
|
|
|
|
|
12 |
|
13 |
def get_records_from_dataset_repo(dataset_id):
|
14 |
dataset_config = check_dataset_and_get_config(dataset_id)
|
@@ -75,6 +78,8 @@ def get_display_df(df):
|
|
75 |
return display_df
|
76 |
|
77 |
def get_demo(leaderboard_tab):
|
|
|
|
|
78 |
logger.info("Loading leaderboard records")
|
79 |
leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
|
80 |
records = leaderboard.records
|
@@ -117,6 +122,10 @@ def get_demo(leaderboard_tab):
|
|
117 |
leaderboard_df = gr.DataFrame(display_df, datatype=types, interactive=False)
|
118 |
|
119 |
def update_leaderboard_records(model_id, dataset_id, columns, task):
|
|
|
|
|
|
|
|
|
120 |
logger.info("Updating leaderboard records")
|
121 |
leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
|
122 |
return filter_table(model_id, dataset_id, columns, task)
|
|
|
3 |
import datasets
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
+
import datetime
|
7 |
|
8 |
from fetch_utils import (check_dataset_and_get_config,
|
9 |
check_dataset_and_get_split)
|
10 |
|
11 |
import leaderboard
|
12 |
logger = logging.getLogger(__name__)
|
13 |
+
global update_time
|
14 |
+
update_time = datetime.datetime.fromtimestamp(0)
|
15 |
|
16 |
def get_records_from_dataset_repo(dataset_id):
|
17 |
dataset_config = check_dataset_and_get_config(dataset_id)
|
|
|
78 |
return display_df
|
79 |
|
80 |
def get_demo(leaderboard_tab):
|
81 |
+
global update_time
|
82 |
+
update_time = datetime.datetime.now()
|
83 |
logger.info("Loading leaderboard records")
|
84 |
leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
|
85 |
records = leaderboard.records
|
|
|
122 |
leaderboard_df = gr.DataFrame(display_df, datatype=types, interactive=False)
|
123 |
|
124 |
def update_leaderboard_records(model_id, dataset_id, columns, task):
|
125 |
+
global update_time
|
126 |
+
if datetime.datetime.now() - update_time < datetime.timedelta(minutes=10):
|
127 |
+
return gr.update()
|
128 |
+
update_time = datetime.datetime.now()
|
129 |
logger.info("Updating leaderboard records")
|
130 |
leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
|
131 |
return filter_table(model_id, dataset_id, columns, task)
|