File size: 765 Bytes
b29fd2d
 
 
7d9cce6
b29fd2d
 
7d9cce6
b29fd2d
7d9cce6
b29fd2d
 
 
 
7d9cce6
 
b29fd2d
 
 
 
 
7d9cce6
 
b29fd2d
 
 
 
 
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
import os

import pandas as pd
from datasets import Dataset, load_dataset
from dotenv import load_dotenv
from huggingface_hub import login

load_dotenv()

HF_TOKEN = os.environ.get("HF_TOKEN", None)
RESULT_DATASET_ID = os.environ.get("RESULT_DATASET_ID", None)
if HF_TOKEN:
    login(token=HF_TOKEN)


def get_leaderboard_df() -> pd.DataFrame:
    # リーダーボードデータセットをHugging Face Hubからロード
    ds = load_dataset(RESULT_DATASET_ID, split="train")
    df = ds.to_pandas()
    return df


def save_leaderboard_df(df: pd.DataFrame):
    # DataFrameをDataset化
    ds = Dataset.from_pandas(df, preserve_index=False)
    # push_to_hubで更新
    ds.push_to_hub(RESULT_DATASET_ID, token=HF_TOKEN, commit_message="Update leaderboard")