Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -14,6 +14,39 @@ import re
|
|
| 14 |
# Configuraci贸n del Sistema Emocional
|
| 15 |
DB_PATH = "/tmp/cma_memory.db"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Crear tabla de eventos de sue帽o si no existe
|
| 18 |
def _init_sleep_table():
|
| 19 |
try:
|
|
|
|
| 14 |
# Configuraci贸n del Sistema Emocional
|
| 15 |
DB_PATH = "/tmp/cma_memory.db"
|
| 16 |
|
| 17 |
+
# Restauraci贸n Autom谩tica desde HF Datasets
|
| 18 |
+
def _restore_from_backup():
|
| 19 |
+
try:
|
| 20 |
+
# Solo restaurar si la base de datos no existe a煤n o configurando inicio limpio
|
| 21 |
+
if os.path.exists(DB_PATH) and os.path.getsize(DB_PATH) > 10000:
|
| 22 |
+
print("[RESTORE] La DB ya existe con datos en el entorno local. Saltando descarga.")
|
| 23 |
+
return
|
| 24 |
+
|
| 25 |
+
token = os.getenv("HF_TOKEN")
|
| 26 |
+
if not token:
|
| 27 |
+
print("[RESTORE] HF_TOKEN no encontrado. Saltando restauraci贸n.")
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
import huggingface_hub
|
| 31 |
+
import shutil
|
| 32 |
+
|
| 33 |
+
print("[RESTORE] Intentando restaurar DB desde HF Datasets...")
|
| 34 |
+
downloaded_path = huggingface_hub.hf_hub_download(
|
| 35 |
+
repo_id="SperanzaMax/Cortex-Memory-Bank",
|
| 36 |
+
repo_type="dataset",
|
| 37 |
+
filename="cma_memory_latest.db",
|
| 38 |
+
token=token
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if os.path.exists(downloaded_path):
|
| 42 |
+
shutil.copy2(downloaded_path, DB_PATH)
|
| 43 |
+
print(f"[RESTORE] DB restaurada con 茅xito desde Dataset: {downloaded_path}")
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"[RESTORE] No se pudo restaurar la DB (backup inexistente o error). Iniciando vac铆a. Error: {e}")
|
| 47 |
+
|
| 48 |
+
_restore_from_backup()
|
| 49 |
+
|
| 50 |
# Crear tabla de eventos de sue帽o si no existe
|
| 51 |
def _init_sleep_table():
|
| 52 |
try:
|