Spaces:
Running
Running
Jason
commited on
Jason/submit only to submissions repo (#65)
Browse filesscoring, result publishing no longer automatic through web submissions
- app.py +3 -0
- config.py +1 -4
- submission.py +89 -69
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
# app.py
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import urllib.parse
|
4 |
|
|
|
1 |
# app.py
|
2 |
+
import logging
|
3 |
+
logging.basicConfig(level=logging.WARNING)
|
4 |
+
|
5 |
import gradio as gr
|
6 |
import urllib.parse
|
7 |
|
config.py
CHANGED
@@ -18,8 +18,5 @@ else:
|
|
18 |
RESULTS_DATASET = f"allenai/asta-bench-results"
|
19 |
LEADERBOARD_PATH = f"allenai/asta-bench-leaderboard"
|
20 |
|
21 |
-
|
22 |
-
DATA_DIR = os.path.join(os.path.dirname(__file__), "data", CONFIG_NAME)
|
23 |
-
else:
|
24 |
-
DATA_DIR = "/home/user/data/" + CONFIG_NAME
|
25 |
EXTRACTED_DATA_DIR = os.path.join(DATA_DIR, "extracted")
|
|
|
18 |
RESULTS_DATASET = f"allenai/asta-bench-results"
|
19 |
LEADERBOARD_PATH = f"allenai/asta-bench-leaderboard"
|
20 |
|
21 |
+
DATA_DIR = "/tmp/abl/data/" + CONFIG_NAME
|
|
|
|
|
|
|
22 |
EXTRACTED_DATA_DIR = os.path.join(DATA_DIR, "extracted")
|
submission.py
CHANGED
@@ -1,4 +1,10 @@
|
|
|
|
|
|
|
|
1 |
import matplotlib
|
|
|
|
|
|
|
2 |
matplotlib.use('Agg')
|
3 |
|
4 |
import os
|
@@ -38,15 +44,14 @@ from content import (
|
|
38 |
format_warning,
|
39 |
)
|
40 |
|
|
|
|
|
|
|
41 |
api = HfApi()
|
42 |
MAX_UPLOAD_BYTES = 100 * 1024**2
|
43 |
AGENTEVAL_MANIFEST_NAME = "agenteval.json"
|
44 |
os.makedirs(EXTRACTED_DATA_DIR, exist_ok=True)
|
45 |
|
46 |
-
# --- Global State for Viewers (simple caching) ---
|
47 |
-
CACHED_VIEWERS = {}
|
48 |
-
CACHED_TAG_MAPS = {}
|
49 |
-
|
50 |
# --- Submission Logic (largely unchanged from original, ensure LeaderboardSubmission and other deps are fine) ---
|
51 |
def try_load_dataset_submission(*args, **kwargs) -> DatasetDict: # Renamed to avoid conflict if LV has one
|
52 |
try:
|
@@ -90,11 +95,21 @@ def add_new_eval(
|
|
90 |
degree_of_control: str | None,
|
91 |
path_to_file: tempfile._TemporaryFileWrapper | None,
|
92 |
username: str,
|
93 |
-
|
94 |
profile: gr.OAuthProfile,
|
95 |
-
# We need global eval_results for checks; this might need rethinking if it's purely display driven now
|
96 |
-
# For now, let's assume we still load it for submission checks
|
97 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
# Load current eval_results for submission checks
|
99 |
# This is a bit redundant if display part reloads it, but submission needs its own consistent view
|
100 |
current_eval_results_for_submission = try_load_dataset_submission(
|
@@ -102,16 +117,13 @@ def add_new_eval(
|
|
102 |
CONFIG_NAME,
|
103 |
download_mode="force_redownload", # Or a less aggressive mode
|
104 |
verification_mode=VerificationMode.NO_CHECKS,
|
105 |
-
trust_remote_code=True,
|
106 |
)
|
107 |
-
if not agent_name:
|
108 |
-
return format_warning("Please provide an agent name.")
|
109 |
|
110 |
submission_time = datetime.now(timezone.utc)
|
111 |
if not username or username.strip() == "":
|
112 |
username = profile.username # Default to HF username
|
113 |
|
114 |
-
|
115 |
try:
|
116 |
user_data_resp = requests.get(f"https://huggingface.co/api/users/{profile.username}/overview")
|
117 |
user_data_resp.raise_for_status()
|
@@ -120,10 +132,10 @@ def add_new_eval(
|
|
120 |
if submission_time - created_at < timedelta(days=60):
|
121 |
return format_error("This account is not authorized to submit here (account too new).")
|
122 |
except Exception as e:
|
123 |
-
|
124 |
-
return
|
125 |
|
126 |
-
|
127 |
contact_infos = try_load_dataset_submission(
|
128 |
CONTACT_DATASET, CONFIG_NAME, download_mode="force_redownload",
|
129 |
verification_mode=VerificationMode.NO_CHECKS, trust_remote_code=True
|
@@ -133,14 +145,15 @@ def add_new_eval(
|
|
133 |
for row in contact_infos.get(val_or_test, []) if row["username_auth"] == profile.username
|
134 |
)
|
135 |
if user_submission_dates and (submission_time - user_submission_dates[-1] < timedelta(days=1)):
|
|
|
136 |
return format_error("You already submitted once in the last 24h for this split; please try again later.")
|
137 |
|
138 |
-
|
139 |
-
_, parsed_mail = parseaddr(
|
140 |
if "@" not in parsed_mail:
|
141 |
return format_warning("Please provide a valid email address.")
|
142 |
|
143 |
-
|
144 |
if val_or_test in current_eval_results_for_submission and len(current_eval_results_for_submission[val_or_test]) > 0:
|
145 |
existing_submissions = current_eval_results_for_submission[val_or_test].to_dict().get("submission", [])
|
146 |
for sub_item in existing_submissions:
|
@@ -148,63 +161,76 @@ def add_new_eval(
|
|
148 |
sub_item.get("username", "").lower() == username.lower()):
|
149 |
return format_warning("This agent name by this user has already been submitted to this split.")
|
150 |
|
151 |
-
if path_to_file is None:
|
152 |
-
return format_warning("Please attach a .tar.gz file.")
|
153 |
-
|
154 |
safe_username = sanitize_path_component(username)
|
155 |
safe_agent_name = sanitize_path_component(agent_name)
|
156 |
extracted_dir = os.path.join(EXTRACTED_DATA_DIR, f"{safe_username}_{safe_agent_name}")
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
return format_error(f"Error extracting file: {e}. Ensure it's a valid .tar.gz.")
|
178 |
-
else: print("mock extracted file", flush=True)
|
179 |
-
|
180 |
|
181 |
submission_name = f"{safe_username}_{safe_agent_name}_{submission_time.strftime('%Y-%m-%d_%H-%M-%S')}"
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
if val_or_test in contact_infos:
|
198 |
contact_infos[val_or_test] = contact_infos[val_or_test].add_item(contact_info)
|
199 |
else:
|
200 |
contact_infos[val_or_test] = Dataset.from_list([contact_info])
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
207 |
|
|
|
|
|
208 |
|
209 |
# 3. Process and score the submission
|
210 |
eval_result_obj = None # Define to avoid NameError
|
@@ -258,13 +284,6 @@ def add_new_eval(
|
|
258 |
return format_error(f"Failed to upload summary results to leaderboard: {e}")
|
259 |
else: print("mock uploaded results to lb", flush=True)
|
260 |
|
261 |
-
# Invalidate viewer cache for the split that was updated
|
262 |
-
if val_or_test in CACHED_VIEWERS:
|
263 |
-
del CACHED_VIEWERS[val_or_test]
|
264 |
-
if val_or_test in CACHED_TAG_MAPS:
|
265 |
-
del CACHED_TAG_MAPS[val_or_test]
|
266 |
-
|
267 |
-
|
268 |
return format_log(
|
269 |
f"Agent '{agent_name}' submitted successfully by '{username}' to '{val_or_test}' split. "
|
270 |
"Please refresh the leaderboard in a few moments. It may take some time for changes to propagate."
|
@@ -309,6 +328,8 @@ def build_page():
|
|
309 |
gr.HTML(heading_html)
|
310 |
with gr.Column():
|
311 |
pass # Keeps this row's content on the left side of the page.
|
|
|
|
|
312 |
with gr.Row():
|
313 |
with gr.Column():
|
314 |
level_of_test_radio = gr.Radio(["validation", "test"], value="validation", label="Split")
|
@@ -328,7 +349,6 @@ def build_page():
|
|
328 |
file_types=[".gz", ".tar.gz"]
|
329 |
)
|
330 |
with gr.Row():
|
331 |
-
gr.LoginButton()
|
332 |
submit_eval_button = gr.Button("Submit Evaluation")
|
333 |
submission_result = gr.Markdown()
|
334 |
|
|
|
1 |
+
import logging
|
2 |
+
import sys
|
3 |
+
|
4 |
import matplotlib
|
5 |
+
from agenteval.cli import SUBMISSION_METADATA_FILENAME
|
6 |
+
from agenteval.models import SubmissionMetadata
|
7 |
+
|
8 |
matplotlib.use('Agg')
|
9 |
|
10 |
import os
|
|
|
44 |
format_warning,
|
45 |
)
|
46 |
|
47 |
+
logger = logging.getLogger(__name__)
|
48 |
+
logger.setLevel(logging.DEBUG)
|
49 |
+
|
50 |
api = HfApi()
|
51 |
MAX_UPLOAD_BYTES = 100 * 1024**2
|
52 |
AGENTEVAL_MANIFEST_NAME = "agenteval.json"
|
53 |
os.makedirs(EXTRACTED_DATA_DIR, exist_ok=True)
|
54 |
|
|
|
|
|
|
|
|
|
55 |
# --- Submission Logic (largely unchanged from original, ensure LeaderboardSubmission and other deps are fine) ---
|
56 |
def try_load_dataset_submission(*args, **kwargs) -> DatasetDict: # Renamed to avoid conflict if LV has one
|
57 |
try:
|
|
|
95 |
degree_of_control: str | None,
|
96 |
path_to_file: tempfile._TemporaryFileWrapper | None,
|
97 |
username: str,
|
98 |
+
email: str,
|
99 |
profile: gr.OAuthProfile,
|
|
|
|
|
100 |
):
|
101 |
+
if not agent_name:
|
102 |
+
return format_warning("Please provide an agent name.")
|
103 |
+
|
104 |
+
def submission_error(msg: str) -> str:
|
105 |
+
logger.debug(f"agent {agent_name}: {msg}")
|
106 |
+
return format_error(msg)
|
107 |
+
|
108 |
+
if path_to_file is None:
|
109 |
+
return format_warning("Please attach a .tar.gz file.")
|
110 |
+
|
111 |
+
logger.info(f"agent {agent_name}: Checking submission")
|
112 |
+
|
113 |
# Load current eval_results for submission checks
|
114 |
# This is a bit redundant if display part reloads it, but submission needs its own consistent view
|
115 |
current_eval_results_for_submission = try_load_dataset_submission(
|
|
|
117 |
CONFIG_NAME,
|
118 |
download_mode="force_redownload", # Or a less aggressive mode
|
119 |
verification_mode=VerificationMode.NO_CHECKS,
|
|
|
120 |
)
|
|
|
|
|
121 |
|
122 |
submission_time = datetime.now(timezone.utc)
|
123 |
if not username or username.strip() == "":
|
124 |
username = profile.username # Default to HF username
|
125 |
|
126 |
+
logger.debug(f"agent {agent_name}: User account age check {profile.username}")
|
127 |
try:
|
128 |
user_data_resp = requests.get(f"https://huggingface.co/api/users/{profile.username}/overview")
|
129 |
user_data_resp.raise_for_status()
|
|
|
132 |
if submission_time - created_at < timedelta(days=60):
|
133 |
return format_error("This account is not authorized to submit here (account too new).")
|
134 |
except Exception as e:
|
135 |
+
logger.warning(f"Error checking user account age: {e}")
|
136 |
+
return submission_error("Could not verify account age. Please try again later.")
|
137 |
|
138 |
+
logger.debug(f"agent {agent_name}: Submission frequency check {profile.username}")
|
139 |
contact_infos = try_load_dataset_submission(
|
140 |
CONTACT_DATASET, CONFIG_NAME, download_mode="force_redownload",
|
141 |
verification_mode=VerificationMode.NO_CHECKS, trust_remote_code=True
|
|
|
145 |
for row in contact_infos.get(val_or_test, []) if row["username_auth"] == profile.username
|
146 |
)
|
147 |
if user_submission_dates and (submission_time - user_submission_dates[-1] < timedelta(days=1)):
|
148 |
+
logger.info(f"agent {agent_name}: Denied submission because user {username} submitted recently")
|
149 |
return format_error("You already submitted once in the last 24h for this split; please try again later.")
|
150 |
|
151 |
+
logger.debug(f"agent {agent_name}: Email validation {email}")
|
152 |
+
_, parsed_mail = parseaddr(email)
|
153 |
if "@" not in parsed_mail:
|
154 |
return format_warning("Please provide a valid email address.")
|
155 |
|
156 |
+
logger.debug(f"agent {agent_name}: Duplicate submission check")
|
157 |
if val_or_test in current_eval_results_for_submission and len(current_eval_results_for_submission[val_or_test]) > 0:
|
158 |
existing_submissions = current_eval_results_for_submission[val_or_test].to_dict().get("submission", [])
|
159 |
for sub_item in existing_submissions:
|
|
|
161 |
sub_item.get("username", "").lower() == username.lower()):
|
162 |
return format_warning("This agent name by this user has already been submitted to this split.")
|
163 |
|
|
|
|
|
|
|
164 |
safe_username = sanitize_path_component(username)
|
165 |
safe_agent_name = sanitize_path_component(agent_name)
|
166 |
extracted_dir = os.path.join(EXTRACTED_DATA_DIR, f"{safe_username}_{safe_agent_name}")
|
167 |
|
168 |
+
logger.debug(f"agent {agent_name}: File extraction to {extracted_dir}")
|
169 |
+
try:
|
170 |
+
if os.path.exists(extracted_dir): shutil.rmtree(extracted_dir)
|
171 |
+
os.makedirs(extracted_dir, exist_ok=True)
|
172 |
+
with tarfile.open(path_to_file.name, "r:gz") as tar:
|
173 |
+
members_extracted = 0
|
174 |
+
for member in tar.getmembers():
|
175 |
+
if not member.isreg(): continue
|
176 |
+
fname = os.path.basename(member.name)
|
177 |
+
if not fname or fname.startswith("."): continue
|
178 |
+
fobj = tar.extractfile(member)
|
179 |
+
if not fobj: continue
|
180 |
+
with open(os.path.join(extracted_dir, fname), "wb") as out:
|
181 |
+
out.write(fobj.read())
|
182 |
+
members_extracted +=1
|
183 |
+
if members_extracted == 0:
|
184 |
+
return submission_error("Submission tarball is empty or contains no valid files.")
|
185 |
+
except Exception as e:
|
186 |
+
return submission_error(f"Error extracting file: {e}. Ensure it's a valid .tar.gz.")
|
|
|
|
|
|
|
187 |
|
188 |
submission_name = f"{safe_username}_{safe_agent_name}_{submission_time.strftime('%Y-%m-%d_%H-%M-%S')}"
|
189 |
|
190 |
+
logger.debug(f"agent {agent_name}: Generate submission.json")
|
191 |
+
subm_meta = SubmissionMetadata(
|
192 |
+
agent_name=agent_name,
|
193 |
+
agent_description=agent_description,
|
194 |
+
agent_url=agent_url,
|
195 |
+
openness=openness,
|
196 |
+
tool_usage=degree_of_control,
|
197 |
+
username=username,
|
198 |
+
submit_time=submission_time,
|
199 |
+
)
|
200 |
+
with open(os.path.join(extracted_dir, SUBMISSION_METADATA_FILENAME), "w", encoding="utf-8") as fp:
|
201 |
+
fp.write(subm_meta.model_dump_json(indent=2))
|
202 |
+
|
203 |
+
logger.info(f"agent {agent_name}: Upload raw (unscored) submission files")
|
204 |
+
try:
|
205 |
+
checked_upload_folder(api, extracted_dir, SUBMISSION_DATASET, CONFIG_NAME, val_or_test, submission_name)
|
206 |
+
except ValueError as e:
|
207 |
+
return submission_error(str(e))
|
208 |
+
except Exception as e:
|
209 |
+
return submission_error(f"Failed to upload raw submission: {e}")
|
210 |
+
|
211 |
+
logger.info(f"agent {agent_name}: Save contact information")
|
212 |
+
contact_info = subm_meta.model_dump()
|
213 |
+
contact_info["submit_time"] = submission_time.isoformat()
|
214 |
+
contact_info["username_auth"] = profile.username
|
215 |
+
contact_info["email"] = email
|
216 |
+
|
217 |
+
logger.debug(f"agent {agent_name}: Contact info: {contact_info}")
|
218 |
if val_or_test in contact_infos:
|
219 |
contact_infos[val_or_test] = contact_infos[val_or_test].add_item(contact_info)
|
220 |
else:
|
221 |
contact_infos[val_or_test] = Dataset.from_list([contact_info])
|
222 |
|
223 |
+
try:
|
224 |
+
contact_infos.push_to_hub(CONTACT_DATASET, config_name=CONFIG_NAME)
|
225 |
+
except Exception as e:
|
226 |
+
return submission_error(f"Submission recorded, but contact info failed to save: {e}")
|
227 |
+
|
228 |
+
msg = f"Agent '{agent_name}' submitted successfully by '{username}' to '{val_or_test}' split. "
|
229 |
+
logger.info(f"agent {agent_name}: {msg}")
|
230 |
+
return format_log(msg)
|
231 |
|
232 |
+
def _deprecated_scoring_logic():
|
233 |
+
# No longer triggered on eval submission. Kept for quick reference for a little while (2025). TODO delete this.
|
234 |
|
235 |
# 3. Process and score the submission
|
236 |
eval_result_obj = None # Define to avoid NameError
|
|
|
284 |
return format_error(f"Failed to upload summary results to leaderboard: {e}")
|
285 |
else: print("mock uploaded results to lb", flush=True)
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
return format_log(
|
288 |
f"Agent '{agent_name}' submitted successfully by '{username}' to '{val_or_test}' split. "
|
289 |
"Please refresh the leaderboard in a few moments. It may take some time for changes to propagate."
|
|
|
328 |
gr.HTML(heading_html)
|
329 |
with gr.Column():
|
330 |
pass # Keeps this row's content on the left side of the page.
|
331 |
+
with gr.Row():
|
332 |
+
gr.LoginButton()
|
333 |
with gr.Row():
|
334 |
with gr.Column():
|
335 |
level_of_test_radio = gr.Radio(["validation", "test"], value="validation", label="Split")
|
|
|
349 |
file_types=[".gz", ".tar.gz"]
|
350 |
)
|
351 |
with gr.Row():
|
|
|
352 |
submit_eval_button = gr.Button("Submit Evaluation")
|
353 |
submission_result = gr.Markdown()
|
354 |
|