File size: 1,312 Bytes
924a755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Mirror run traces to a HF Dataset repo (plan §15.4) when HF_TOKEN is present.
Falls back silently to local-only traces/ otherwise.

Run:  python -m scripts.push_traces [--repo Shanmuk4622/autosource-traces]
"""
from __future__ import annotations

import argparse
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from core.config import api_key, settings, traces_dir  # noqa: E402


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--repo", default="Shanmuk4622/autosource-traces")
    args = parser.parse_args()

    token = api_key("HF_TOKEN")
    if not token or not settings()["features"]["hf_trace_mirror"]:
        print("[push_traces] HF_TOKEN missing or mirror disabled — local traces only.")
        return

    from huggingface_hub import HfApi
    api = HfApi(token=token)
    api.create_repo(args.repo, repo_type="dataset", exist_ok=True, private=False)
    api.upload_folder(
        folder_path=str(traces_dir()),
        repo_id=args.repo,
        repo_type="dataset",
        ignore_patterns=[".llm_cache.json", "*.decision.json"],
        commit_message="mirror local run traces",
    )
    print(f"[push_traces] mirrored traces/ -> hf.co/datasets/{args.repo}")


if __name__ == "__main__":
    main()