Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -49,7 +49,8 @@ def api_client() -> HfApi:
|
|
| 49 |
def _today_utc_str() -> str:
|
| 50 |
return datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
| 51 |
|
| 52 |
-
def _count_submissions_today(username: str) -> int:
|
|
|
|
| 53 |
try:
|
| 54 |
files = api_client().list_repo_files(
|
| 55 |
repo_id=DB_REPO_ID, repo_type=DB_REPO_TYPE, token=SUBMISSIONS_TOKEN
|
|
@@ -65,17 +66,24 @@ def _count_submissions_today(username: str) -> int:
|
|
| 65 |
filename=f, token=SUBMISSIONS_TOKEN
|
| 66 |
)
|
| 67 |
meta = json.load(open(p))
|
| 68 |
-
if meta.get("username", "").lower() =
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
except Exception:
|
| 74 |
continue
|
| 75 |
return count
|
| 76 |
except Exception:
|
| 77 |
return 0
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
def _validate_submission_json(obj: Any) -> Tuple[bool, str]:
|
| 80 |
if not isinstance(obj, list):
|
| 81 |
return False, "Submission must be a JSON list of annotations."
|
|
@@ -241,7 +249,7 @@ def load_leaderboard():
|
|
| 241 |
return pd.DataFrame(), f"β Could not load leaderboard: {e}"
|
| 242 |
|
| 243 |
if not df.empty and "phase_codename" in df.columns:
|
| 244 |
-
df = df[df["phase_codename"] == "test-
|
| 245 |
|
| 246 |
if df.empty:
|
| 247 |
return pd.DataFrame(), "βΉοΈ No scored Standard phase submissions yet. Be the first!"
|
|
@@ -279,10 +287,15 @@ def handle_submit(file, team, model_name, phase_label, challenge_type, profile:
|
|
| 279 |
if not model_name.strip():
|
| 280 |
return "β Please enter a Model Name.", ""
|
| 281 |
|
| 282 |
-
#
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
# Parse JSON
|
| 288 |
try:
|
|
@@ -296,8 +309,6 @@ def handle_submit(file, team, model_name, phase_label, challenge_type, profile:
|
|
| 296 |
if not ok:
|
| 297 |
return f"β Invalid submission format: {msg}", ""
|
| 298 |
|
| 299 |
-
# Resolve phase codename
|
| 300 |
-
phase_codename = next((p["codename"] for p in PHASES if p["label"] == phase_label), phase_label)
|
| 301 |
original_filename = os.path.basename(file)
|
| 302 |
|
| 303 |
# Upload
|
|
@@ -315,9 +326,9 @@ def handle_submit(file, team, model_name, phase_label, challenge_type, profile:
|
|
| 315 |
except Exception as e:
|
| 316 |
return f"β Upload failed: {e}", ""
|
| 317 |
|
| 318 |
-
remaining =
|
| 319 |
return (
|
| 320 |
-
f"β
Submission queued successfully! Visit **My Submissions** to see the results. You have {remaining}/{
|
| 321 |
submission_id,
|
| 322 |
)
|
| 323 |
|
|
@@ -381,9 +392,13 @@ def load_my_submissions(phase_filter: str, profile: gr.OAuthProfile | None):
|
|
| 381 |
def get_daily_cap_info(profile: gr.OAuthProfile | None):
|
| 382 |
if profile is None:
|
| 383 |
return ""
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
|
| 389 |
def get_user_greeting(profile: gr.OAuthProfile | None):
|
|
@@ -553,8 +568,8 @@ with demo.route("Object Localization", "/object-localization") as obj_loc:
|
|
| 553 |
|
| 554 |
# Leaderboard
|
| 555 |
with gr.TabItem("π Leaderboard"):
|
| 556 |
-
gr.Markdown("###
|
| 557 |
-
gr.Markdown(f"Ranked by **{DEFAULT_SORT_METRIC}** (descending).
|
| 558 |
with gr.Accordion("π How is the Score Calculated?", open=False):
|
| 559 |
gr.Markdown(EVAL_DETAILS_MD)
|
| 560 |
lb_msg = gr.Markdown("")
|
|
@@ -654,7 +669,6 @@ with demo.route("Visual Question Answering", "/vqa"):
|
|
| 654 |
gr.Markdown("### π Coming Soon")
|
| 655 |
gr.Markdown(
|
| 656 |
"This challenge is currently under development. "
|
| 657 |
-
"Check back soon or follow [@VizWiz](https://vizwiz.org) for updates."
|
| 658 |
)
|
| 659 |
|
| 660 |
# ββ ANSWER GROUNDING PAGE βββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -663,7 +677,6 @@ with demo.route("Answer Grounding", "/answer-grounding"):
|
|
| 663 |
gr.Markdown("### π Coming Soon")
|
| 664 |
gr.Markdown(
|
| 665 |
"This challenge is currently under development. "
|
| 666 |
-
"Check back soon or follow [@VizWiz](https://vizwiz.org) for updates."
|
| 667 |
)
|
| 668 |
|
| 669 |
|
|
|
|
| 49 |
def _today_utc_str() -> str:
|
| 50 |
return datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
| 51 |
|
| 52 |
+
def _count_submissions_today(username: str, phase_codename: str | None = None) -> int:
|
| 53 |
+
"""Count today's submissions for a user, optionally filtered by phase."""
|
| 54 |
try:
|
| 55 |
files = api_client().list_repo_files(
|
| 56 |
repo_id=DB_REPO_ID, repo_type=DB_REPO_TYPE, token=SUBMISSIONS_TOKEN
|
|
|
|
| 66 |
filename=f, token=SUBMISSIONS_TOKEN
|
| 67 |
)
|
| 68 |
meta = json.load(open(p))
|
| 69 |
+
if meta.get("username", "").lower() != username.lower():
|
| 70 |
+
continue
|
| 71 |
+
if phase_codename and meta.get("phase_codename") != phase_codename:
|
| 72 |
+
continue
|
| 73 |
+
ts = meta.get("timestamp", 0)
|
| 74 |
+
sub_date = datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d")
|
| 75 |
+
if sub_date == today:
|
| 76 |
+
count += 1
|
| 77 |
except Exception:
|
| 78 |
continue
|
| 79 |
return count
|
| 80 |
except Exception:
|
| 81 |
return 0
|
| 82 |
|
| 83 |
+
def _get_cap_for_phase(phase_codename: str) -> int:
|
| 84 |
+
"""Return the daily submission cap for a given phase."""
|
| 85 |
+
return 1 if phase_codename == "test-challenge2024" else DAILY_SUBMISSION_CAP
|
| 86 |
+
|
| 87 |
def _validate_submission_json(obj: Any) -> Tuple[bool, str]:
|
| 88 |
if not isinstance(obj, list):
|
| 89 |
return False, "Submission must be a JSON list of annotations."
|
|
|
|
| 249 |
return pd.DataFrame(), f"β Could not load leaderboard: {e}"
|
| 250 |
|
| 251 |
if not df.empty and "phase_codename" in df.columns:
|
| 252 |
+
df = df[df["phase_codename"] == "test-challenge2024"]
|
| 253 |
|
| 254 |
if df.empty:
|
| 255 |
return pd.DataFrame(), "βΉοΈ No scored Standard phase submissions yet. Be the first!"
|
|
|
|
| 287 |
if not model_name.strip():
|
| 288 |
return "β Please enter a Model Name.", ""
|
| 289 |
|
| 290 |
+
# Resolve phase codename first (needed for cap check)
|
| 291 |
+
phase_codename = next((p["codename"] for p in PHASES if p["label"] == phase_label), phase_label)
|
| 292 |
+
cap = _get_cap_for_phase(phase_codename)
|
| 293 |
+
|
| 294 |
+
# Daily cap check (phase-specific)
|
| 295 |
+
subs_today = _count_submissions_today(username, phase_codename)
|
| 296 |
+
if subs_today >= cap:
|
| 297 |
+
phase_label_str = "challenge" if phase_codename == "test-challenge2024" else "this"
|
| 298 |
+
return f"β You've reached your daily limit of {cap} submission(s) for the {phase_label_str} phase. Come back tomorrow!", ""
|
| 299 |
|
| 300 |
# Parse JSON
|
| 301 |
try:
|
|
|
|
| 309 |
if not ok:
|
| 310 |
return f"β Invalid submission format: {msg}", ""
|
| 311 |
|
|
|
|
|
|
|
| 312 |
original_filename = os.path.basename(file)
|
| 313 |
|
| 314 |
# Upload
|
|
|
|
| 326 |
except Exception as e:
|
| 327 |
return f"β Upload failed: {e}", ""
|
| 328 |
|
| 329 |
+
remaining = cap - subs_today - 1
|
| 330 |
return (
|
| 331 |
+
f"β
Submission queued successfully! Visit **My Submissions** to see the results. You have {remaining}/{cap} submissions remaining today for this phase.",
|
| 332 |
submission_id,
|
| 333 |
)
|
| 334 |
|
|
|
|
| 392 |
def get_daily_cap_info(profile: gr.OAuthProfile | None):
|
| 393 |
if profile is None:
|
| 394 |
return ""
|
| 395 |
+
lines = []
|
| 396 |
+
for p in PHASES:
|
| 397 |
+
cap = _get_cap_for_phase(p["codename"])
|
| 398 |
+
used = _count_submissions_today(profile.username, p["codename"])
|
| 399 |
+
remaining = cap - used
|
| 400 |
+
lines.append(f"**{p['label'].split('(')[0].strip()}:** {remaining}/{cap} remaining")
|
| 401 |
+
return " \n".join(lines)
|
| 402 |
|
| 403 |
|
| 404 |
def get_user_greeting(profile: gr.OAuthProfile | None):
|
|
|
|
| 568 |
|
| 569 |
# Leaderboard
|
| 570 |
with gr.TabItem("π Leaderboard"):
|
| 571 |
+
gr.Markdown("### Challenge Phase Rankings")
|
| 572 |
+
gr.Markdown(f"Ranked by **{DEFAULT_SORT_METRIC}** (descending). Challenge phase only.")
|
| 573 |
with gr.Accordion("π How is the Score Calculated?", open=False):
|
| 574 |
gr.Markdown(EVAL_DETAILS_MD)
|
| 575 |
lb_msg = gr.Markdown("")
|
|
|
|
| 669 |
gr.Markdown("### π Coming Soon")
|
| 670 |
gr.Markdown(
|
| 671 |
"This challenge is currently under development. "
|
|
|
|
| 672 |
)
|
| 673 |
|
| 674 |
# ββ ANSWER GROUNDING PAGE βββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 677 |
gr.Markdown("### π Coming Soon")
|
| 678 |
gr.Markdown(
|
| 679 |
"This challenge is currently under development. "
|
|
|
|
| 680 |
)
|
| 681 |
|
| 682 |
|