Spaces:
Running
Running
Restart space if check significance server is not reachable
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ from content import (
|
|
| 15 |
MORE_DETAILS_MARKDOWN,
|
| 16 |
ABOUT_MARKDOWN,
|
| 17 |
)
|
| 18 |
-
from server import LeaderboardServer, xmlAndMarkdownEscape, xmlQuoteAttr, api, requests
|
| 19 |
|
| 20 |
HF_SPACE_TOKEN = os.environ["HF_SPACE_TOKEN"]
|
| 21 |
HF_SPACE_ID = os.environ["HF_SPACE_ID"]
|
|
@@ -397,6 +397,15 @@ def on_tournament_results_corrupted():
|
|
| 397 |
def restart_space():
|
| 398 |
api.restart_space(repo_id=HF_SPACE_ID, token=HF_SPACE_TOKEN)
|
| 399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
def on_application_load():
|
| 401 |
with leaderboard_server.var_lock.ro:
|
| 402 |
leaderboard = gr.update(
|
|
@@ -514,6 +523,15 @@ const intervalId = setInterval(addTitleForEachRowOfLeaderboardTable, 1000);
|
|
| 514 |
|
| 515 |
def gradio_app():
|
| 516 |
with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css, head=custom_js) as main:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
gr.Markdown(HEADER_MARKDOWN)
|
| 518 |
|
| 519 |
if leaderboard_server.tournament_results_corrupted:
|
|
|
|
| 15 |
MORE_DETAILS_MARKDOWN,
|
| 16 |
ABOUT_MARKDOWN,
|
| 17 |
)
|
| 18 |
+
from server import LeaderboardServer, xmlAndMarkdownEscape, xmlQuoteAttr, api, requests, check_significance_is_reachable
|
| 19 |
|
| 20 |
HF_SPACE_TOKEN = os.environ["HF_SPACE_TOKEN"]
|
| 21 |
HF_SPACE_ID = os.environ["HF_SPACE_ID"]
|
|
|
|
| 397 |
def restart_space():
|
| 398 |
api.restart_space(repo_id=HF_SPACE_ID, token=HF_SPACE_TOKEN)
|
| 399 |
|
| 400 |
+
def check_significance_is_reachable_hook():
|
| 401 |
+
# Due to a frequent exception on Hugging Face Space: requests.exceptions.ConnectionError("HTTPSConnectionPool(host='czechllm.fit.vutbr.cz', port=443): Max retries exceeded with url: /benczechmark-leaderboard/compare_significance/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa3bbf76320>: Failed to establish a new connection: [Errno 101] Network is unreachable'))")
|
| 402 |
+
|
| 403 |
+
if check_significance_is_reachable():
|
| 404 |
+
print("Check significance is reachable.")
|
| 405 |
+
return gr.update(active=False)
|
| 406 |
+
else:
|
| 407 |
+
restart_space()
|
| 408 |
+
|
| 409 |
def on_application_load():
|
| 410 |
with leaderboard_server.var_lock.ro:
|
| 411 |
leaderboard = gr.update(
|
|
|
|
| 523 |
|
| 524 |
def gradio_app():
|
| 525 |
with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css, head=custom_js) as main:
|
| 526 |
+
check_significance_is_reachable_timer = gr.Timer(
|
| 527 |
+
value=60, # seconds
|
| 528 |
+
)
|
| 529 |
+
|
| 530 |
+
check_significance_is_reachable_timer.tick(
|
| 531 |
+
fn=check_significance_is_reachable_hook,
|
| 532 |
+
outputs=check_significance_is_reachable_timer
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
gr.Markdown(HEADER_MARKDOWN)
|
| 536 |
|
| 537 |
if leaderboard_server.tournament_results_corrupted:
|
server.py
CHANGED
|
@@ -12,6 +12,7 @@ else:
|
|
| 12 |
print(f"{os.environ.get('CURL_CA_BUNDLE') = }")
|
| 13 |
print(f"{os.environ.get('REQUESTS_CA_BUNDLE') = }")
|
| 14 |
|
|
|
|
| 15 |
import hashlib
|
| 16 |
import time
|
| 17 |
from datetime import datetime, timezone
|
|
@@ -63,6 +64,25 @@ def xmlAndMarkdownEscape(text):
|
|
| 63 |
class CheckSignificanceError(Exception):
|
| 64 |
pass
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
def check_significance_send_task(model_a_path, model_b_path):
|
| 67 |
url = 'https://czechllm.fit.vutbr.cz/benczechmark-leaderboard/compare_significance/'
|
| 68 |
|
|
|
|
| 12 |
print(f"{os.environ.get('CURL_CA_BUNDLE') = }")
|
| 13 |
print(f"{os.environ.get('REQUESTS_CA_BUNDLE') = }")
|
| 14 |
|
| 15 |
+
import tempfile
|
| 16 |
import hashlib
|
| 17 |
import time
|
| 18 |
from datetime import datetime, timezone
|
|
|
|
| 64 |
class CheckSignificanceError(Exception):
|
| 65 |
pass
|
| 66 |
|
| 67 |
+
def check_significance_is_reachable():
|
| 68 |
+
with (
|
| 69 |
+
tempfile.NamedTemporaryFile(delete_on_close=False) as model_a_fp,
|
| 70 |
+
tempfile.NamedTemporaryFile(delete_on_close=False) as model_b_fp,
|
| 71 |
+
):
|
| 72 |
+
model_a_fp.close()
|
| 73 |
+
model_b_fp.close()
|
| 74 |
+
|
| 75 |
+
model_a_path = model_a_fp.name
|
| 76 |
+
model_b_path = model_b_fp.name
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
check_significance_send_task(model_a_path, model_b_path)
|
| 80 |
+
except CheckSignificanceError:
|
| 81 |
+
pass
|
| 82 |
+
except:
|
| 83 |
+
return False
|
| 84 |
+
return True
|
| 85 |
+
|
| 86 |
def check_significance_send_task(model_a_path, model_b_path):
|
| 87 |
url = 'https://czechllm.fit.vutbr.cz/benczechmark-leaderboard/compare_significance/'
|
| 88 |
|