Kevin Xie
Upload main processing scripts for this repo
577fb61
from helpers.excel_processor import ExcelProcessor
from helpers.reorganize_indices import reorganize_indices
import config
import json
def update_ranks():
"""Update ranks for all leaderboards based on average performance."""
for leaderboard_path in config.ALL_LEADERBOARD_PATHS:
with open(leaderboard_path, 'r') as f:
data = json.load(f)
avg_performance_dict = data['Average Performance']
# Tuples of the original index (key) and the performance score
tps = []
for idx, value in avg_performance_dict.items():
tps.append((idx, value))
# Sort the tuples by the performance score in descending order
tps.sort(key=lambda x: float(x[1]), reverse=True)
for rank, tp in enumerate(tps):
original_idx = tp[0]
data['T'][original_idx] = rank + 1 # Rank starts from 1
with open(leaderboard_path, 'w') as f:
json.dump(data, f, indent=4, ensure_ascii=False)
def create_leaderboards(
excel_path: str,
output_path: str,
sheet_names_list: list,
invalid_models=None
):
"""
Function that updates a singular leaderboard (JSON).
Args:
excel_path: Path to the excel file
output_path: Path to the output file
sheet_names_list: List of sheet names to create leaderboards from
invalid_models: List of models to exclude from the leaderboards
"""
excel_processor = ExcelProcessor(excel_path, invalid_models)
# Create leaderboards (JSON)
excel_processor.create_leaderboards(sheet_names_list=sheet_names_list, output_path=output_path)
# Reorganize the leaderboard inices
reorganize_indices(output_path)
# Create task information JSON
excel_processor.create_task_information(config.TASK_INFO_PATH)
def create_all_leaderboards(
excel_path: str,
leaderboard_configs: list,
invalid_models=None
):
"""
Loops through each leaderboard's configs to update all leaderboards
(calls the above function multiple times)
Args:
excel_path: Path to the excel file
leaderboard_configs: List of leaderboard configs
invalid_models: List of models to exclude from the leaderboards
"""
for config in leaderboard_configs:
print(f"Creating {config['name']} leaderboard...")
create_leaderboards(
excel_path,
config['output_path'],
config['sheet_names'],
invalid_models=invalid_models
)
print(f"{config['name']} leaderboard created successfully!")
if __name__ == "__main__":
print("=" * 80)
print("πŸš€ BRIDGE Leaderboard Generation Script")
print("=" * 80)
print()
# # ######################################################### #
# # ######################################################### #
# HOW TO UPDATE LEADERBOARDS
# 1. Download the new excel sheet and/or update the path in scripts/config.py
# 2. Specify which models to exclude from the leaderboard in scripts/config.py (INVALID_MODELS)
# 3. Run: python scripts/main.py (from project root)
# 4. Done! All leaderboards and task information have been updated.
# 5. Push to GitHub and deploy to Hugging Face Spaces.
# # ######################################################### #
# # ######################################################### #
# Validate that the Excel file exists
from pathlib import Path
excel_path_obj = Path(config.EXCEL_PATH)
if not excel_path_obj.exists():
print("❌ ERROR: Excel file not found!")
print(f" Expected location: {excel_path_obj.absolute()}")
print()
print("πŸ“ To fix this:")
print(" 1. Place your Excel file in the project root, OR")
print(" 2. Update EXCEL_PATH in scripts/config.py to point to your Excel file")
print()
print(f" Current working directory: {Path.cwd()}")
exit(1)
print(f"πŸ“Š Using Excel file: {excel_path_obj.absolute()}")
print(f"🎯 Invalid models to exclude: {len(config.INVALID_MODELS)} model(s)")
print()
print("-" * 80)
# All configuration is now in scripts/config.py
# This makes it easy to share the code and update paths in one place
try:
# Create all leaderboards with a single function call
create_all_leaderboards(
config.EXCEL_PATH,
config.LEADERBOARD_CONFIGS,
config.INVALID_MODELS
)
print()
print("-" * 80)
print("βœ… Leaderboards created successfully!")
print()
# Update the ranks of the leaderboards (leftmost column)
print("πŸ”„ Updating ranks...")
update_ranks()
print()
print("=" * 80)
print("βœ… All operations completed successfully!")
print("=" * 80)
print()
print("πŸ“ Updated files:")
print(" - leaderboards/Zero-Shot_leaderboard.json")
print(" - leaderboards/Few-Shot_leaderboard.json")
print(" - leaderboards/CoT_leaderboard.json")
print(" - task_information.json")
print()
print("πŸš€ Next steps:")
print(" 1. Review the updated leaderboard files")
print(" 2. Test the web app: python app.py")
print(" 3. Push to GitHub and deploy to Hugging Face Spaces")
print()
except Exception as e:
print()
print("=" * 80)
print("❌ ERROR: An error occurred during leaderboard generation")
print("=" * 80)
print(f"Error message: {str(e)}")
print()
import traceback
traceback.print_exc()
print()
print("πŸ’‘ Common issues:")
print(" - Verify Excel file has required sheets (Models, B-CLF, B-EXT, B-GEN, etc.)")
print(" - Check that model names in INVALID_MODELS match exactly")
print(" - Ensure pandas and openpyxl are installed: pip install -r scripts/requirements.txt")
exit(1)