Spaces:
Paused
Paused
File size: 1,360 Bytes
b9ba589 ecb7a1f b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec b9ba589 edbbeec | 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 | import os
from pathlib import Path
HF_TOKEN = os.environ.get("HF_TOKEN", "")
DATASET_REPO = os.environ.get("OPENCLAW_DATASET_REPO", "")
PERSISTENT_FILES = {"topic_history.json", "fact_history.json", "token.pickle"}
def pull_state(base_dir):
if not DATASET_REPO or not HF_TOKEN:
print("Skipping hub pull: missing env vars"); return
from huggingface_hub import hf_hub_download
for fname in PERSISTENT_FILES:
try:
hf_hub_download(repo_id=DATASET_REPO, filename=fname,
repo_type="dataset", token=HF_TOKEN,
local_dir=str(base_dir), local_dir_use_symlinks=False)
print(f" pulled {fname}")
except Exception as e:
print(f" skipped {fname}: {e}")
def push_file(local_path):
if not DATASET_REPO or not HF_TOKEN: return
p = Path(local_path)
if p.name not in PERSISTENT_FILES or not p.exists(): return
try:
from huggingface_hub import HfApi
HfApi(token=HF_TOKEN).upload_file(
path_or_fileobj=str(p), path_in_repo=p.name,
repo_id=DATASET_REPO, repo_type="dataset", token=HF_TOKEN,
commit_message=f"auto: {p.name}")
except Exception as e:
print(f" push failed {p.name}: {e}")
def push_all_state(base_dir):
for fname in PERSISTENT_FILES:
push_file(Path(base_dir) / fname)
|