Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -319,6 +319,53 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 319 |
for task in pending:
|
| 320 |
task.cancel()
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
if __name__ == "__main__":
|
| 323 |
import uvicorn
|
| 324 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 319 |
for task in pending:
|
| 320 |
task.cancel()
|
| 321 |
|
| 322 |
+
# --- NEU: EXPORT / IMPORT ENDPOINTS ---
|
| 323 |
+
|
| 324 |
+
@app.get("/api/session/export")
|
| 325 |
+
async def export_state():
|
| 326 |
+
"""Gibt den kompletten aktuellen Zustand als JSON zurück."""
|
| 327 |
+
if not system.ready:
|
| 328 |
+
return {"error": "System not ready"}
|
| 329 |
+
|
| 330 |
+
return {
|
| 331 |
+
'vocab': system.vocab.get_state(),
|
| 332 |
+
'sync': system.learner.get_state(),
|
| 333 |
+
'history': list(system.text_comm.messages),
|
| 334 |
+
'physics': system.holo.get_full_state(),
|
| 335 |
+
'timestamp': time.time()
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
@app.post("/api/session/import")
|
| 339 |
+
async def import_state(request: Request):
|
| 340 |
+
"""Empfängt ein JSON und überschreibt den laufenden Zustand."""
|
| 341 |
+
try:
|
| 342 |
+
data = await request.json()
|
| 343 |
+
|
| 344 |
+
# 1. State im RAM überschreiben
|
| 345 |
+
system.vocab = exp1014ecaa4.VocabularyLearner(data.get('vocab', {}))
|
| 346 |
+
system.learner = exp1014ecaa4.SynchronizationLearner(data.get('sync', {}))
|
| 347 |
+
|
| 348 |
+
# Physics Restore
|
| 349 |
+
if 'physics' in data:
|
| 350 |
+
system.holo.restore_full_state(data['physics'])
|
| 351 |
+
|
| 352 |
+
# History Restore
|
| 353 |
+
if 'history' in data:
|
| 354 |
+
system.text_comm.messages = exp1014ecaa4.deque(data['history'], maxlen=50)
|
| 355 |
+
|
| 356 |
+
# 2. Speichern, damit es persistent bleibt
|
| 357 |
+
system.mgr.save_global_state(
|
| 358 |
+
system.vocab.get_state(),
|
| 359 |
+
system.learner.get_state(),
|
| 360 |
+
system.text_comm.messages,
|
| 361 |
+
physics_state=system.holo.get_full_state()
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
return {"status": "ok", "message": "Session imported successfully"}
|
| 365 |
+
except Exception as e:
|
| 366 |
+
print(f"Import Error: {e}")
|
| 367 |
+
return {"status": "error", "message": str(e)}
|
| 368 |
+
|
| 369 |
if __name__ == "__main__":
|
| 370 |
import uvicorn
|
| 371 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|