yangzhitao commited on
Commit
22161b0
·
1 Parent(s): 852f90d

feat: add script to upload leaderboard results to Hugging Face Hub

Browse files
Files changed (1) hide show
  1. scripts/upload_dataset.py +58 -0
scripts/upload_dataset.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Upload the eval-results/leaderboard folder to y-playground/results on Hugging Face Hub.
4
+ """
5
+
6
+ import os
7
+ from pathlib import Path
8
+
9
+ from dotenv import load_dotenv
10
+ from huggingface_hub import HfApi
11
+
12
+ # Load environment variables
13
+ load_dotenv()
14
+
15
+ # Configuration
16
+ LOCAL_FOLDER = Path("eval-results/leaderboard")
17
+ REPO_ID = "y-playground/results"
18
+ REPO_TYPE = "dataset" # or "model" or "space"
19
+
20
+
21
+ def main():
22
+ # Get Hugging Face token from environment
23
+ hf_token = os.getenv("HF_TOKEN")
24
+ if not hf_token:
25
+ raise ValueError(
26
+ "HF_TOKEN environment variable is not set. "
27
+ "Please set it in your .env file or export it as an environment variable."
28
+ )
29
+
30
+ # Validate local folder exists
31
+ if not LOCAL_FOLDER.exists():
32
+ raise FileNotFoundError(f"Local folder not found: {LOCAL_FOLDER}")
33
+
34
+ if not LOCAL_FOLDER.is_dir():
35
+ raise ValueError(f"Path is not a directory: {LOCAL_FOLDER}")
36
+
37
+ # Initialize Hugging Face API
38
+ api = HfApi(token=hf_token)
39
+
40
+ print(f"Uploading folder: {LOCAL_FOLDER}")
41
+ print(f"Destination: {REPO_ID}/leaderboard (type: {REPO_TYPE})")
42
+ print()
43
+
44
+ # Upload folder to leaderboard directory in the repo
45
+ api.upload_folder(
46
+ folder_path=str(LOCAL_FOLDER),
47
+ repo_id=REPO_ID,
48
+ repo_type=REPO_TYPE,
49
+ path_in_repo="leaderboard",
50
+ commit_message=f"Upload leaderboard results from {LOCAL_FOLDER}",
51
+ )
52
+
53
+ print(f"✓ Successfully uploaded {LOCAL_FOLDER} to {REPO_ID}/leaderboard")
54
+ print(f" View at: https://huggingface.co/datasets/{REPO_ID}")
55
+
56
+
57
+ if __name__ == "__main__":
58
+ main()