Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
d59421c
1
Parent(s):
51358a5
enforce 24h wait time
Browse files- app.py +5 -4
- src/submission/submit.py +37 -5
app.py
CHANGED
@@ -91,10 +91,9 @@ def add_solution_cbk(
|
|
91 |
return styled_error("Please sign in with Hugging Face before submitting.")
|
92 |
|
93 |
# Display handle and display name (may change over time)
|
94 |
-
handle
|
95 |
-
|
96 |
-
|
97 |
-
logger.info(f"Displaying name: {display_name}")
|
98 |
|
99 |
# Stable account id
|
100 |
claims = fetch_sub_claim(token) or {}
|
@@ -137,6 +136,8 @@ def add_solution_cbk(
|
|
137 |
|
138 |
return add_new_solutions(
|
139 |
lbdb,
|
|
|
|
|
140 |
system_name,
|
141 |
org,
|
142 |
sys_type,
|
|
|
91 |
return styled_error("Please sign in with Hugging Face before submitting.")
|
92 |
|
93 |
# Display handle and display name (may change over time)
|
94 |
+
logger.info(f"User handle: {profile.username}")
|
95 |
+
display_name = profile.name or profile.username
|
96 |
+
logger.info(f"Display name: {display_name}")
|
|
|
97 |
|
98 |
# Stable account id
|
99 |
claims = fetch_sub_claim(token) or {}
|
|
|
136 |
|
137 |
return add_new_solutions(
|
138 |
lbdb,
|
139 |
+
profile.username,
|
140 |
+
stable_id,
|
141 |
system_name,
|
142 |
org,
|
143 |
sys_type,
|
src/submission/submit.py
CHANGED
@@ -1,25 +1,30 @@
|
|
1 |
import time
|
2 |
-
from datetime import datetime, timezone
|
3 |
import os
|
4 |
import requests
|
5 |
|
6 |
import pandas as pd
|
7 |
-
from datasets import Dataset
|
8 |
from pandas.api.types import is_integer_dtype
|
9 |
import gradio as gr
|
10 |
|
11 |
from src.datamodel.data import F1Data
|
12 |
from src.display.formatting import styled_error, styled_message
|
13 |
from src.display.utils import ModelType
|
14 |
-
from src.envs import SUBMISSIONS_REPO
|
15 |
from src.logger import get_logger
|
16 |
from src.validation.validate import is_submission_file_valid, is_valid
|
17 |
|
|
|
18 |
logger = get_logger(__name__)
|
19 |
|
|
|
|
|
20 |
|
21 |
def add_new_solutions(
|
22 |
lbdb: F1Data,
|
|
|
|
|
23 |
system_name: str,
|
24 |
org: str,
|
25 |
sys_type: str,
|
@@ -27,8 +32,35 @@ def add_new_solutions(
|
|
27 |
is_warmup_dataset: bool,
|
28 |
ensure_all_present: bool = False,
|
29 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
logger.info(
|
31 |
-
f"Adding new submission
|
32 |
)
|
33 |
|
34 |
# Double-checking.
|
@@ -48,7 +80,7 @@ def add_new_solutions(
|
|
48 |
"An error occurred. Please try again later."
|
49 |
) # Use same message as external error. Avoid infoleak.
|
50 |
|
51 |
-
submission_id = f"{datetime.now(timezone.utc).strftime('%Y%m%d_%H%M%S')}_{
|
52 |
|
53 |
# Seems good, creating the eval.
|
54 |
logger.info(f"Adding new submission: {submission_id}")
|
|
|
1 |
import time
|
2 |
+
from datetime import datetime, timezone, timedelta
|
3 |
import os
|
4 |
import requests
|
5 |
|
6 |
import pandas as pd
|
7 |
+
from datasets import Dataset, get_dataset_config_names
|
8 |
from pandas.api.types import is_integer_dtype
|
9 |
import gradio as gr
|
10 |
|
11 |
from src.datamodel.data import F1Data
|
12 |
from src.display.formatting import styled_error, styled_message
|
13 |
from src.display.utils import ModelType
|
14 |
+
from src.envs import SUBMISSIONS_REPO, TOKEN
|
15 |
from src.logger import get_logger
|
16 |
from src.validation.validate import is_submission_file_valid, is_valid
|
17 |
|
18 |
+
|
19 |
logger = get_logger(__name__)
|
20 |
|
21 |
+
MIN_WAIT_TIME_PER_USER_HRS = 1
|
22 |
+
|
23 |
|
24 |
def add_new_solutions(
|
25 |
lbdb: F1Data,
|
26 |
+
username: str,
|
27 |
+
stable_id: str,
|
28 |
system_name: str,
|
29 |
org: str,
|
30 |
sys_type: str,
|
|
|
32 |
is_warmup_dataset: bool,
|
33 |
ensure_all_present: bool = False,
|
34 |
):
|
35 |
+
# Users must wait MIN_WAIT_TIME_PER_USER_HRS hours between submissions.
|
36 |
+
submitted_ids = get_dataset_config_names(SUBMISSIONS_REPO, token=TOKEN)
|
37 |
+
user_last_submission_date = None
|
38 |
+
for sid in submitted_ids:
|
39 |
+
# Extract stable ID (last part)
|
40 |
+
past_stable_id = sid.rsplit("_", 1)[-1]
|
41 |
+
# Extract timestamp string (first two parts)
|
42 |
+
ts_str = "_".join(sid.split("_", 2)[:2])
|
43 |
+
|
44 |
+
ts = datetime.strptime(ts_str, "%Y%m%d_%H%M%S").replace(tzinfo=timezone.utc)
|
45 |
+
if past_stable_id == stable_id:
|
46 |
+
if user_last_submission_date is None:
|
47 |
+
user_last_submission_date = ts
|
48 |
+
else:
|
49 |
+
user_last_submission_date = max(user_last_submission_date, ts)
|
50 |
+
|
51 |
+
if user_last_submission_date is not None:
|
52 |
+
now = datetime.now(timezone.utc)
|
53 |
+
elapsed = now - user_last_submission_date
|
54 |
+
if elapsed < timedelta(hours=MIN_WAIT_TIME_PER_USER_HRS):
|
55 |
+
remaining_hrs = (MIN_WAIT_TIME_PER_USER_HRS - elapsed.total_seconds()) / 3600
|
56 |
+
logger.info(f"{username} must wait {remaining_hrs:.2f} more hours.")
|
57 |
+
return styled_error(
|
58 |
+
f"You must wait {MIN_WAIT_TIME_PER_USER_HRS} hours between submissions. "
|
59 |
+
f"Remaining wait time: {remaining_hrs:.2f} hours"
|
60 |
+
)
|
61 |
+
|
62 |
logger.info(
|
63 |
+
f"Adding new submission: {system_name=}, {org=}, {sys_type=} and {submission_path=}",
|
64 |
)
|
65 |
|
66 |
# Double-checking.
|
|
|
80 |
"An error occurred. Please try again later."
|
81 |
) # Use same message as external error. Avoid infoleak.
|
82 |
|
83 |
+
submission_id = f"{datetime.now(timezone.utc).strftime('%Y%m%d_%H%M%S')}_{username}_{stable_id}"
|
84 |
|
85 |
# Seems good, creating the eval.
|
86 |
logger.info(f"Adding new submission: {submission_id}")
|