tytsui commited on
Commit ·
ef2699c
1
Parent(s): d981b00
update
Browse files- app.py +43 -12
- src/leaderboard/student_results.py +26 -0
- src/submission/student_queue.py +2 -2
app.py
CHANGED
|
@@ -3,7 +3,8 @@ 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 get_student_leaderboard_df, get_student_status
|
|
|
|
| 7 |
from src.submission.student_queue import queue_student_submission
|
| 8 |
from src.envs import EVAL_RESULTS_PATH, RESULTS_REPO, TOKEN
|
| 9 |
|
|
@@ -31,10 +32,8 @@ with demo:
|
|
| 31 |
preproc_py_uploader = gr.File(label="Preprocessing (preprocess.py)", file_count="single", file_types=[".py"])
|
| 32 |
with gr.Row():
|
| 33 |
eval_btn = gr.Button("Upload and Queue Evaluation")
|
| 34 |
-
status_btn = gr.Button("Check Status")
|
| 35 |
with gr.Row():
|
| 36 |
student_submit_result = gr.Markdown()
|
| 37 |
-
student_status_result = gr.Markdown()
|
| 38 |
|
| 39 |
def _file_path(obj):
|
| 40 |
if obj is None:
|
|
@@ -45,18 +44,55 @@ with demo:
|
|
| 45 |
return obj.name
|
| 46 |
return str(obj)
|
| 47 |
|
| 48 |
-
def handle_student_submit(group_id, alias, state_dict_file, model_py_file, preproc_py_file):
|
| 49 |
try:
|
| 50 |
-
msg = queue_student_submission(
|
| 51 |
group_id=group_id,
|
| 52 |
alias=alias,
|
| 53 |
state_dict_file=_file_path(state_dict_file),
|
| 54 |
model_py_file=_file_path(model_py_file),
|
| 55 |
preproc_py_file=_file_path(preproc_py_file),
|
| 56 |
)
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
eval_btn.click(
|
| 62 |
handle_student_submit,
|
|
@@ -64,11 +100,6 @@ with demo:
|
|
| 64 |
[student_submit_result],
|
| 65 |
)
|
| 66 |
|
| 67 |
-
status_btn.click(
|
| 68 |
-
get_student_status,
|
| 69 |
-
[group_id_tb],
|
| 70 |
-
[student_status_result],
|
| 71 |
-
)
|
| 72 |
|
| 73 |
with gr.TabItem("📊 Leaderboard", elem_id="student-leaderboard-tab"):
|
| 74 |
# Ensure latest results are cached locally at startup
|
|
|
|
| 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 get_student_leaderboard_df, get_student_status, get_latest_submission
|
| 7 |
+
import time
|
| 8 |
from src.submission.student_queue import queue_student_submission
|
| 9 |
from src.envs import EVAL_RESULTS_PATH, RESULTS_REPO, TOKEN
|
| 10 |
|
|
|
|
| 32 |
preproc_py_uploader = gr.File(label="Preprocessing (preprocess.py)", file_count="single", file_types=[".py"])
|
| 33 |
with gr.Row():
|
| 34 |
eval_btn = gr.Button("Upload and Queue Evaluation")
|
|
|
|
| 35 |
with gr.Row():
|
| 36 |
student_submit_result = gr.Markdown()
|
|
|
|
| 37 |
|
| 38 |
def _file_path(obj):
|
| 39 |
if obj is None:
|
|
|
|
| 44 |
return obj.name
|
| 45 |
return str(obj)
|
| 46 |
|
| 47 |
+
def handle_student_submit(group_id, alias, state_dict_file, model_py_file, preproc_py_file, progress=gr.Progress()):
|
| 48 |
try:
|
| 49 |
+
msg, ts = queue_student_submission(
|
| 50 |
group_id=group_id,
|
| 51 |
alias=alias,
|
| 52 |
state_dict_file=_file_path(state_dict_file),
|
| 53 |
model_py_file=_file_path(model_py_file),
|
| 54 |
preproc_py_file=_file_path(preproc_py_file),
|
| 55 |
)
|
| 56 |
+
progress(0.2, desc="Queueing...")
|
| 57 |
except Exception as e:
|
| 58 |
+
return f"Error during submission: {e}"
|
| 59 |
+
|
| 60 |
+
# Polling loop
|
| 61 |
+
start_time = time.time()
|
| 62 |
+
while True:
|
| 63 |
+
time.sleep(5)
|
| 64 |
+
if time.time() - start_time > 600: # 10 min timeout
|
| 65 |
+
return f"Timed out waiting for results. Please check back later. Submission ID: {ts}"
|
| 66 |
+
|
| 67 |
+
try:
|
| 68 |
+
snapshot_download(
|
| 69 |
+
repo_id=RESULTS_REPO,
|
| 70 |
+
local_dir=EVAL_RESULTS_PATH,
|
| 71 |
+
repo_type="dataset",
|
| 72 |
+
tqdm_class=None,
|
| 73 |
+
etag_timeout=30,
|
| 74 |
+
token=TOKEN,
|
| 75 |
+
)
|
| 76 |
+
except Exception:
|
| 77 |
+
pass # Ignore network errors during polling
|
| 78 |
+
|
| 79 |
+
submission = get_latest_submission(group_id)
|
| 80 |
+
if not submission:
|
| 81 |
+
continue
|
| 82 |
+
|
| 83 |
+
# Check if this is the submission we just made
|
| 84 |
+
if submission.get("timestamp") != ts:
|
| 85 |
+
continue
|
| 86 |
+
|
| 87 |
+
status = submission.get("status", "UNKNOWN")
|
| 88 |
+
if status == "PENDING":
|
| 89 |
+
progress(0.5, desc="Evaluating...")
|
| 90 |
+
elif status == "SUCCESS":
|
| 91 |
+
progress(1.0, desc="Done!")
|
| 92 |
+
return "Evaluation Successful! Check the Leaderboard tab."
|
| 93 |
+
elif status == "FAILED":
|
| 94 |
+
progress(1.0, desc="Failed")
|
| 95 |
+
return f"Submission Failed: {submission.get('error', 'Unknown error')}"
|
| 96 |
|
| 97 |
eval_btn.click(
|
| 98 |
handle_student_submit,
|
|
|
|
| 100 |
[student_submit_result],
|
| 101 |
)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
with gr.TabItem("📊 Leaderboard", elem_id="student-leaderboard-tab"):
|
| 105 |
# Ensure latest results are cached locally at startup
|
src/leaderboard/student_results.py
CHANGED
|
@@ -134,3 +134,29 @@ def get_student_status(group_id: str) -> str:
|
|
| 134 |
return "" # User requested to say nothing if success
|
| 135 |
else:
|
| 136 |
return f"Status: {status}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
return "" # User requested to say nothing if success
|
| 135 |
else:
|
| 136 |
return f"Status: {status}"
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def get_latest_submission(group_id: str) -> Optional[Dict]:
|
| 140 |
+
attempts_dir = os.path.join(EVAL_RESULTS_PATH, PROJ_DIR, "student_attempts")
|
| 141 |
+
if not os.path.isdir(attempts_dir):
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
rows = []
|
| 145 |
+
for fname in os.listdir(attempts_dir):
|
| 146 |
+
if not fname.endswith(".json"):
|
| 147 |
+
continue
|
| 148 |
+
try:
|
| 149 |
+
with open(os.path.join(attempts_dir, fname), "r") as f:
|
| 150 |
+
data = json.load(f)
|
| 151 |
+
# Ensure group_id comparison is robust (string vs int)
|
| 152 |
+
if str(data.get("group_id", "")).strip() == str(group_id).strip():
|
| 153 |
+
rows.append(data)
|
| 154 |
+
except Exception:
|
| 155 |
+
continue
|
| 156 |
+
|
| 157 |
+
if not rows:
|
| 158 |
+
return None
|
| 159 |
+
|
| 160 |
+
# Sort by timestamp desc
|
| 161 |
+
rows.sort(key=lambda x: x.get("timestamp", ""), reverse=True)
|
| 162 |
+
return rows[0]
|
src/submission/student_queue.py
CHANGED
|
@@ -22,7 +22,7 @@ def queue_student_submission(
|
|
| 22 |
state_dict_file: Optional[str],
|
| 23 |
model_py_file: str,
|
| 24 |
preproc_py_file: str,
|
| 25 |
-
) -> str:
|
| 26 |
"""
|
| 27 |
Uploads submitted files to the private queue dataset for offline evaluation.
|
| 28 |
Layout in repo:
|
|
@@ -97,6 +97,6 @@ def queue_student_submission(
|
|
| 97 |
except Exception:
|
| 98 |
pass
|
| 99 |
|
| 100 |
-
return f"Submission queued for Group '{group_id}' at {ts}. Your model will be evaluated shortly."
|
| 101 |
|
| 102 |
|
|
|
|
| 22 |
state_dict_file: Optional[str],
|
| 23 |
model_py_file: str,
|
| 24 |
preproc_py_file: str,
|
| 25 |
+
) -> tuple[str, str]:
|
| 26 |
"""
|
| 27 |
Uploads submitted files to the private queue dataset for offline evaluation.
|
| 28 |
Layout in repo:
|
|
|
|
| 97 |
except Exception:
|
| 98 |
pass
|
| 99 |
|
| 100 |
+
return f"Submission queued for Group '{group_id}' at {ts}. Your model will be evaluated shortly.", ts
|
| 101 |
|
| 102 |
|