tytsui commited on
Commit ·
c4372d8
1
Parent(s): 8819b16
update
Browse files
app.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
from huggingface_hub import snapshot_download
|
| 4 |
|
| 5 |
from src.display.css_html_js import custom_css
|
| 6 |
-
from src.leaderboard.student_results import
|
| 7 |
-
get_group_submission_history,
|
| 8 |
-
get_latest_submission,
|
| 9 |
-
get_student_leaderboard_df,
|
| 10 |
-
)
|
| 11 |
-
import time
|
| 12 |
from src.submission.student_queue import queue_student_submission
|
| 13 |
-
from src.envs import EVAL_RESULTS_PATH, RESULTS_REPO, TOKEN
|
| 14 |
|
| 15 |
|
| 16 |
demo = gr.Blocks(css=custom_css)
|
|
@@ -48,6 +47,34 @@ with demo:
|
|
| 48 |
return obj.name
|
| 49 |
return str(obj)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
def handle_student_submit(group_id, alias, state_dict_file, model_py_file, preproc_py_file, progress=gr.Progress()):
|
| 52 |
try:
|
| 53 |
msg, ts = queue_student_submission(
|
|
@@ -69,6 +96,7 @@ with demo:
|
|
| 69 |
return f"Timed out waiting for results. Please check back later. Submission ID: {ts}"
|
| 70 |
|
| 71 |
try:
|
|
|
|
| 72 |
snapshot_download(
|
| 73 |
repo_id=RESULTS_REPO,
|
| 74 |
local_dir=EVAL_RESULTS_PATH,
|
|
@@ -77,18 +105,24 @@ with demo:
|
|
| 77 |
etag_timeout=30,
|
| 78 |
token=TOKEN,
|
| 79 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
except Exception:
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
if not submission:
|
| 85 |
continue
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
if submission.get("timestamp") != ts:
|
| 89 |
-
continue
|
| 90 |
-
|
| 91 |
-
status = submission.get("status", "UNKNOWN")
|
| 92 |
if status == "PENDING":
|
| 93 |
progress(0.5, desc="Evaluating...")
|
| 94 |
elif status == "SUCCESS":
|
|
@@ -215,8 +249,6 @@ with demo:
|
|
| 215 |
history_rows.append(
|
| 216 |
{
|
| 217 |
"Timestamp": sub.get("timestamp", ""),
|
| 218 |
-
"Status": sub.get("status", "UNKNOWN"),
|
| 219 |
-
"Error": sub.get("error", ""),
|
| 220 |
"Dataset": sub.get("dataset", ""),
|
| 221 |
"Avg distance (m)": sub.get("avg_distance_m"),
|
| 222 |
"Avg infer (ms)": sub.get("avg_infer_ms"),
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
import gradio as gr
|
| 6 |
import pandas as pd
|
| 7 |
from huggingface_hub import snapshot_download
|
| 8 |
|
| 9 |
from src.display.css_html_js import custom_css
|
| 10 |
+
from src.leaderboard.student_results import get_group_submission_history, get_student_leaderboard_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from src.submission.student_queue import queue_student_submission
|
| 12 |
+
from src.envs import EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, PROJ_DIR, QUEUE_REPO, RESULTS_REPO, TOKEN
|
| 13 |
|
| 14 |
|
| 15 |
demo = gr.Blocks(css=custom_css)
|
|
|
|
| 47 |
return obj.name
|
| 48 |
return str(obj)
|
| 49 |
|
| 50 |
+
def _load_latest_request(group_id: str, ts: str) -> dict | None:
|
| 51 |
+
"""Load the latest request.json for this group and timestamp from the local request cache."""
|
| 52 |
+
base_dir = os.path.join(EVAL_REQUESTS_PATH, PROJ_DIR)
|
| 53 |
+
if not os.path.isdir(base_dir):
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
rows = []
|
| 57 |
+
for root, _, files in os.walk(base_dir):
|
| 58 |
+
for fname in files:
|
| 59 |
+
if not fname.endswith(".json"):
|
| 60 |
+
continue
|
| 61 |
+
try:
|
| 62 |
+
with open(os.path.join(root, fname), "r") as f:
|
| 63 |
+
data = json.load(f)
|
| 64 |
+
if str(data.get("group_id", "")).strip() != str(group_id).strip():
|
| 65 |
+
continue
|
| 66 |
+
if data.get("timestamp") != ts:
|
| 67 |
+
continue
|
| 68 |
+
rows.append(data)
|
| 69 |
+
except Exception:
|
| 70 |
+
continue
|
| 71 |
+
|
| 72 |
+
if not rows:
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
rows.sort(key=lambda x: x.get("timestamp", ""), reverse=True)
|
| 76 |
+
return rows[0]
|
| 77 |
+
|
| 78 |
def handle_student_submit(group_id, alias, state_dict_file, model_py_file, preproc_py_file, progress=gr.Progress()):
|
| 79 |
try:
|
| 80 |
msg, ts = queue_student_submission(
|
|
|
|
| 96 |
return f"Timed out waiting for results. Please check back later. Submission ID: {ts}"
|
| 97 |
|
| 98 |
try:
|
| 99 |
+
# Keep both results and request queues up to date locally
|
| 100 |
snapshot_download(
|
| 101 |
repo_id=RESULTS_REPO,
|
| 102 |
local_dir=EVAL_RESULTS_PATH,
|
|
|
|
| 105 |
etag_timeout=30,
|
| 106 |
token=TOKEN,
|
| 107 |
)
|
| 108 |
+
snapshot_download(
|
| 109 |
+
repo_id=QUEUE_REPO,
|
| 110 |
+
local_dir=EVAL_REQUESTS_PATH,
|
| 111 |
+
repo_type="dataset",
|
| 112 |
+
tqdm_class=None,
|
| 113 |
+
etag_timeout=30,
|
| 114 |
+
token=TOKEN,
|
| 115 |
+
)
|
| 116 |
except Exception:
|
| 117 |
+
# Ignore transient network/cache errors and retry
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
# Read status and possible error message from request.json
|
| 121 |
+
submission = _load_latest_request(group_id, ts)
|
| 122 |
if not submission:
|
| 123 |
continue
|
| 124 |
+
|
| 125 |
+
status = submission.get("status", "PENDING")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
if status == "PENDING":
|
| 127 |
progress(0.5, desc="Evaluating...")
|
| 128 |
elif status == "SUCCESS":
|
|
|
|
| 249 |
history_rows.append(
|
| 250 |
{
|
| 251 |
"Timestamp": sub.get("timestamp", ""),
|
|
|
|
|
|
|
| 252 |
"Dataset": sub.get("dataset", ""),
|
| 253 |
"Avg distance (m)": sub.get("avg_distance_m"),
|
| 254 |
"Avg infer (ms)": sub.get("avg_infer_ms"),
|