|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Batch import models to leaderboard |
| 4 | +Usage: python batch_import_models.py models_data.json |
| 5 | +""" |
| 6 | + |
| 7 | +import json |
| 8 | +import sys |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | +# Add the leaderboard directory to Python path |
| 12 | +sys.path.insert(0, str(Path(__file__).parent)) |
| 13 | + |
| 14 | +from manage_leaderboard import LeaderboardManager |
| 15 | + |
| 16 | + |
| 17 | +def batch_import(models_file: str): |
| 18 | + """Batch import models from JSON file""" |
| 19 | + |
| 20 | + with open(models_file, "r", encoding="utf-8") as f: |
| 21 | + models_data = json.load(f) |
| 22 | + |
| 23 | + manager = LeaderboardManager() |
| 24 | + |
| 25 | + # Clear existing models if specified |
| 26 | + if models_data.get("clear_existing", False): |
| 27 | + print("🗑️ Clearing existing models...") |
| 28 | + manager.data["models"] = [] |
| 29 | + |
| 30 | + # Import models |
| 31 | + imported_count = 0 |
| 32 | + for model_data in models_data["models"]: |
| 33 | + model_info = model_data["model_info"] |
| 34 | + subcategory_scores = model_data["scores"] |
| 35 | + |
| 36 | + success = manager.add_model(model_info, subcategory_scores) |
| 37 | + if success: |
| 38 | + imported_count += 1 |
| 39 | + |
| 40 | + print( |
| 41 | + f"\n✅ Successfully imported {imported_count}/{len(models_data['models'])} models" |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + if len(sys.argv) != 2: |
| 47 | + print("Usage: python batch_import_models.py models_data.json") |
| 48 | + sys.exit(1) |
| 49 | + |
| 50 | + batch_import(sys.argv[1]) |
0 commit comments