Datasets:
File size: 2,027 Bytes
a4f049f | 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 74 75 76 77 78 79 80 81 | """
Upload UD dataset to HuggingFace Hub.
Dataset: undertheseanlp/UDD-v0.1
Usage:
export $(cat .env | xargs) && python upload_to_hf.py
"""
import json
import os
from os.path import expanduser, join
from datasets import Dataset, DatasetDict
from huggingface_hub import HfApi, login
def load_jsonl(filepath):
"""Load JSONL file."""
data = []
with open(filepath, "r", encoding="utf-8") as f:
for line in f:
data.append(json.loads(line))
return data
def main():
# Login with token from environment
token = os.environ.get("HF_TOKEN")
if token:
print("Logging in with HF_TOKEN...")
login(token=token)
else:
print("Warning: HF_TOKEN not set. Using cached credentials.")
source_folder = expanduser("~/Downloads/UD_Vietnamese-UUD-v0.1")
jsonl_file = join(source_folder, "train.jsonl")
readme_file = join(source_folder, "README.md")
print("Loading data...")
data = load_jsonl(jsonl_file)
print(f"Loaded {len(data)} sentences")
# Create HuggingFace Dataset
print("Creating HuggingFace Dataset...")
dataset = Dataset.from_list(data)
# Create DatasetDict with train split
dataset_dict = DatasetDict({
"train": dataset
})
print(f"Dataset: {dataset_dict}")
print(f"Features: {dataset.features}")
# Push to HuggingFace Hub
repo_id = "undertheseanlp/UDD-v0.1"
print(f"\nPushing to HuggingFace Hub: {repo_id}")
dataset_dict.push_to_hub(
repo_id,
private=False,
commit_message="Update: 1000 sentences from Vietnamese Legal Corpus"
)
# Upload README.md
print("Uploading README.md...")
api = HfApi()
api.upload_file(
path_or_fileobj=readme_file,
path_in_repo="README.md",
repo_id=repo_id,
repo_type="dataset",
commit_message="Add README with dataset card"
)
print(f"\nDone! Dataset available at: https://huggingface.co/datasets/{repo_id}")
if __name__ == "__main__":
main()
|