Spaces:
Runtime error
Runtime error
feat: derive dataset name from Space repo name to avoid conflicts
Browse filesWhen AUTO_CREATE_DATASET=true, the auto-derived dataset name now uses
the Space's repo name (from SPACE_ID) instead of a fixed "HuggingClaw".
E.g. Space "tao-shen/MyBot" → dataset "tao-shen/MyBot-data".
This prevents multiple duplicated Spaces from sharing the same dataset.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- README.md +1 -1
- scripts/sync_hf.py +6 -3
README.md
CHANGED
|
@@ -103,7 +103,7 @@ HuggingClaw syncs `~/.openclaw` (conversations, settings, credentials) to a priv
|
|
| 103 |
1. Set `AUTO_CREATE_DATASET` = `true` in your Space secrets
|
| 104 |
2. Set `HF_TOKEN` with write permission
|
| 105 |
3. (Optional) Set `OPENCLAW_DATASET_REPO` if you want a custom repo name
|
| 106 |
-
4. On first startup, HuggingClaw automatically creates a **private** Dataset repo. If `OPENCLAW_DATASET_REPO` is not set, it derives the name from your HF
|
| 107 |
|
| 108 |
> **Security note:** `AUTO_CREATE_DATASET` defaults to `false` — the system will not create repos on your behalf unless you explicitly opt in.
|
| 109 |
|
|
|
|
| 103 |
1. Set `AUTO_CREATE_DATASET` = `true` in your Space secrets
|
| 104 |
2. Set `HF_TOKEN` with write permission
|
| 105 |
3. (Optional) Set `OPENCLAW_DATASET_REPO` if you want a custom repo name
|
| 106 |
+
4. On first startup, HuggingClaw automatically creates a **private** Dataset repo. If `OPENCLAW_DATASET_REPO` is not set, it derives the name from your HF username + Space name: `your-username/SpaceName-data` (e.g. `tao-shen/HuggingClaw-data`). Each Space gets its own dataset, so duplicating a Space won't cause conflicts
|
| 107 |
|
| 108 |
> **Security note:** `AUTO_CREATE_DATASET` defaults to `false` — the system will not create repos on your behalf unless you explicitly opt in.
|
| 109 |
|
scripts/sync_hf.py
CHANGED
|
@@ -78,15 +78,18 @@ SPACE_ID = os.environ.get("SPACE_ID", "") # e.g. "tao-shen/HuggingClaw"
|
|
| 78 |
SYNC_INTERVAL = int(os.environ.get("SYNC_INTERVAL", "60"))
|
| 79 |
AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")
|
| 80 |
|
| 81 |
-
# Dataset repo: user-specified, or auto-derived from HF_TOKEN username
|
| 82 |
HF_REPO_ID = os.environ.get("OPENCLAW_DATASET_REPO", "")
|
| 83 |
if not HF_REPO_ID and AUTO_CREATE_DATASET and HF_TOKEN:
|
| 84 |
try:
|
| 85 |
_api = HfApi(token=HF_TOKEN)
|
| 86 |
_username = _api.whoami()["name"]
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
print(f"[SYNC] OPENCLAW_DATASET_REPO not set — auto-derived: {HF_REPO_ID}")
|
| 89 |
-
del _api, _username
|
| 90 |
except Exception as e:
|
| 91 |
print(f"[SYNC] WARNING: Could not derive username from HF_TOKEN: {e}")
|
| 92 |
HF_REPO_ID = ""
|
|
|
|
| 78 |
SYNC_INTERVAL = int(os.environ.get("SYNC_INTERVAL", "60"))
|
| 79 |
AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")
|
| 80 |
|
| 81 |
+
# Dataset repo: user-specified, or auto-derived from Space ID / HF_TOKEN username
|
| 82 |
HF_REPO_ID = os.environ.get("OPENCLAW_DATASET_REPO", "")
|
| 83 |
if not HF_REPO_ID and AUTO_CREATE_DATASET and HF_TOKEN:
|
| 84 |
try:
|
| 85 |
_api = HfApi(token=HF_TOKEN)
|
| 86 |
_username = _api.whoami()["name"]
|
| 87 |
+
# Use Space repo name if available (e.g. "tao-shen/HuggingClaw" → "HuggingClaw")
|
| 88 |
+
# so each Space gets its own dataset (e.g. "tao-shen/HuggingClaw-data")
|
| 89 |
+
_space_name = SPACE_ID.split("/")[-1] if SPACE_ID else "HuggingClaw"
|
| 90 |
+
HF_REPO_ID = f"{_username}/{_space_name}-data"
|
| 91 |
print(f"[SYNC] OPENCLAW_DATASET_REPO not set — auto-derived: {HF_REPO_ID}")
|
| 92 |
+
del _api, _username, _space_name
|
| 93 |
except Exception as e:
|
| 94 |
print(f"[SYNC] WARNING: Could not derive username from HF_TOKEN: {e}")
|
| 95 |
HF_REPO_ID = ""
|