Spaces:
Running
Running
Shiyu Zhao
commited on
Commit
·
438e395
1
Parent(s):
aa3c137
Update space
Browse files
app.py
CHANGED
@@ -212,6 +212,33 @@ def sanitize_name(name):
|
|
212 |
"""Sanitize name for file system use"""
|
213 |
return re.sub(r'[^a-zA-Z0-9]', '_', name)
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
def scan_submissions_directory():
|
216 |
"""
|
217 |
Scans the submissions directory and updates the leaderboard tables with all submitted results.
|
@@ -268,16 +295,9 @@ def scan_submissions_directory():
|
|
268 |
continue
|
269 |
|
270 |
# Read latest.json
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
repo_type="space",
|
275 |
-
filename=latest_file,
|
276 |
-
text=True
|
277 |
-
)
|
278 |
-
latest_info = json.loads(latest_content)
|
279 |
-
except Exception as e:
|
280 |
-
print(f"Error reading latest.json for {folder_name}: {str(e)}")
|
281 |
continue
|
282 |
|
283 |
# Check submission status
|
@@ -300,16 +320,9 @@ def scan_submissions_directory():
|
|
300 |
continue
|
301 |
|
302 |
# Read metadata file
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
repo_type="space",
|
307 |
-
filename=metadata_file,
|
308 |
-
text=True
|
309 |
-
)
|
310 |
-
submission_data = json.loads(metadata_content)
|
311 |
-
except Exception as e:
|
312 |
-
print(f"Error reading metadata for {folder_name}: {str(e)}")
|
313 |
continue
|
314 |
|
315 |
# Map the split name if necessary
|
@@ -349,6 +362,12 @@ def scan_submissions_directory():
|
|
349 |
except Exception as e:
|
350 |
print(f"Error processing folder {folder_name}: {str(e)}")
|
351 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
# Print summary
|
354 |
print("\nLeaderboard initialization summary:")
|
@@ -383,19 +402,19 @@ def initialize_leaderboard():
|
|
383 |
except Exception as e:
|
384 |
print(f"Error initializing leaderboard: {str(e)}")
|
385 |
|
386 |
-
# Utility function to get file content
|
387 |
def get_file_content(file_path):
|
388 |
"""
|
389 |
Helper function to safely read file content from HuggingFace repository
|
390 |
"""
|
391 |
try:
|
392 |
api = HfApi()
|
393 |
-
|
394 |
repo_id=REPO_ID,
|
395 |
-
|
396 |
-
|
397 |
)
|
398 |
-
|
|
|
399 |
except Exception as e:
|
400 |
print(f"Error reading file {file_path}: {str(e)}")
|
401 |
return None
|
|
|
212 |
"""Sanitize name for file system use"""
|
213 |
return re.sub(r'[^a-zA-Z0-9]', '_', name)
|
214 |
|
215 |
+
def read_json_from_hub(api: HfApi, repo_id: str, file_path: str) -> dict:
|
216 |
+
"""
|
217 |
+
Read and parse JSON file from HuggingFace Hub.
|
218 |
+
|
219 |
+
Args:
|
220 |
+
api: HuggingFace API instance
|
221 |
+
repo_id: Repository ID
|
222 |
+
file_path: Path to file in repository
|
223 |
+
|
224 |
+
Returns:
|
225 |
+
dict: Parsed JSON content
|
226 |
+
"""
|
227 |
+
try:
|
228 |
+
# Download the file content as bytes
|
229 |
+
content = api.hf_hub_download(
|
230 |
+
repo_id=repo_id,
|
231 |
+
filename=file_path,
|
232 |
+
repo_type="space"
|
233 |
+
)
|
234 |
+
|
235 |
+
# Read and parse JSON
|
236 |
+
with open(content, 'r') as f:
|
237 |
+
return json.load(f)
|
238 |
+
except Exception as e:
|
239 |
+
print(f"Error reading JSON file {file_path}: {str(e)}")
|
240 |
+
return None
|
241 |
+
|
242 |
def scan_submissions_directory():
|
243 |
"""
|
244 |
Scans the submissions directory and updates the leaderboard tables with all submitted results.
|
|
|
295 |
continue
|
296 |
|
297 |
# Read latest.json
|
298 |
+
latest_info = read_json_from_hub(api, REPO_ID, latest_file)
|
299 |
+
if not latest_info:
|
300 |
+
print(f"Failed to read latest.json for {folder_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
continue
|
302 |
|
303 |
# Check submission status
|
|
|
320 |
continue
|
321 |
|
322 |
# Read metadata file
|
323 |
+
submission_data = read_json_from_hub(api, REPO_ID, metadata_file)
|
324 |
+
if not submission_data:
|
325 |
+
print(f"Failed to read metadata for {folder_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
continue
|
327 |
|
328 |
# Map the split name if necessary
|
|
|
362 |
except Exception as e:
|
363 |
print(f"Error processing folder {folder_name}: {str(e)}")
|
364 |
continue
|
365 |
+
|
366 |
+
# Sort each DataFrame by MRR score
|
367 |
+
for df in [df_synthesized_full, df_synthesized_10, df_human_generated]:
|
368 |
+
mrr_cols = [col for col in df.columns if col.endswith('_MRR')]
|
369 |
+
if mrr_cols:
|
370 |
+
df.sort_values(by=mrr_cols[0], ascending=False, inplace=True)
|
371 |
|
372 |
# Print summary
|
373 |
print("\nLeaderboard initialization summary:")
|
|
|
402 |
except Exception as e:
|
403 |
print(f"Error initializing leaderboard: {str(e)}")
|
404 |
|
|
|
405 |
def get_file_content(file_path):
|
406 |
"""
|
407 |
Helper function to safely read file content from HuggingFace repository
|
408 |
"""
|
409 |
try:
|
410 |
api = HfApi()
|
411 |
+
content_path = api.hf_hub_download(
|
412 |
repo_id=REPO_ID,
|
413 |
+
filename=file_path,
|
414 |
+
repo_type="space"
|
415 |
)
|
416 |
+
with open(content_path, 'r') as f:
|
417 |
+
return f.read()
|
418 |
except Exception as e:
|
419 |
print(f"Error reading file {file_path}: {str(e)}")
|
420 |
return None
|