| #!/usr/bin/env python3 | |
| """ | |
| 推送数据集到 HuggingFace | |
| 用法: | |
| python push_to_hf.py --repo your-username/sre-challenge-dataset | |
| """ | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| def push_to_huggingface(repo_id): | |
| """推送到 HuggingFace""" | |
| try: | |
| from huggingface_hub import HfApi | |
| except ImportError: | |
| print("请先安装: pip install huggingface_hub") | |
| return | |
| import subprocess | |
| dataset_dir = Path(__file__).parent | |
| # 先生成 parquet(HF viewer 不能自动转换深度嵌套 JSON) | |
| print("正在生成 parquet...") | |
| subprocess.run([sys.executable, str(dataset_dir / "gen_parquet.py")], check=True) | |
| api = HfApi() | |
| print(f"正在推送到 {repo_id}...") | |
| # 上传所有文件 | |
| api.upload_folder( | |
| folder_path=str(dataset_dir), | |
| repo_id=repo_id, | |
| repo_type="dataset", | |
| ignore_patterns=["*.pyc", "__pycache__", ".git", "*.sh"] | |
| ) | |
| print(f"✅ 推送成功: https://huggingface.co/datasets/{repo_id}") | |
| def main(): | |
| parser = argparse.ArgumentParser(description='推送到 HuggingFace') | |
| parser.add_argument('--repo', required=True, help='仓库名,格式: username/dataset-name') | |
| args = parser.parse_args() | |
| push_to_huggingface(args.repo) | |
| if __name__ == '__main__': | |
| main() | |