#!/usr/bin/env python3 """ CORPUSLIB Topics Dataset - HuggingFace Upload Script Uploads the CORPUSLIB topic catalog to HuggingFace Hub """ import os import json from huggingface_hub import HfApi, login, create_repo, upload_folder # Configuration HF_USERNAME = "ctaxnagomi" DATASET_NAME = "corpuslib-topics" DATASET_DIR = os.path.dirname(os.path.abspath(__file__)) def main(): print("=" * 60) print("CORPUSLIB Topics Dataset - HuggingFace Upload") print("=" * 60) print() # Load token token_path = os.path.expanduser("~/.cache/huggingface/token") if os.path.exists(token_path): with open(token_path, 'r') as f: token = f.read().strip() print(f"[OK] Token loaded from {token_path}") else: print("[ERROR] Token not found. Please run: huggingface-cli login") return # Initialize API api = HfApi() # Login print("Logging in to HuggingFace...") login(token=token) print("[OK] Logged in") # Create repository repo_id = f"{HF_USERNAME}/{DATASET_NAME}" print(f"Creating repository: {repo_id}") try: create_repo( repo_id=repo_id, repo_type="dataset", token=token, exist_ok=True ) print(f"[OK] Repository created: https://huggingface.co/datasets/{repo_id}") except Exception as e: print(f"Repository may already exist: {e}") # Upload folder print(f"Uploading dataset from {DATASET_DIR}...") try: upload_folder( repo_id=repo_id, folder_path=DATASET_DIR, repo_type="dataset", token=token ) print(f"[OK] Dataset uploaded successfully!") print(f" URL: https://huggingface.co/datasets/{repo_id}") except Exception as e: print(f"[ERROR] Upload failed: {e}") return print() print("=" * 60) print("Upload complete!") print("=" * 60) if __name__ == "__main__": main()