tao-shen Claude Opus 4.6 commited on
Commit
8f44b56
·
1 Parent(s): 907c2cc

fix: auto-derive dataset name from SPACE_ID, not HF_TOKEN username

Browse files

Always use {SPACE_ID}-data (e.g. tao-shen/HuggingClaw-data) so
duplicated Spaces automatically get their own dataset repo.
No longer requires AUTO_CREATE_DATASET for name derivation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/sync_hf.py +12 -8
scripts/sync_hf.py CHANGED
@@ -80,18 +80,22 @@ SPACE_ID = os.environ.get("SPACE_ID", "") # e.g. "tao-shen/HuggingClaw"
80
  SYNC_INTERVAL = int(os.environ.get("SYNC_INTERVAL", "60"))
81
  AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")
82
 
83
- # Dataset repo: user-specified, or auto-derived from Space ID / HF_TOKEN username
 
 
84
  HF_REPO_ID = os.environ.get("OPENCLAW_DATASET_REPO", "")
85
- if not HF_REPO_ID and AUTO_CREATE_DATASET and HF_TOKEN:
 
 
 
 
 
86
  try:
87
  _api = HfApi(token=HF_TOKEN)
88
  _username = _api.whoami()["name"]
89
- # Use Space repo name if available (e.g. "tao-shen/HuggingClaw" → "HuggingClaw")
90
- # so each Space gets its own dataset (e.g. "tao-shen/HuggingClaw-data")
91
- _space_name = SPACE_ID.split("/")[-1] if SPACE_ID else "HuggingClaw"
92
- HF_REPO_ID = f"{_username}/{_space_name}-data"
93
- print(f"[SYNC] OPENCLAW_DATASET_REPO not set — auto-derived: {HF_REPO_ID}")
94
- del _api, _username, _space_name
95
  except Exception as e:
96
  print(f"[SYNC] WARNING: Could not derive username from HF_TOKEN: {e}")
97
  HF_REPO_ID = ""
 
80
  SYNC_INTERVAL = int(os.environ.get("SYNC_INTERVAL", "60"))
81
  AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")
82
 
83
+ # Dataset repo: always auto-derive from SPACE_ID when not explicitly set.
84
+ # Format: {username}/{SpaceName}-data (e.g. "tao-shen/HuggingClaw-data")
85
+ # This ensures each duplicated Space gets its own dataset automatically.
86
  HF_REPO_ID = os.environ.get("OPENCLAW_DATASET_REPO", "")
87
+ if not HF_REPO_ID and SPACE_ID:
88
+ # SPACE_ID = "username/SpaceName" → derive "username/SpaceName-data"
89
+ HF_REPO_ID = f"{SPACE_ID}-data"
90
+ print(f"[SYNC] OPENCLAW_DATASET_REPO not set — auto-derived from SPACE_ID: {HF_REPO_ID}")
91
+ elif not HF_REPO_ID and HF_TOKEN:
92
+ # Fallback: no SPACE_ID (local Docker), derive from HF_TOKEN username
93
  try:
94
  _api = HfApi(token=HF_TOKEN)
95
  _username = _api.whoami()["name"]
96
+ HF_REPO_ID = f"{_username}/HuggingClaw-data"
97
+ print(f"[SYNC] OPENCLAW_DATASET_REPO not set auto-derived from HF_TOKEN: {HF_REPO_ID}")
98
+ del _api, _username
 
 
 
99
  except Exception as e:
100
  print(f"[SYNC] WARNING: Could not derive username from HF_TOKEN: {e}")
101
  HF_REPO_ID = ""