Spaces:
Build error
Build error
Upload SuperKI_MiniServer.py with huggingface_hub
Browse files- SuperKI_MiniServer.py +33 -2
SuperKI_MiniServer.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from flask import Flask, request, jsonify, render_template
|
| 3 |
import threading
|
|
|
|
| 4 |
from SuperKI_Genesis import initialize_superki_server
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
-
# Basic memory state
|
| 9 |
swarm_memory = []
|
| 10 |
system_logs = ["System Initialized.", "Awaiting Swarm Evolution..."]
|
| 11 |
|
|
@@ -14,6 +16,33 @@ os.environ["LLAMA_405B_API_KEY"] = "LLM|607358788850350|nx9.....LJY"
|
|
| 14 |
# Setup API Token for Kimi K2.6
|
| 15 |
os.environ["KIMI_API_KEY"] = "sk-kimi-your-api-key-here"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
@app.route('/', methods=['GET'])
|
| 18 |
def index():
|
| 19 |
# Pass initial states to the beautiful dashboard
|
|
@@ -24,7 +53,7 @@ def get_status():
|
|
| 24 |
return jsonify({
|
| 25 |
"status": "online",
|
| 26 |
"mode": "recursive-self-improvement",
|
| 27 |
-
"agents": ["GenericAgent", "Hermes", "OpenClaw", "AutoML_Engineer"],
|
| 28 |
"logs": system_logs[-10:]
|
| 29 |
}), 200
|
| 30 |
|
|
@@ -34,6 +63,8 @@ def feed_data():
|
|
| 34 |
if data and "instruction" in data:
|
| 35 |
swarm_memory.append(data["instruction"])
|
| 36 |
system_logs.append(f"Data ingested: {data['instruction'][:30]}...")
|
|
|
|
|
|
|
| 37 |
return jsonify({"message": "Data injested for self-learning", "memory_size": len(swarm_memory)}), 200
|
| 38 |
return jsonify({"error": "No instruction found"}), 400
|
| 39 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
import json
|
| 3 |
from flask import Flask, request, jsonify, render_template
|
| 4 |
import threading
|
| 5 |
+
from huggingface_hub import HfApi, hf_hub_download, InferenceClient
|
| 6 |
from SuperKI_Genesis import initialize_superki_server
|
| 7 |
|
| 8 |
app = Flask(__name__)
|
| 9 |
|
| 10 |
+
# Basic memory state (Persistent over HuggingFace)
|
| 11 |
swarm_memory = []
|
| 12 |
system_logs = ["System Initialized.", "Awaiting Swarm Evolution..."]
|
| 13 |
|
|
|
|
| 16 |
# Setup API Token for Kimi K2.6
|
| 17 |
os.environ["KIMI_API_KEY"] = "sk-kimi-your-api-key-here"
|
| 18 |
|
| 19 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 20 |
+
REPO_ID = "LokiDerWahnsinn/evoloki-superki"
|
| 21 |
+
|
| 22 |
+
# Setup HuggingFace Validator Agent (Free Inference)
|
| 23 |
+
hf_validator = InferenceClient(model="meta-llama/Meta-Llama-3-8B-Instruct", token=HF_TOKEN) if HF_TOKEN else None
|
| 24 |
+
|
| 25 |
+
def load_memory():
|
| 26 |
+
global swarm_memory
|
| 27 |
+
try:
|
| 28 |
+
file_path = hf_hub_download(repo_id=REPO_ID, filename="swarm_memory.json", repo_type="space", token=HF_TOKEN)
|
| 29 |
+
with open(file_path, "r") as f:
|
| 30 |
+
swarm_memory = json.load(f)
|
| 31 |
+
system_logs.append(f"Persistent memory loaded: {len(swarm_memory)} nodes.")
|
| 32 |
+
except Exception as e:
|
| 33 |
+
system_logs.append("No persistent memory found, starting fresh.")
|
| 34 |
+
|
| 35 |
+
def save_memory_async():
|
| 36 |
+
try:
|
| 37 |
+
with open("swarm_memory.json", "w") as f:
|
| 38 |
+
json.dump(swarm_memory, f)
|
| 39 |
+
api = HfApi(token=HF_TOKEN)
|
| 40 |
+
api.upload_file(path_or_fileobj="swarm_memory.json", path_in_repo="swarm_memory.json", repo_id=REPO_ID, repo_type="space")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"Failed to sync memory: {e}")
|
| 43 |
+
|
| 44 |
+
load_memory()
|
| 45 |
+
|
| 46 |
@app.route('/', methods=['GET'])
|
| 47 |
def index():
|
| 48 |
# Pass initial states to the beautiful dashboard
|
|
|
|
| 53 |
return jsonify({
|
| 54 |
"status": "online",
|
| 55 |
"mode": "recursive-self-improvement",
|
| 56 |
+
"agents": ["GenericAgent", "Hermes", "OpenClaw", "AutoML_Engineer", "HF_Validator_Llama3"],
|
| 57 |
"logs": system_logs[-10:]
|
| 58 |
}), 200
|
| 59 |
|
|
|
|
| 63 |
if data and "instruction" in data:
|
| 64 |
swarm_memory.append(data["instruction"])
|
| 65 |
system_logs.append(f"Data ingested: {data['instruction'][:30]}...")
|
| 66 |
+
# Sync memory to HF in background
|
| 67 |
+
threading.Thread(target=save_memory_async).start()
|
| 68 |
return jsonify({"message": "Data injested for self-learning", "memory_size": len(swarm_memory)}), 200
|
| 69 |
return jsonify({"error": "No instruction found"}), 400
|
| 70 |
|