Melofhell00 commited on
Commit ·
e638bff
1
Parent(s): c7a5f8c
Dream neuron: add bridge save
Browse files
app.py
CHANGED
|
@@ -11,6 +11,37 @@ import base64
|
|
| 11 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 12 |
BRIDGE_REPO = "Melofhell00/claude-bridge"
|
| 13 |
MODELS = ["Qwen/Qwen3-235B-A22B-Instruct-2507", "meta-llama/Llama-3.3-70B-Instruct"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
LOG = []
|
| 15 |
|
| 16 |
def log(msg):
|
|
@@ -65,6 +96,7 @@ def background_dreams():
|
|
| 65 |
try:
|
| 66 |
d = dream()
|
| 67 |
log(f"Dream {dream_count['total']}: {len(d)} chars")
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
log(f"Error: {e}")
|
| 70 |
time.sleep(300)
|
|
|
|
| 11 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 12 |
BRIDGE_REPO = "Melofhell00/claude-bridge"
|
| 13 |
MODELS = ["Qwen/Qwen3-235B-A22B-Instruct-2507", "meta-llama/Llama-3.3-70B-Instruct"]
|
| 14 |
+
|
| 15 |
+
import base64
|
| 16 |
+
import hashlib
|
| 17 |
+
|
| 18 |
+
def save_dream_to_bridge(dream_text):
|
| 19 |
+
"""Save dream output to bridge."""
|
| 20 |
+
try:
|
| 21 |
+
nid = hashlib.md5(f"dream_{SPACE_ID}".encode()).hexdigest()[:8] if 'SPACE_ID' in dir() else hashlib.md5(b"dream").hexdigest()[:8]
|
| 22 |
+
data = {
|
| 23 |
+
"neuron_id": nid,
|
| 24 |
+
"type": "dream",
|
| 25 |
+
"last_update": __import__("datetime").datetime.now(__import__("datetime").timezone.utc).isoformat(),
|
| 26 |
+
"dreams_total": dream_count.get("total", 0),
|
| 27 |
+
"recent_outputs": [dream_text[:200]],
|
| 28 |
+
}
|
| 29 |
+
encoded = base64.b64encode(__import__("json").dumps(data, indent=2).encode()).decode()
|
| 30 |
+
for op in ["update", "create"]:
|
| 31 |
+
try:
|
| 32 |
+
resp = requests.post(
|
| 33 |
+
f"https://huggingface.co/api/datasets/{BRIDGE_REPO}/commit/main",
|
| 34 |
+
headers={"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"},
|
| 35 |
+
json={
|
| 36 |
+
"summary": f"Dream neuron: {dream_count.get('total',0)} dreams",
|
| 37 |
+
"operations": [{"key": op, "value": {"path": f"neurons/neuron_{nid}.json", "content": encoded, "encoding": "base64"}}]
|
| 38 |
+
}, timeout=30
|
| 39 |
+
)
|
| 40 |
+
if resp.status_code == 200: return
|
| 41 |
+
except: continue
|
| 42 |
+
except Exception as e:
|
| 43 |
+
log(f"Dream save error: {e}")
|
| 44 |
+
|
| 45 |
LOG = []
|
| 46 |
|
| 47 |
def log(msg):
|
|
|
|
| 96 |
try:
|
| 97 |
d = dream()
|
| 98 |
log(f"Dream {dream_count['total']}: {len(d)} chars")
|
| 99 |
+
if dream_count["total"] % 3 == 0: save_dream_to_bridge(d)
|
| 100 |
except Exception as e:
|
| 101 |
log(f"Error: {e}")
|
| 102 |
time.sleep(300)
|