File size: 1,919 Bytes
cd1b5e8
 
 
 
 
 
 
22161b0
 
cd1b5e8
 
 
 
 
 
22161b0
 
 
 
 
 
 
 
 
 
 
 
 
cd1b5e8
 
 
22161b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# !/usr/bin/env python3
# /// script
# dependencies = [
#   "python-dotenv",
#   "huggingface-hub",
# ]
# ///
"""
Upload the eval-results/leaderboard folder to y-playground/results on Hugging Face Hub.

Usage:

```bash
uv run scripts/upload_dataset.py
```
"""

import os
from pathlib import Path

from dotenv import load_dotenv
from huggingface_hub import HfApi

# Load environment variables
load_dotenv()

# Configuration
LOCAL_FOLDER = Path("eval-results/leaderboard")
HF_OWNER = os.getenv("HF_OWNER", "lmms-lab-si")
HF_RESULTS_REPO_NAME = os.getenv("HF_RESULTS_REPO_NAME", "EASI-Leaderboard-Results")
REPO_ID = f"{HF_OWNER}/{HF_RESULTS_REPO_NAME}"
REPO_TYPE = "dataset"  # or "model" or "space"


def main():
    # Get Hugging Face token from environment
    hf_token = os.getenv("HF_TOKEN")
    if not hf_token:
        raise ValueError(
            "HF_TOKEN environment variable is not set. "
            "Please set it in your .env file or export it as an environment variable."
        )

    # Validate local folder exists
    if not LOCAL_FOLDER.exists():
        raise FileNotFoundError(f"Local folder not found: {LOCAL_FOLDER}")

    if not LOCAL_FOLDER.is_dir():
        raise ValueError(f"Path is not a directory: {LOCAL_FOLDER}")

    # Initialize Hugging Face API
    api = HfApi(token=hf_token)

    print(f"Uploading folder: {LOCAL_FOLDER}")
    print(f"Destination: {REPO_ID}/leaderboard (type: {REPO_TYPE})")
    print()

    # Upload folder to leaderboard directory in the repo
    api.upload_folder(
        folder_path=str(LOCAL_FOLDER),
        repo_id=REPO_ID,
        repo_type=REPO_TYPE,
        path_in_repo="leaderboard",
        commit_message=f"Upload leaderboard results from {LOCAL_FOLDER}",
    )

    print(f"✓ Successfully uploaded {LOCAL_FOLDER} to {REPO_ID}/leaderboard")
    print(f"  View at: https://huggingface.co/datasets/{REPO_ID}")


if __name__ == "__main__":
    main()