File size: 751 Bytes
928f123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pandas as pd
import datasets
from datasets import Dataset
from huggingface_hub import create_repo
from huggingface_hub.utils import HfHubHTTPError

def push_to_hf_hub(
	qnas, repo_id, token, append=True
):
    print(1)
    exist = False
    df = pd.DataFrame([qnas])
    ds = Dataset.from_pandas(df)
    ds = ds.cast_column("target_date", datasets.features.Value("timestamp[s]"))

    print(2)
    try:
        create_repo(repo_id, repo_type="dataset", token=token)
    except HfHubHTTPError as e:
        exist = True
    
    if exist and append:
        print(3)
        existing_ds = datasets.load_dataset(repo_id)
        ds = datasets.concatenate_datasets([existing_ds['train'], ds])

    print(4)
    ds.push_to_hub(repo_id, token=token)