|
|
""" |
|
|
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(): |
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
print("Creating HuggingFace Dataset...") |
|
|
dataset = Dataset.from_list(data) |
|
|
|
|
|
|
|
|
dataset_dict = DatasetDict({ |
|
|
"train": dataset |
|
|
}) |
|
|
|
|
|
print(f"Dataset: {dataset_dict}") |
|
|
print(f"Features: {dataset.features}") |
|
|
|
|
|
|
|
|
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" |
|
|
) |
|
|
|
|
|
|
|
|
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() |
|
|
|