specimba commited on
Commit
b926133
·
verified ·
1 Parent(s): 4120dcd

Add hf_bucket_bridge.py: sync VAP to persistent bucket

Browse files
Files changed (1) hide show
  1. hf_bucket_bridge.py +27 -0
hf_bucket_bridge.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """HF Bucket persistence bridge for NEXUS OS.
2
+
3
+ Usage inside Space:
4
+ from hf_bucket_bridge import save_vap, load_vap
5
+ save_vap({"event": "purple_scan", "score": 0.97})
6
+
7
+ CLI equivalent:
8
+ hf buckets cp ./vap.json hf://buckets/specimba/nexus-vap-bucket/vap/run-001.json
9
+ """
10
+ import os, json, subprocess, tempfile
11
+
12
+ BUCKET = "hf://buckets/specimba/nexus-vap-bucket"
13
+
14
+ def save_vap(data: dict, filename: str = None):
15
+ ts = data.get("timestamp", "")
16
+ fn = filename or f"vap/{ts.replace(':', '-')}.json"
17
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
18
+ json.dump(data, f)
19
+ tmp = f.name
20
+ subprocess.run(["hf", "buckets", "cp", tmp, f"{BUCKET}/{fn}"], check=False)
21
+ os.unlink(tmp)
22
+ return f"{BUCKET}/{fn}"
23
+
24
+ def load_vap(pattern: str = "vap/", limit: int = 10):
25
+ """List recent VAP files from bucket."""
26
+ r = subprocess.run(["hf", "buckets", "list", "specimba/nexus-vap-bucket", pattern, "-R", "-q"], capture_output=True, text=True)
27
+ return r.stdout.strip().split("\n")[:limit]