Spaces:
Sleeping
Sleeping
File size: 6,147 Bytes
577fb61 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 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)
|