#!/usr/bin/env python3 """ Setup script to ensure all necessary files and directories are created before running the application. """ import os import json import sys def setup(): """Create necessary directories and files if they don't exist.""" print("Setting up leaderboard application...") # Create submissions directory if not os.path.exists("submissions"): print("Creating submissions directory...") os.makedirs("submissions", exist_ok=True) # Create models.json if it doesn't exist or is empty if not os.path.exists("models.json") or os.path.getsize("models.json") == 0: print("Creating models.json configuration file...") config = { "title": "TRAIL Performance Leaderboard", "description": "This leaderboard tracks and compares model performance across multiple metrics. Submit your model results to see how they stack up!", "metrics": ["Cat. F1", "Loc. Acc", "Joint F1"], "main_metric": "Cat. F1" } with open("models.json", "w") as f: json.dump(config, f, indent=2) else: # Validate JSON format try: with open("models.json", "r") as f: json.load(f) print("models.json exists and is valid.") except json.JSONDecodeError: print("models.json exists but has invalid JSON. Creating new file...") config = { "title": "Model Performance Leaderboard", "description": "This leaderboard tracks and compares model performance across multiple metrics. Submit your model results to see how they stack up!", "metrics": ["Cat. F1", "Loc. Acc", "Joint F1"], "main_metric": "Cat. F1" } with open("models.json", "w") as f: json.dump(config, f, indent=2) print("Setup complete.") if __name__ == "__main__": setup()