Spaces:
Sleeping
Sleeping
Update main.py
Browse files48 unmodified lines495051525354559 unmodified lines6566676869707172737475767778798081159 unmodified lines24124224324424524624731 unmodified lines2792802812822832842852862872887 unmodified lines29629729829930030130230311 unmodified lines31531631731831932032132232357 unmodified lines381382383384385386387388389163 unmodified lines55355455555655755855956093 unmodified lines6546556566576586596602 unmodified lines66366466566666766866948 unmodified linesdef _today_utc_str() -> str:return datetime.now(timezone.utc).strftime("%Y-%m-%d")def _count_submissions_today(username: str) -> int:try:files = api_client().list_repo_files(repo_id=DB_REPO_ID, repo_type=DB_REPO_TYPE, token=SUBMISSIONS_TOKEN9 unmodified linesfilename=f, token=SUBMISSIONS_TOKEN)meta = json.load(open(p))if meta.get("username", "").lower() == username.lower():ts = meta.get("timestamp", 0)sub_date = datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d")if sub_date == today:count += 1except Exception:continuereturn countexcept Exception:return 0def _validate_submission_json(obj: Any) -> Tuple[bool, str]:if not isinstance(obj, list):return False, "Submission must be a JSON list of annotations."159 unmodified linesreturn pd.DataFrame(), f"β Could not load leaderboard: {e}"if not df.empty and "phase_codename" in df.columns:df = df[df["phase_codename"] == "test-standard2024"]if df.empty:return pd.DataFrame(), "βΉοΈ No scored Standard phase submissions yet. Be the first!"31 unmodified linesif not model_name.strip():return "β Please enter a Model Name.", ""# Daily cap checksubs_today = _count_submissions_today(username)if subs_today >= DAILY_SUBMISSION_CAP:return f"β You've reached your daily limit of {DAILY_SUBMISSION_CAP} submissions. Come back tomorrow!", ""# Parse JSONtry:7 unmodified linesif not ok:return f"β Invalid submission format: {msg}", ""# Resolve phase codenamephase_codename = next((p["codename"] for p in PHASES if p["label"] == phase_label), phase_label)original_filename = os.path.basename(file)# Upload11 unmodified linesexcept Exception as e:return f"β Upload failed: {e}", ""remaining = DAILY_SUBMISSION_CAP - subs_today - 1return (f"β Submission queued successfully! Visit **My Submissions** to see the results. You have {remaining}/{DAILY_SUBMISSION_CAP} submissions remaining today.",submission_id,)57 unmodified linesdef get_daily_cap_info(profile: gr.OAuthProfile | None):if profile is None:return ""subs_today = _count_submissions_today(profile.username)remaining = DAILY_SUBMISSION_CAP - subs_todayreturn f"**{remaining}/{DAILY_SUBMISSION_CAP}** submissions remaining today"def get_user_greeting(profile: gr.OAuthProfile | None):163 unmodified lines# Leaderboardwith gr.TabItem("π Leaderboard"):gr.Markdown("### Standard Phase Rankings")gr.Markdown(f"Ranked by **{DEFAULT_SORT_METRIC}** (descending). Standard phase only.")with gr.Accordion("π How is the Score Calculated?", open=False):gr.Markdown(EVAL_DETAILS_MD)lb_msg = gr.Markdown("")93 unmodified linesgr.Markdown("### π Coming Soon")gr.Markdown("This challenge is currently under development. ""Check back soon or follow [@VizWiz](https://vizwiz.org) for updates.")# ββ ANSWER GROUNDING PAGE βββββββββββββββββββββββββββββββββββββββββββββ2 unmodified linesgr.Markdown("### π Coming Soon")gr.Markdown("This challenge is currently under development. ""Check back soon or follow [@VizWiz](https://vizwiz.org) for updates.")48 unmodified lines49505152535455569 unmodified lines666768697071727374757677787980818283848586878889159 unmodified lines24925025125225325425531 unmodified lines2872882892902912922932942952962972982993003017 unmodified lines30931031131231331411 unmodified lines32632732832933033133233333457 unmodified lines392393394395396397398399400401402403404163 unmodified lines56856957057157257357457593 unmodified lines6696706716726736742 unmodified lines67767867968068168248 unmodified linesdef _today_utc_str() -> str:return datetime.now(timezone.utc).strftime("%Y-%m-%d")def _count_submissions_today(username: str, phase_codename: str | None = None) -> int:"""Count today's submissions for a user, optionally filtered by phase."""try:files = api_client().list_repo_files(repo_id=DB_REPO_ID, repo_type=DB_REPO_TYPE, token=SUBMISSIONS_TOKEN9 unmodified linesfilename=f, token=SUBMISSIONS_TOKEN)meta = json.load(open(p))if meta.get("username", "").lower() != username.lower():continueif phase_codename and meta.get("phase_codename") != phase_codename:continuets = meta.get("timestamp", 0)sub_date = datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d")if sub_date == today:count += 1except Exception:continuereturn countexcept Exception:return 0def _get_cap_for_phase(phase_codename: str) -> int:"""Return the daily submission cap for a given phase."""return 1 if phase_codename == "test-challenge2024" else DAILY_SUBMISSION_CAPdef _validate_submission_json(obj: Any) -> Tuple[bool, str]:if not isinstance(obj, list):return False, "Submission must be a JSON list of annotations."159 unmodified linesreturn pd.DataFrame(), f"β Could not load leaderboard: {e}"if not df.empty and "phase_codename" in df.columns:df = df[df["phase_codename"] == "test-challenge2024"]if df.empty:return pd.DataFrame(), "βΉοΈ No scored Standard phase submissions yet. Be the first!"31 unmodified linesif not model_name.strip():return "β Please enter a Model Name.", ""# Resolve phase codename first (needed for cap check)phase_codename = next((p["codename"] for p in PHASES if p["label"] == phase_label), phase_label)cap = _get_cap_for_phase(phase_codename)# Daily cap check (phase-specific)subs_today = _count_submissions_today(username, phase_codename)if subs_today >= cap:phase_label_str = "challenge" if phase_codename == "test-challenge2024" else "this"return f"β You've reached your daily limit of {cap} submission(s) for the {phase_label_str} phase. Come back tomorrow!", ""# Parse JSONtry:7 unmodified linesif not ok:return f"β Invalid submission format: {msg}", ""original_filename = os.path.basename(file)# Upload11 unmodified linesexcept Exception as e:return f"β Upload failed: {e}", ""remaining = cap - subs_today - 1return (f"β Submission queued successfully! Visit **My Submissions** to see the results. You have {remaining}/{cap} submissions remaining today for this phase.",submission_id,)57 unmodified linesdef get_daily_cap_info(profile: gr.OAuthProfile | None):if profile is None:return ""lines = []for p in PHASES:cap = _get_cap_for_phase(p["codename"])used = _count_submissions_today(profile.username, p["codename"])remaining = cap - usedlines.append(f"**{p['label'].split('(')[0].strip()}:** {remaining}/{cap} remaining")return " \n".join(lines)def get_user_greeting(profile: gr.OAuthProfile | None):163 unmodified lines# Leaderboardwith gr.TabItem("π Leaderboard"):gr.Markdown("### Challenge Phase Rankings")gr.Markdown(f"Ranked by **{DEFAULT_SORT_METRIC}** (descending). Challenge phase only.")with gr.Accordion("π How is the Score Calculated?", open=False):gr.Markdown(EVAL_DETAILS_MD)lb_msg = gr.Markdown("")93 unmodified linesgr.Markdown("### π Coming Soon")gr.Markdown("This challenge is currently under development. ")# ββ ANSWER GROUNDING PAGE βββββββββββββββββββββββββββββββββββββββββββββ2 unmodified linesgr.Markdown("### π Coming Soon")gr.Markdown("This challenge is currently under development. ")
main.py+35-22