File size: 868 Bytes
1c75c98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# tracklight_server/hf/push.py

from datasets import Dataset
from huggingface_hub import HfApi, HfFolder
from ..db import duckdb
import os

def push_to_hub(repo_id: str, hf_token: str):
    """
    Pushes the local DuckDB data to a Hugging Face Dataset repo.
    """
    # Authenticate with Hugging Face
    HfFolder.save_token(hf_token)

    # Get all data from DuckDB
    with duckdb.get_connection() as con:
        df = con.execute(f"SELECT * FROM {duckdb.TABLE_NAME}").fetchdf()

    if df.empty:
        print("No data to push.")
        return

    # Create a Hugging Face Dataset
    dataset = Dataset.from_pandas(df)

    # Push the dataset to the Hub
    try:
        dataset.push_to_hub(repo_id=repo_id, private=True)
        print(f"Successfully pushed data to {repo_id}")
    except Exception as e:
        print(f"Failed to push data to {repo_id}: {e}")