tytsui commited on
Commit ·
d981b00
1
Parent(s): 693035e
Show error message
Browse files- app.py +9 -1
- src/leaderboard/student_results.py +36 -0
- tests/reproduce_issue.py +60 -0
app.py
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
| 7 |
from src.submission.student_queue import queue_student_submission
|
| 8 |
from src.envs import EVAL_RESULTS_PATH, RESULTS_REPO, TOKEN
|
| 9 |
|
|
@@ -31,8 +31,10 @@ 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 |
with gr.Row():
|
| 35 |
student_submit_result = gr.Markdown()
|
|
|
|
| 36 |
|
| 37 |
def _file_path(obj):
|
| 38 |
if obj is None:
|
|
@@ -62,6 +64,12 @@ with demo:
|
|
| 62 |
[student_submit_result],
|
| 63 |
)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
with gr.TabItem("📊 Leaderboard", elem_id="student-leaderboard-tab"):
|
| 66 |
# Ensure latest results are cached locally at startup
|
| 67 |
try:
|
|
|
|
| 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 |
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:
|
|
|
|
| 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
|
| 75 |
try:
|
src/leaderboard/student_results.py
CHANGED
|
@@ -98,3 +98,39 @@ def get_student_leaderboard_df(dataset_name: Optional[str] = None) -> Tuple[pd.D
|
|
| 98 |
return best_df, stats
|
| 99 |
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
return best_df, stats
|
| 99 |
|
| 100 |
|
| 101 |
+
|
| 102 |
+
def get_student_status(group_id: str) -> str:
|
| 103 |
+
attempts_dir = os.path.join(EVAL_RESULTS_PATH, PROJ_DIR, "student_attempts")
|
| 104 |
+
if not os.path.isdir(attempts_dir):
|
| 105 |
+
return "No submissions found."
|
| 106 |
+
|
| 107 |
+
rows = []
|
| 108 |
+
for fname in os.listdir(attempts_dir):
|
| 109 |
+
if not fname.endswith(".json"):
|
| 110 |
+
continue
|
| 111 |
+
try:
|
| 112 |
+
with open(os.path.join(attempts_dir, fname), "r") as f:
|
| 113 |
+
data = json.load(f)
|
| 114 |
+
# Ensure group_id comparison is robust (string vs int)
|
| 115 |
+
if str(data.get("group_id", "")).strip() == str(group_id).strip():
|
| 116 |
+
rows.append(data)
|
| 117 |
+
except Exception:
|
| 118 |
+
continue
|
| 119 |
+
|
| 120 |
+
if not rows:
|
| 121 |
+
return "No submissions found."
|
| 122 |
+
|
| 123 |
+
# Sort by timestamp desc
|
| 124 |
+
rows.sort(key=lambda x: x.get("timestamp", ""), reverse=True)
|
| 125 |
+
|
| 126 |
+
latest = rows[0]
|
| 127 |
+
status = latest.get("status", "UNKNOWN")
|
| 128 |
+
|
| 129 |
+
if status == "FAILED":
|
| 130 |
+
return f"Submission Failed: {latest.get('error', 'Unknown error')}"
|
| 131 |
+
elif status == "PENDING":
|
| 132 |
+
return "Submission Pending..."
|
| 133 |
+
elif status == "SUCCESS":
|
| 134 |
+
return "" # User requested to say nothing if success
|
| 135 |
+
else:
|
| 136 |
+
return f"Status: {status}"
|
tests/reproduce_issue.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
# Mock environment
|
| 8 |
+
PROJ_DIR = "Proj A"
|
| 9 |
+
EVAL_RESULTS_PATH = "/tmp/img2gps_test_results"
|
| 10 |
+
|
| 11 |
+
def setup_mock_data():
|
| 12 |
+
attempts_dir = os.path.join(EVAL_RESULTS_PATH, PROJ_DIR, "student_attempts")
|
| 13 |
+
os.makedirs(attempts_dir, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
# Create a failed attempt
|
| 16 |
+
attempt1 = {
|
| 17 |
+
"group_id": "123",
|
| 18 |
+
"alias": "TestGroup",
|
| 19 |
+
"timestamp": "20231027T100000Z",
|
| 20 |
+
"status": "FAILED",
|
| 21 |
+
"error": "Simulated error message",
|
| 22 |
+
"dataset": "img_val"
|
| 23 |
+
}
|
| 24 |
+
with open(os.path.join(attempts_dir, "attempt1.json"), "w") as f:
|
| 25 |
+
json.dump(attempt1, f)
|
| 26 |
+
|
| 27 |
+
# Create a success attempt (older)
|
| 28 |
+
attempt2 = {
|
| 29 |
+
"group_id": "123",
|
| 30 |
+
"alias": "TestGroup",
|
| 31 |
+
"timestamp": "20231026T100000Z",
|
| 32 |
+
"status": "SUCCESS",
|
| 33 |
+
"avg_distance_m": 100.0,
|
| 34 |
+
"dataset": "img_val"
|
| 35 |
+
}
|
| 36 |
+
with open(os.path.join(attempts_dir, "attempt2.json"), "w") as f:
|
| 37 |
+
json.dump(attempt2, f)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
setup_mock_data()
|
| 43 |
+
|
| 44 |
+
# Mock src.envs to avoid importing huggingface_hub
|
| 45 |
+
import sys
|
| 46 |
+
from unittest.mock import MagicMock
|
| 47 |
+
|
| 48 |
+
mock_envs = MagicMock()
|
| 49 |
+
mock_envs.EVAL_RESULTS_PATH = EVAL_RESULTS_PATH
|
| 50 |
+
mock_envs.PROJ_DIR = PROJ_DIR
|
| 51 |
+
sys.modules["src.envs"] = mock_envs
|
| 52 |
+
|
| 53 |
+
# Now import the function to test
|
| 54 |
+
from src.leaderboard.student_results import get_student_status
|
| 55 |
+
|
| 56 |
+
status = get_student_status("123")
|
| 57 |
+
print(f"Status for 123: {status}")
|
| 58 |
+
|
| 59 |
+
status_unknown = get_student_status("999")
|
| 60 |
+
print(f"Status for 999: {status_unknown}")
|