Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Clémentine
commited on
Commit
•
a39e583
1
Parent(s):
b974197
prevent too many concurrent calls
Browse files
app.py
CHANGED
@@ -48,6 +48,7 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(
|
|
48 |
# Convert the environment variable "LEADERBOARD_FULL_INIT" to a boolean value, defaulting to True if the variable is not set.
|
49 |
# This controls whether a full initialization should be performed.
|
50 |
DO_FULL_INIT = os.getenv("LEADERBOARD_FULL_INIT", "True") == "True"
|
|
|
51 |
|
52 |
def restart_space():
|
53 |
API.restart_space(repo_id=REPO_ID, token=HF_TOKEN)
|
@@ -89,7 +90,11 @@ def download_dataset(repo_id, local_dir, repo_type="dataset", max_attempts=3, ba
|
|
89 |
attempt += 1
|
90 |
raise Exception(f"Failed to download {repo_id} after {max_attempts} attempts")
|
91 |
|
92 |
-
def get_latest_data_leaderboard():
|
|
|
|
|
|
|
|
|
93 |
leaderboard_dataset = datasets.load_dataset(
|
94 |
AGGREGATED_REPO,
|
95 |
"default",
|
@@ -306,6 +311,8 @@ with demo:
|
|
306 |
)
|
307 |
|
308 |
demo.load(fn=get_latest_data_leaderboard, inputs=None, outputs=[leaderboard])
|
|
|
|
|
309 |
|
310 |
demo.queue(default_concurrency_limit=40)
|
311 |
|
@@ -355,17 +362,17 @@ async def update_leaderboard(payload: WebhookPayload) -> None:
|
|
355 |
verification_mode="no_checks"
|
356 |
)
|
357 |
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
|
371 |
webhooks_server.launch()
|
|
|
48 |
# Convert the environment variable "LEADERBOARD_FULL_INIT" to a boolean value, defaulting to True if the variable is not set.
|
49 |
# This controls whether a full initialization should be performed.
|
50 |
DO_FULL_INIT = os.getenv("LEADERBOARD_FULL_INIT", "True") == "True"
|
51 |
+
LAST_UPDATE_LEADERBOARD = datetime.datetime.now()
|
52 |
|
53 |
def restart_space():
|
54 |
API.restart_space(repo_id=REPO_ID, token=HF_TOKEN)
|
|
|
90 |
attempt += 1
|
91 |
raise Exception(f"Failed to download {repo_id} after {max_attempts} attempts")
|
92 |
|
93 |
+
def get_latest_data_leaderboard(init: bool = False):
|
94 |
+
current_time = datetime.datetime.now()
|
95 |
+
if current_time - LAST_UPDATE_LEADERBOARD < datetime.timedelta(minutes=10):
|
96 |
+
return
|
97 |
+
LAST_UPDATE_LEADERBOARD = current_time
|
98 |
leaderboard_dataset = datasets.load_dataset(
|
99 |
AGGREGATED_REPO,
|
100 |
"default",
|
|
|
311 |
)
|
312 |
|
313 |
demo.load(fn=get_latest_data_leaderboard, inputs=None, outputs=[leaderboard])
|
314 |
+
#demo.load(fn=get_latest_data_queue, inputs=None, outputs=[finished_eval_table, running_eval_table, pending_eval_table])
|
315 |
+
|
316 |
|
317 |
demo.queue(default_concurrency_limit=40)
|
318 |
|
|
|
362 |
verification_mode="no_checks"
|
363 |
)
|
364 |
|
365 |
+
LAST_UPDATE_QUEUE = datetime.datetime.now()
|
366 |
+
@webhooks_server.add_webhook
|
367 |
+
async def update_queue(payload: WebhookPayload) -> None:
|
368 |
+
"""Redownloads the queue dataset each time it updates"""
|
369 |
+
if payload.repo.type == "dataset" and payload.event.action == "update":
|
370 |
+
current_time = datetime.datetime.now()
|
371 |
+
if current_time - LAST_UPDATE_QUEUE > datetime.timedelta(minutes=10):
|
372 |
+
print("would have updated")
|
373 |
+
# We only redownload is last update was more than 10 minutes ago, as the queue is
|
374 |
+
# updated regularly and heavy to download
|
375 |
+
#download_dataset(QUEUE_REPO, EVAL_REQUESTS_PATH)
|
376 |
+
LAST_UPDATE_QUEUE = datetime.datetime.now()
|
377 |
|
378 |
webhooks_server.launch()
|